pub struct Name(/* private fields */);Expand description
X.501 Name as defined in RFC 5280 Section 4.1.2.4. X.501 Name is used to represent distinguished names.
Name ::= CHOICE { rdnSequence RDNSequence }To build name, the syntax described in RFC 4514 Section 3 is expected.
The following attribute names are recognized:
String X.500 AttributeType
------ --------------------------------------------
CN commonName (2.5.4.3)
L localityName (2.5.4.7)
ST stateOrProvinceName (2.5.4.8)
O organizationName (2.5.4.10)
OU organizationalUnitName (2.5.4.11)
C countryName (2.5.4.6)
STREET streetAddress (2.5.4.9)
DC domainComponent (0.9.2342.19200300.100.1.25)
UID userId (0.9.2342.19200300.100.1.1)
§Example
use std::str::FromStr;
use x509_cert::name::Name;
// Multiple syntaxes are supported by `from_str`:
let subject = Name::from_str("CN=example.com").unwrap();
let subject = Name::from_str("C=US; ST=California; L=Los Angeles; O=InternetCorporationforAssignedNamesandNumbers; CN=www.example.org").unwrap();
let subject = Name::from_str("C=US,ST=California,L=Los Angeles,O=InternetCorporationforAssignedNamesandNumbers,CN=www.example.org").unwrap();
let subject = Name::from_str("C=US/ST=California/L=Los Angeles/O=InternetCorporationforAssignedNamesandNumbers/CN=www.example.org").unwrap();
let subject = Name::from_str("UID=jsmith,DC=example,DC=net").unwrap();
let subject = Name::from_str("OU=Sales+CN=J. Smith,DC=example,DC=net").unwrap();
let subject = Name::from_str(r#"CN=James \"Jim\" Smith\, III,DC=example,DC=net"#).unwrap();
let subject = Name::from_str(r#"CN=Before\0dAfter,DC=example,DC=net"#).unwrap();
let subject = Name::from_str("1.3.6.1.4.1.1466.0=#04024869").unwrap();Implementations§
Source§impl Name
impl Name
Sourcepub fn hazmat_from_rdn_sequence(value: RdnSequence) -> Name
pub fn hazmat_from_rdn_sequence(value: RdnSequence) -> Name
Build a name from an RdnSequence.
This is provided as an escape hatch (see RFC 5280 Section 4.1.2.4) to build
names from bmpString, TeletexString, or UniversalString:
When CAs have previously issued certificates with issuer fields with
attributes encoded using TeletexString, BMPString, or
UniversalString, then the CA MAY continue to use these encodings of
the DirectoryString to preserve backward compatibility.§Safety
As the name implies, this is a dangerous helper. You are responsible for ensuring the
RdnSequence complies with the RFC.
Source§impl Name
impl Name
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of RelativeDistinguishedName elements in this Name.
Sourcepub fn iter(&self) -> impl Iterator<Item = &AttributeTypeAndValue>
pub fn iter(&self) -> impl Iterator<Item = &AttributeTypeAndValue>
Returns an iterator over the inner AttributeTypeAndValues.
This iterator does not expose which attributes are grouped together as
RelativeDistinguishedNames. If you need this, use Self::iter_rdn.
Sourcepub fn iter_rdn(&self) -> impl Iterator<Item = &RelativeDistinguishedName>
pub fn iter_rdn(&self) -> impl Iterator<Item = &RelativeDistinguishedName>
Returns an iterator over the inner RelativeDistinguishedNames.
Source§impl Name
impl Name
Sourcepub fn by_oid<'a, T>(
&'a self,
oid: ObjectIdentifier,
) -> Result<Option<T>, Error>
pub fn by_oid<'a, T>( &'a self, oid: ObjectIdentifier, ) -> Result<Option<T>, Error>
Returns the element found in the name identified by oid
This will return Ok(None) if no such element is present.
If more than one attribute is present with the specified OID, only the first attribute is
returned. Later elements should be fetched using Name::iter.
§Errors
This will return der::Error if the content is not serialized as expected
Sourcepub fn common_name(&self) -> Result<Option<DirectoryString>, Error>
pub fn common_name(&self) -> Result<Option<DirectoryString>, Error>
Returns the Common Name (CN) found in the name.
This will return Ok(None) if no CN is found.
If more than one value is present, only the first is returned.
Later elements should be fetched using Name::iter.
§Errors
This will return der::Error if the content is not serialized as a string.
Sourcepub fn country(&self) -> Result<Option<PrintableStringRef<'_>>, Error>
pub fn country(&self) -> Result<Option<PrintableStringRef<'_>>, Error>
Returns the Country (C) found in the name.
This will return Ok(None) if no Country is found.
If more than one value is present, only the first is returned.
Later elements should be fetched using Name::iter.
§Errors
This will return der::Error if the content is not serialized as a printableString.
Sourcepub fn state_or_province(&self) -> Result<Option<DirectoryString>, Error>
pub fn state_or_province(&self) -> Result<Option<DirectoryString>, Error>
Returns the State or Province (ST) found in the name.
This will return Ok(None) if no State or Province is found.
If more than one value is present, only the first is returned.
Later elements should be fetched using Name::iter.
§Errors
This will return der::Error if the content is not serialized as a string.
Sourcepub fn locality(&self) -> Result<Option<DirectoryString>, Error>
pub fn locality(&self) -> Result<Option<DirectoryString>, Error>
Returns the Locality (L) found in the name.
This will return Ok(None) if no Locality is found.
If more than one value is present, only the first is returned.
Later elements should be fetched using Name::iter.
§Errors
This will return der::Error if the content is not serialized as a string.
Sourcepub fn organization(&self) -> Result<Option<DirectoryString>, Error>
pub fn organization(&self) -> Result<Option<DirectoryString>, Error>
Returns the Organization (O) found in the name.
This will return Ok(None) if no Organization is found.
If more than one value is present, only the first is returned.
Later elements should be fetched using Name::iter.
§Errors
This will return der::Error if the content is not serialized as a string.
Sourcepub fn organization_unit(&self) -> Result<Option<DirectoryString>, Error>
pub fn organization_unit(&self) -> Result<Option<DirectoryString>, Error>
Returns the Organization Unit (OU) found in the name.
This will return Ok(None) if no Organization Unit is found.
If more than one value is present, only the first is returned.
Later elements should be fetched using Name::iter.
§Errors
This will return der::Error if the content is not serialized as a string.
Sourcepub fn email_address(&self) -> Result<Option<Ia5StringRef<'_>>, Error>
pub fn email_address(&self) -> Result<Option<Ia5StringRef<'_>>, Error>
Returns the Email Address (emailAddress) found in the name.
This will return Ok(None) if no email address is found.
If more than one value is present, only the first is returned.
Later elements should be fetched using Name::iter.
§Errors
This will return der::Error if the content is not serialized as an ia5String.