Struct x509_certificate::rfc5280::TbsCertificate
source · pub struct TbsCertificate {
pub version: Option<Version>,
pub serial_number: CertificateSerialNumber,
pub signature: AlgorithmIdentifier,
pub issuer: Name,
pub validity: Validity,
pub subject: Name,
pub subject_public_key_info: SubjectPublicKeyInfo,
pub issuer_unique_id: Option<UniqueIdentifier>,
pub subject_unique_id: Option<UniqueIdentifier>,
pub extensions: Option<Extensions>,
pub raw_data: Option<Vec<u8>>,
}Expand description
TBS Certificate.
This holds most of the metadata within an X.509 certificate.
TBSCertificate ::= SEQUENCE {
version [0] Version DEFAULT v1,
serialNumber CertificateSerialNumber,
signature AlgorithmIdentifier,
issuer Name,
validity Validity,
subject Name,
subjectPublicKeyInfo SubjectPublicKeyInfo,
issuerUniqueID [1] IMPLICIT UniqueIdentifier OPTIONAL,
-- If present, version MUST be v2 or v3
subjectUniqueID [2] IMPLICIT UniqueIdentifier OPTIONAL,
-- If present, version MUST be v2 or v3
extensions [3] Extensions OPTIONAL
-- If present, version MUST be v3 -- }
Fields§
§version: Option<Version>§serial_number: CertificateSerialNumber§signature: AlgorithmIdentifier§issuer: Name§validity: Validity§subject: Name§subject_public_key_info: SubjectPublicKeyInfo§issuer_unique_id: Option<UniqueIdentifier>§subject_unique_id: Option<UniqueIdentifier>§extensions: Option<Extensions>§raw_data: Option<Vec<u8>>Raw bytes this instance was constructed from.
This is what signature verification should be performed against.
Implementations§
source§impl TbsCertificate
impl TbsCertificate
sourcepub fn take_from<S: Source>(
cons: &mut Constructed<'_, S>
) -> Result<Self, DecodeError<S::Error>>
pub fn take_from<S: Source>(
cons: &mut Constructed<'_, S>
) -> Result<Self, DecodeError<S::Error>>
Examples found in repository?
src/rfc5280.rs (line 194)
191 192 193 194 195 196 197 198 199 200 201 202 203
pub fn from_sequence<S: Source>(
cons: &mut Constructed<S>,
) -> Result<Self, DecodeError<S::Error>> {
let tbs_certificate = TbsCertificate::take_from(cons)?;
let signature_algorithm = AlgorithmIdentifier::take_from(cons)?;
let signature = BitString::take_from(cons)?;
Ok(Self {
tbs_certificate,
signature_algorithm,
signature,
})
}sourcepub fn encode_ref(&self) -> impl Values + '_
pub fn encode_ref(&self) -> impl Values + '_
Examples found in repository?
More examples
src/certificate.rs (line 1013)
962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031
pub fn create_with_random_keypair(
&self,
) -> Result<
(
CapturedX509Certificate,
InMemorySigningKeyPair,
ring::pkcs8::Document,
),
Error,
> {
let (key_pair, document) = InMemorySigningKeyPair::generate_random(self.key_algorithm)?;
let key_pair_signature_algorithm = key_pair.signature_algorithm();
let issuer = if let Some(issuer) = &self.issuer {
issuer
} else {
&self.subject
};
let tbs_certificate = rfc5280::TbsCertificate {
version: Some(rfc5280::Version::V3),
serial_number: self.serial_number.into(),
signature: key_pair_signature_algorithm?.into(),
issuer: issuer.clone(),
validity: rfc5280::Validity {
not_before: Time::from(self.not_before),
not_after: Time::from(self.not_after),
},
subject: self.subject.clone(),
subject_public_key_info: rfc5280::SubjectPublicKeyInfo {
algorithm: key_pair
.key_algorithm()
.expect("InMemorySigningKeyPair always has known key algorithm")
.into(),
subject_public_key: BitString::new(0, key_pair.public_key_data()),
},
issuer_unique_id: None,
subject_unique_id: None,
extensions: if self.extensions.is_empty() {
None
} else {
Some(self.extensions.clone())
},
raw_data: None,
};
// Now encode the TBS certificate so we can sign it with the private key
// and include its signature.
let mut tbs_der = Vec::<u8>::new();
tbs_certificate
.encode_ref()
.write_encoded(Mode::Der, &mut tbs_der)?;
let signature = key_pair.try_sign(&tbs_der)?;
let signature_algorithm = key_pair.signature_algorithm()?;
let cert = rfc5280::Certificate {
tbs_certificate,
signature_algorithm: signature_algorithm.into(),
signature: BitString::new(0, Bytes::copy_from_slice(signature.as_ref())),
};
let cert = X509Certificate::from(cert);
let cert_der = cert.encode_der()?;
let cert = CapturedX509Certificate::from_der(cert_der)?;
Ok((cert, key_pair, document))
}Trait Implementations§
source§impl Clone for TbsCertificate
impl Clone for TbsCertificate
source§fn clone(&self) -> TbsCertificate
fn clone(&self) -> TbsCertificate
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moresource§impl Debug for TbsCertificate
impl Debug for TbsCertificate
source§impl PartialEq<TbsCertificate> for TbsCertificate
impl PartialEq<TbsCertificate> for TbsCertificate
source§fn eq(&self, other: &TbsCertificate) -> bool
fn eq(&self, other: &TbsCertificate) -> bool
This method tests for
self and other values to be equal, and is used
by ==.