dnutil

package module
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 16, 2024 License: BSD-3-Clause Imports: 6 Imported by: 0

README

Go ReferenceGo

dnutil

dnutil is a library for easy handling of distinguished name. This library is useful for creating and editing a distinguished name for use in Certificates, CRL and CSR in Golang. With this library, you can easily and freely create Issuer and Subject based on RFC 5280.

Installation

go get github.com/tardevnull/dnutil@latest

Example

package main

import (
	"crypto"
	"crypto/rand"
	"crypto/rsa"
	"crypto/x509"
	"encoding/hex"
	"encoding/pem"
	"fmt"
	"log"
	"os"

	"github.com/tardevnull/dnutil"
)

func main() {

	//CN=ex+0.9.2342.19200300.100.1.1=userid_0001+E=ex@example.com,OU=Dev+OU=Sales,OU=Ext,O=example,C=JP
	d := dnutil.DN{
		dnutil.RDN{dnutil.AttributeTypeAndValue{Type: dnutil.CountryName, Value: dnutil.AttributeValue{Encoding: dnutil.PrintableString, Value: "JP"}}},
		dnutil.RDN{dnutil.AttributeTypeAndValue{Type: dnutil.OrganizationName, Value: dnutil.AttributeValue{Encoding: dnutil.UTF8String, Value: "example"}}},
		dnutil.RDN{dnutil.AttributeTypeAndValue{Type: dnutil.OrganizationalUnit, Value: dnutil.AttributeValue{Encoding: dnutil.UTF8String, Value: "Ext"}}},
		dnutil.RDN{
			dnutil.AttributeTypeAndValue{Type: dnutil.OrganizationalUnit, Value: dnutil.AttributeValue{Encoding: dnutil.UTF8String, Value: "Dev"}},
			dnutil.AttributeTypeAndValue{Type: dnutil.OrganizationalUnit, Value: dnutil.AttributeValue{Encoding: dnutil.UTF8String, Value: "Sales"}},
		},
		dnutil.RDN{
			dnutil.AttributeTypeAndValue{Type: dnutil.CommonName, Value: dnutil.AttributeValue{Encoding: dnutil.UTF8String, Value: "ex"}},
			dnutil.AttributeTypeAndValue{Type: dnutil.Generic, Oid: "0.9.2342.19200300.100.1.1", Value: dnutil.AttributeValue{Encoding: dnutil.UTF8String, Value: "userid_0001"}},
			dnutil.AttributeTypeAndValue{Type: dnutil.ElectronicMailAddress, Value: dnutil.AttributeValue{Encoding: dnutil.IA5String, Value: "ex@example.com"}}},
	}

	subjectBytes, err := dnutil.MarshalDN(d)
	if err != nil {
		log.Fatalf("ERROR:%v\n", err)
	}
	fmt.Println(hex.EncodeToString(subjectBytes))

	dn, err := dnutil.ParseDERDN(subjectBytes)
	if err != nil {
		log.Fatalf("ERROR:%v\n", err)
	}
	fmt.Println(dn)

	//Create CertificateRequest
	privateKey, err := rsa.GenerateKey(rand.Reader, 1024)
	if err != nil {
		log.Fatalf("ERROR:%v\n", err)
	}
	var publicKey crypto.PublicKey
	publicKey = privateKey.Public()

	if err != nil {
		log.Fatalf("ERROR:%v\n", err)
	}

	template := &x509.CertificateRequest{
		PublicKeyAlgorithm: x509.RSA,
		PublicKey:          publicKey,
		SignatureAlgorithm: x509.SHA256WithRSA,
		RawSubject:         subjectBytes,
	}

	csr, err := x509.CreateCertificateRequest(rand.Reader, template, privateKey)
	err = pem.Encode(os.Stdout, &pem.Block{Type: "CERTIFICATE REQUEST", Bytes: csr})
	if err != nil {
		log.Fatalf("ERROR:%v\n", err)
	}

}

example

Usage

type DN []RDN

DN represents an ASN.1 DistinguishedName object.

//Distinguished Name Example
CN=ex+0.9.2342.19200300.100.1.1=userid_0001+E=ex@example.com,OU=Dev+OU=Sales,OU=Ext,O=example,C=JP

C: PrintableString
O: UTF8String
OU=Ext: UTF8String
OU=Dev: UTF8String
OU=Sales: UTF8String
CN: UTF8String
UID(0.9.2342.19200300.100.1.1): UTF8String
EMAIL(ElectronicMailAddress): IA5String

you can write it as DN struct:

var d = dnutil.DN{
	dnutil.RDN{dnutil.AttributeTypeAndValue{Type: dnutil.CountryName, Value: dnutil.AttributeValue{Encoding: dnutil.PrintableString, Value: "JP"}}},
	dnutil.RDN{dnutil.AttributeTypeAndValue{Type: dnutil.OrganizationName, Value: dnutil.AttributeValue{Encoding: dnutil.UTF8String, Value: "example"}}},
	dnutil.RDN{dnutil.AttributeTypeAndValue{Type: dnutil.OrganizationalUnit, Value: dnutil.AttributeValue{Encoding: dnutil.UTF8String, Value: "Ext"}}},
	dnutil.RDN{
		dnutil.AttributeTypeAndValue{Type: dnutil.OrganizationalUnit, Value: dnutil.AttributeValue{Encoding: dnutil.UTF8String, Value: "Dev"}},
		dnutil.AttributeTypeAndValue{Type: dnutil.OrganizationalUnit, Value: dnutil.AttributeValue{Encoding: dnutil.UTF8String, Value: "Sales"}},},
	dnutil.RDN{
		dnutil.AttributeTypeAndValue{Type: dnutil.CommonName, Value: dnutil.AttributeValue{Encoding: dnutil.UTF8String, Value: "ex"}},
		dnutil.AttributeTypeAndValue{Type: dnutil.Generic, Oid: "0.9.2342.19200300.100.1.1", Value: dnutil.AttributeValue{Encoding: dnutil.UTF8String, Value: "userid_0001"}},
		dnutil.AttributeTypeAndValue{Type: dnutil.ElectronicMailAddress, Value: dnutil.AttributeValue{Encoding: dnutil.IA5String, Value: "ex@example.com"}}},
}
Note:
  • 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:
  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 
  • If Type is Generic and Oid is a known AttributeType object identifier(CountryName(="2.5.4.6"), OrganizationName(="2.5.4.10"), etc.), the combination follows the one already enumerated. ex: If Type: Generic, Oid: "2.5.4.6"(=CountryName), then only PrintableString is allowed.
func MarshalDN(dn DN) (dnBytes []byte, err error)

MarshalDN converts a DN to distinguished name (DN), ASN.1 DER form.

dn := dnutil.DN{dnutil.RDN{dnutil.AttributeTypeAndValue{Type: dnutil.CommonName, Value: dnutil.AttributeValue{Encoding: dnutil.UTF8String, Value: "cn1"}}},}
b, err := dnutil.MarshalDN(d)
func ParseDERDN(dnBytes []byte) (dn DN, err error)

ParseDERDn parses a distinguished name, ASN.1 DER form and returns DN.

//CN=abc (UTF8String)
b := []byte{0x30, 0x0e, 0x31, 0x0c, 0x30, 0x0a, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x03, 0x61, 0x62, 0x63}
dn, err := dnutil.ParseDERDN(b)
Note:
  • AttributeValue of the relative distinguished name currently supported are following ASN.1 string encodings:
PrintableString
UTF8String
IA5String
  • AttributeTypeAndValue of the relative distinguished name currently supported are following combinations of OBJECT IDENTIFIER of AttributeType and Encoding of the AttributeValue:
2.5.4.6  : PrintableString
2.5.4.10 : PrintableString or UTF8String
2.5.4.11 : PrintableString or UTF8String
2.5.4.46 : PrintableString
2.5.4.8 : PrintableString or UTF8String
2.5.4.3 : PrintableString or UTF8String
2.5.4.5  : PrintableString
2.5.4.7 : PrintableString or UTF8String
2.5.4.12 : PrintableString or UTF8String
2.5.4.4 : PrintableString or UTF8String
2.5.4.42 : PrintableString or UTF8String
2.5.4.43 : PrintableString or UTF8String
2.5.4.65 : PrintableString or UTF8String
2.5.4.44 : PrintableString or UTF8String
1.2.840.113549.1.9.1 : IA5String
0.9.2342.19200300.100.1.25 : IA5String
The other OBJECT IDENTIFIER : PrintableString or UTF8String or IA5String
func (d DN) ToRFC4514FormatString() string

ToRFC4514FormatString returns an RFC4514 Format string of the DN.

d := dnutil.DN{
	dnutil.RDN{dnutil.AttributeTypeAndValue{Type: dnutil.CountryName, Value: dnutil.AttributeValue{Encoding: dnutil.PrintableString, Value: "JP"}}},
	dnutil.RDN{dnutil.AttributeTypeAndValue{Type: dnutil.OrganizationName, Value: dnutil.AttributeValue{Encoding: dnutil.UTF8String, Value: "example Co., Ltd"}}},
	dnutil.RDN{dnutil.AttributeTypeAndValue{Type: dnutil.OrganizationalUnit, Value: dnutil.AttributeValue{Encoding: dnutil.UTF8String, Value: "A,B;"}}},
	dnutil.RDN{
		dnutil.AttributeTypeAndValue{Type: dnutil.OrganizationalUnit, Value: dnutil.AttributeValue{Encoding: dnutil.UTF8String, Value: "#Dev"}},
		dnutil.AttributeTypeAndValue{Type: dnutil.OrganizationalUnit, Value: dnutil.AttributeValue{Encoding: dnutil.UTF8String, Value: " Sales"}},
	},
	dnutil.RDN{
		dnutil.AttributeTypeAndValue{Type: dnutil.CommonName, Value: dnutil.AttributeValue{Encoding: dnutil.UTF8String, Value: "ex"}},
		dnutil.AttributeTypeAndValue{Type: dnutil.Generic, Oid: "0.9.2342.19200300.100.1.1", Value: dnutil.AttributeValue{Encoding: dnutil.UTF8String, Value: "userid_0001"}},
		dnutil.AttributeTypeAndValue{Type: dnutil.ElectronicMailAddress, Value: dnutil.AttributeValue{Encoding: dnutil.IA5String, Value: "ex@example.com"}}},
}
RFC4514 section2 Format: CN=ex+0.9.2342.19200300.100.1.1=userid_0001+EMAIL=ex@example.com,OU=\#Dev+OU=\ Sales,OU=A\,B\;,O=example Co.\, Ltd,C=JP
func ValidateCountryCode(c string) (bool, error)

ValidateCountryCode validates whether c is a valid ISO-3166-Alpha2-code.

isValid, err := ValidateCountryCode("JP")

License

BSD 3-Clause

Documentation

Overview

Package dnutil implements a library for easy handling of distinguished name.

dnutil is a library for easy handling of distinguished name.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MarshalDN

func MarshalDN(dn DN) (dnBytes []byte, err error)

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

func ValidateCountryCode(c string) (bool, error)

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

type AttributeValue struct {
	Encoding Encoding
	Value    string
}

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

func ParseDERDN(dnBytes []byte) (dn DN, err error)

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) CountRDN

func (d DN) CountRDN() int

CountRDN returns number of RDN of DN.

func (DN) RetrieveRDN added in v0.3.0

func (d DN) RetrieveRDN(index int) (rdn RDN, err error)

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

func (d DN) RetrieveRDNsByOids(oids []string) (rdns []RDN)

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

func (d DN) ReverseDnOrder() DN

ReverseDnOrder returns a new reverse order DN.

func (DN) String added in v0.5.0

func (d DN) String() string

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

func (d DN) ToRFC4514FormatString() string

ToRFC4514FormatString returns an RFC4514 Format string of this DN.

type Encoding

type Encoding int
const (
	PrintableString Encoding = iota + 1
	UTF8String
	IA5String
)

func (Encoding) String

func (e Encoding) String() string

type RDN

RDN represents an ASN.1 RelativeDistinguishedName object. https://datatracker.ietf.org/doc/html/rfc5280#section-4.1.2.4

func (RDN) CountAttributeTypeAndValue

func (r RDN) CountAttributeTypeAndValue() int

CountAttributeTypeAndValue returns number of AttributeTypeAndValue of RDN.

func (RDN) String added in v0.5.0

func (r RDN) String() string

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

func (r RDN) ToRFC4514FormatString() string

ToRFC4514FormatString returns an RFC4514 Format string of this RDN.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL