Documentation ¶
Overview ¶
Package dnutil implements a library for easy handling of distinguished name.
dnutil is a library for easy handling of distinguished name.
Index ¶
- func MarshalDN(dn DN) (dnBytes []byte, err error)
- func ReferOid(atn AttributeType) (oid asn1.ObjectIdentifier, err error)
- func ValidateCountryCode(c string) (bool, error)
- type AttributeType
- type AttributeTypeAndValue
- type AttributeValue
- type DN
- func (d DN) CountRDN() int
- func (d DN) RetrieveRDN(index int) (rdn RDN, err error)
- func (d DN) RetrieveRDNsByAttributeTypes(ats []AttributeType) (rdns []RDN)
- func (d DN) RetrieveRDNsByOids(oids []string) (rdns []RDN)
- func (d DN) ReverseDnOrder() DN
- func (d DN) String() string
- func (d DN) ToRFC4514FormatString() string
- type Encoding
- type RDN
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MarshalDN ¶
MarshalDN converts a DN to distinguished name (DN), ASN.1 DER form. RDN of the DN should have at least one AttributeTypeAndValue element. AttributeValue currently supports the following ASN.1 string encodings:
PrintableString UTF8String IA5String
AttributeType currently supports the following AttributeTypes:
CountryName (2.5.4.6) OrganizationName (2.5.4.10) OrganizationalUnit (2.5.4.11) DnQualifier (2.5.4.46) StateOrProvinceName (2.5.4.8) CommonName (2.5.4.3) SerialNumber (2.5.4.5) LocalityName (2.5.4.7) Title (2.5.4.12) Surname (2.5.4.4) GivenName (2.5.4.42) Initials (2.5.4.43) Pseudonym (2.5.4.65) GenerationQualifier (2.5.4.44) ElectronicMailAddress (1.2.840.113549.1.9.1) DomainComponent (0.9.2342.19200300.100.1.25) Generic (Any OBJECT IDENTIFIER)
Any object identifier can be specified by setting Generic to Type and object identifier to Oid. If Type is Generic, Oid must be specified.
Currently, the following combinations of OBJECT IDENTIFIER for AttributeType and Encoding for AttributeValue are supported:
CountryName (2.5.4.6) : PrintableString OrganizationName (2.5.4.10) : PrintableString or UTF8String OrganizationalUnit (2.5.4.11) : PrintableString or UTF8String DnQualifier (2.5.4.46) : PrintableString StateOrProvinceName (2.5.4.8) : PrintableString or UTF8String CommonName (2.5.4.3) : PrintableString or UTF8String SerialNumber (2.5.4.5) : PrintableString LocalityName (2.5.4.7) : PrintableString or UTF8String Title (2.5.4.12) : PrintableString or UTF8String Surname (2.5.4.4) : PrintableString or UTF8String GivenName (2.5.4.42) : PrintableString or UTF8String Initials (2.5.4.43) : PrintableString or UTF8String Pseudonym (2.5.4.65) : PrintableString or UTF8String GenerationQualifier (2.5.4.44) : PrintableString or UTF8String ElectronicMailAddress (1.2.840.113549.1.9.1) : IA5String DomainComponent (0.9.2342.19200300.100.1.25) : IA5String Generic (Any OBJECT IDENTIFIER other than those already listed) : PrintableString or UTF8String or IA5String
https://datatracker.ietf.org/doc/html/rfc5280#section-4.1.2.4 https://datatracker.ietf.org/doc/html/rfc5280#appendix-A.1
func ReferOid ¶
func ReferOid(atn AttributeType) (oid asn1.ObjectIdentifier, err error)
ReferOid returns corresponding ObjectIdentifier of atn. If not supported AttributeType is specified, then returns blank ObjectIdentifier and error. The following AttributeType are currently supported:
2.5.4.6 CountryName 2.5.4.10 OrganizationName 2.5.4.11 OrganizationalUnit 2.5.4.46 DnQualifier 2.5.4.8 StateOrProvinceName 2.5.4.3 CommonName 2.5.4.5 SerialNumber 2.5.4.7 LocalityName 2.5.4.12 Title 2.5.4.4 Surname 2.5.4.42 GivenName 2.5.4.43 Initials 2.5.4.65 Pseudonym 2.5.4.44 GenerationQualifier 1.2.840.113549.1.9.1 ElectronicMailAddress 0.9.2342.19200300.100.1.25 DomainComponent
https://datatracker.ietf.org/doc/html/rfc5280#section-4.1.2.4 https://datatracker.ietf.org/doc/html/rfc5280#appendix-A.1
func ValidateCountryCode ¶ added in v0.7.0
ValidateCountryCode validates whether c is a valid country code
Types ¶
type AttributeType ¶
type AttributeType int
AttributeType represents a Name of ASN.1 Attribute Type object. https://datatracker.ietf.org/doc/html/rfc5280#section-4.1.2.4
const ( CountryName AttributeType = iota + 1 OrganizationName OrganizationalUnit DnQualifier StateOrProvinceName CommonName SerialNumber LocalityName Title Surname GivenName Initials Pseudonym GenerationQualifier ElectronicMailAddress DomainComponent Generic )
Attribute Type Name
func ReferAttributeTypeName ¶
func ReferAttributeTypeName(oid asn1.ObjectIdentifier) (atn AttributeType, err error)
ReferAttributeTypeName returns corresponding AttributeType of ObjectIdentifier. If not supported ObjectIdentifier is specified, then returns 0 and error. The following ObjectIdentifier are currently supported:
2.5.4.6 CountryName 2.5.4.10 OrganizationName 2.5.4.11 OrganizationalUnit 2.5.4.46 DnQualifier 2.5.4.8 StateOrProvinceName 2.5.4.3 CommonName 2.5.4.5 SerialNumber 2.5.4.7 LocalityName 2.5.4.12 Title 2.5.4.4 Surname 2.5.4.42 GivenName 2.5.4.43 Initials 2.5.4.65 Pseudonym 2.5.4.44 GenerationQualifier 1.2.840.113549.1.9.1 ElectronicMailAddress 0.9.2342.19200300.100.1.25 DomainComponent
https://datatracker.ietf.org/doc/html/rfc5280#section-4.1.2.4 https://datatracker.ietf.org/doc/html/rfc5280#appendix-A.1
func (AttributeType) String ¶
func (a AttributeType) String() string
type AttributeTypeAndValue ¶
type AttributeTypeAndValue struct { //AttributeType Type AttributeType //AttributeValue Value AttributeValue //If Type is Generic, Oid must be specified Oid string }
AttributeTypeAndValue represents an ASN.1 AttributeTypeAndValue object. AttributeType currently supports the following AttributeTypes:
CountryName (2.5.4.6) OrganizationName (2.5.4.10) OrganizationalUnit (2.5.4.11) DnQualifier (2.5.4.46) StateOrProvinceName (2.5.4.8) CommonName (2.5.4.3) SerialNumber (2.5.4.5) LocalityName (2.5.4.7) Title (2.5.4.12) Surname (2.5.4.4) GivenName (2.5.4.42) Initials (2.5.4.43) Pseudonym (2.5.4.65) GenerationQualifier (2.5.4.44) ElectronicMailAddress (1.2.840.113549.1.9.1) DomainComponent (0.9.2342.19200300.100.1.25) Generic (Any OBJECT IDENTIFIER)
Any object identifier can be specified by setting Generic to Type and object identifier to Oid. If Type is Generic, Oid must be specified.
Currently, the following combinations of OBJECT IDENTIFIER for AttributeType and Encoding for AttributeValue are supported:
CountryName (2.5.4.6) : PrintableString OrganizationName (2.5.4.10) : PrintableString or UTF8String OrganizationalUnit (2.5.4.11) : PrintableString or UTF8String DnQualifier (2.5.4.46) : PrintableString StateOrProvinceName (2.5.4.8) : PrintableString or UTF8String CommonName (2.5.4.3) : PrintableString or UTF8String SerialNumber (2.5.4.5) : PrintableString LocalityName (2.5.4.7) : PrintableString or UTF8String Title (2.5.4.12) : PrintableString or UTF8String Surname (2.5.4.4) : PrintableString or UTF8String GivenName (2.5.4.42) : PrintableString or UTF8String Initials (2.5.4.43) : PrintableString or UTF8String Pseudonym (2.5.4.65) : PrintableString or UTF8String GenerationQualifier (2.5.4.44) : PrintableString or UTF8String ElectronicMailAddress (1.2.840.113549.1.9.1) : IA5String DomainComponent (0.9.2342.19200300.100.1.25) : IA5String Generic (Any OBJECT IDENTIFIER other than those already listed) : PrintableString or UTF8String or IA5String
https://datatracker.ietf.org/doc/html/rfc5280#section-4.1.2.4
func (AttributeTypeAndValue) String ¶ added in v0.5.0
func (atv AttributeTypeAndValue) String() string
String returns a string representation of this AttributeTypeAndValue. The attribute type is uppercase, and the attribute type and value are concatenated by "=".
func (AttributeTypeAndValue) ToRFC4514FormatString ¶ added in v0.5.0
func (atv AttributeTypeAndValue) ToRFC4514FormatString() string
ToRFC4514FormatString returns an RFC4514 Format string of this AttributeTypeAndValue. The attribute type is uppercase
type AttributeValue ¶
AttributeValue represents an ASN.1 AttributeValue object. https://datatracker.ietf.org/doc/html/rfc5280#section-4.1.2.4
func (AttributeValue) String ¶
func (av AttributeValue) String() string
String returns a string representation of this AttributeValue.
func (AttributeValue) ToRFC4514FormatString ¶ added in v0.5.0
func (av AttributeValue) ToRFC4514FormatString() string
ToRFC4514FormatString returns an RFC4514 Format string of this AttributeValue.
type DN ¶
type DN []RDN
DN represents an ASN.1 DistinguishedName object. https://datatracker.ietf.org/doc/html/rfc5280#section-4.1.2.4
func ParseDERDN ¶
ParseDERDN parses a distinguished name, ASN.1 DER form and returns DN. RelativeDistinguishedName of the distinguished name should have at least one AttributeTypeAndValue. AttributeValue currently supports the following ASN.1 string encodings:
PrintableString UTF8String IA5String
Currently, the following combinations of OBJECT IDENTIFIER for AttributeType and Encoding for AttributeValue are supported:
2.5.4.6 (CountryName) : PrintableString 2.5.4.10 (OrganizationName) : PrintableString or UTF8String 2.5.4.11 (OrganizationalUnit) : PrintableString or UTF8String 2.5.4.46 (DnQualifier) : PrintableString 2.5.4.8 (StateOrProvinceName) : PrintableString or UTF8String 2.5.4.3 (CommonName) : PrintableString or UTF8String 2.5.4.5 (SerialNumber) : PrintableString 2.5.4.7 (LocalityName) : PrintableString or UTF8String 2.5.4.12 (Title) : PrintableString or UTF8String 2.5.4.4 (Surname) : PrintableString or UTF8String 2.5.4.42 (GivenName) : PrintableString or UTF8String 2.5.4.43 (Initials) : PrintableString or UTF8String 2.5.4.65 (Pseudonym) : PrintableString or UTF8String 2.5.4.44 (GenerationQualifier) : PrintableString or UTF8String 1.2.840.113549.1.9.1 (ElectronicMailAddress) : IA5String 0.9.2342.19200300.100.1.25 (DomainComponent) : IA5String Any OBJECT IDENTIFIER other than those already listed (Generic) : PrintableString or UTF8String or IA5String
https://datatracker.ietf.org/doc/html/rfc5280#section-4.1.2.4 https://datatracker.ietf.org/doc/html/rfc5280#appendix-A.1
func (DN) RetrieveRDN ¶ added in v0.3.0
RetrieveRDN returns the rdn specified by index from the DN.
func (DN) RetrieveRDNsByAttributeTypes ¶ added in v0.3.0
func (d DN) RetrieveRDNsByAttributeTypes(ats []AttributeType) (rdns []RDN)
RetrieveRDNsByAttributeTypes returns RDN(s) that exactly match the specified ats AttributeType(s). Because ats is ASN1.SET, the order of ats is ignored. Deprecated: Replace with a RetrieveRDNsByOids implementation.
func (DN) RetrieveRDNsByOids ¶ added in v0.6.0
RetrieveRDNsByOids returns RDN(s) that exactly match the specified oids, AttributeType Oid(s). The order of the AttributeType Oid(s) is ignored because AttributeType Oid(s) is ASN1.SET.
func (DN) ReverseDnOrder ¶ added in v0.5.0
ReverseDnOrder returns a new reverse order DN.
func (DN) String ¶ added in v0.5.0
String returns a string representation of this DN. All string representations of RDN in the DN are concatenated with ",".
func (DN) ToRFC4514FormatString ¶ added in v0.5.0
ToRFC4514FormatString returns an RFC4514 Format string of this DN.
type RDN ¶
type RDN []AttributeTypeAndValue
RDN represents an ASN.1 RelativeDistinguishedName object. https://datatracker.ietf.org/doc/html/rfc5280#section-4.1.2.4
func (RDN) CountAttributeTypeAndValue ¶
CountAttributeTypeAndValue returns number of AttributeTypeAndValue of RDN.
func (RDN) String ¶ added in v0.5.0
String returns a string representation of this RDN. All string representations of AttributeTypeAndValues in the RDN are concatenated with "+".
func (RDN) ToRFC4514FormatString ¶ added in v0.5.0
ToRFC4514FormatString returns an RFC4514 Format string of this RDN.