Source File
pkix.go
Belonging Package
crypto/x509/pkix
package pkix
import (
)
type AlgorithmIdentifier struct {
Algorithm asn1.ObjectIdentifier
Parameters asn1.RawValue `asn1:"optional"`
}
type RDNSequence []RelativeDistinguishedNameSET
var attributeTypeNames = map[string]string{
"2.5.4.6": "C",
"2.5.4.10": "O",
"2.5.4.11": "OU",
"2.5.4.3": "CN",
"2.5.4.5": "SERIALNUMBER",
"2.5.4.7": "L",
"2.5.4.8": "ST",
"2.5.4.9": "STREET",
"2.5.4.17": "POSTALCODE",
}
func ( RDNSequence) () string {
:= ""
for := 0; < len(); ++ {
:= [len()-1-]
if > 0 {
+= ","
}
for , := range {
if > 0 {
+= "+"
}
:= .Type.String()
, := attributeTypeNames[]
if ! {
, := asn1.Marshal(.Value)
if == nil {
+= + "=#" + hex.EncodeToString()
continue // No value escaping necessary.
}
=
}
:= fmt.Sprint(.Value)
:= make([]rune, 0, len())
for , := range {
:= false
switch {
case ',', '+', '"', '\\', '<', '>', ';':
= true
case ' ':
= == 0 || == len()-1
case '#':
= == 0
}
if {
= append(, '\\', )
} else {
= append(, )
}
}
+= + "=" + string()
}
}
return
}
type RelativeDistinguishedNameSET []AttributeTypeAndValue
type AttributeTypeAndValue struct {
Type asn1.ObjectIdentifier
Value interface{}
}
type AttributeTypeAndValueSET struct {
Type asn1.ObjectIdentifier
Value [][]AttributeTypeAndValue `asn1:"set"`
}
type Name struct {
Country, Organization, OrganizationalUnit []string
Locality, Province []string
StreetAddress, PostalCode []string
SerialNumber, CommonName string
func ( *Name) ( *RDNSequence) {
for , := range * {
if len() == 0 {
continue
}
for , := range {
.Names = append(.Names, )
, := .Value.(string)
if ! {
continue
}
:= .Type
if len() == 4 && [0] == 2 && [1] == 5 && [2] == 4 {
switch [3] {
case 3:
.CommonName =
case 5:
.SerialNumber =
case 6:
.Country = append(.Country, )
case 7:
.Locality = append(.Locality, )
case 8:
.Province = append(.Province, )
case 9:
.StreetAddress = append(.StreetAddress, )
case 10:
.Organization = append(.Organization, )
case 11:
.OrganizationalUnit = append(.OrganizationalUnit, )
case 17:
.PostalCode = append(.PostalCode, )
}
}
}
}
}
var (
oidCountry = []int{2, 5, 4, 6}
oidOrganization = []int{2, 5, 4, 10}
oidOrganizationalUnit = []int{2, 5, 4, 11}
oidCommonName = []int{2, 5, 4, 3}
oidSerialNumber = []int{2, 5, 4, 5}
oidLocality = []int{2, 5, 4, 7}
oidProvince = []int{2, 5, 4, 8}
oidStreetAddress = []int{2, 5, 4, 9}
oidPostalCode = []int{2, 5, 4, 17}
)
func ( Name) ( RDNSequence, []string, asn1.ObjectIdentifier) RDNSequence {
if len() == 0 || oidInAttributeTypeAndValue(, .ExtraNames) {
return
}
:= make([]AttributeTypeAndValue, len())
for , := range {
[].Type =
[].Value =
}
return append(, )
}
func ( Name) () ( RDNSequence) {
= .appendRDNs(, .Country, oidCountry)
= .appendRDNs(, .Province, oidProvince)
= .appendRDNs(, .Locality, oidLocality)
= .appendRDNs(, .StreetAddress, oidStreetAddress)
= .appendRDNs(, .PostalCode, oidPostalCode)
= .appendRDNs(, .Organization, oidOrganization)
= .appendRDNs(, .OrganizationalUnit, oidOrganizationalUnit)
if len(.CommonName) > 0 {
= .appendRDNs(, []string{.CommonName}, oidCommonName)
}
if len(.SerialNumber) > 0 {
= .appendRDNs(, []string{.SerialNumber}, oidSerialNumber)
}
for , := range .ExtraNames {
= append(, []AttributeTypeAndValue{})
}
return
}
if .ExtraNames == nil {
for , := range .Names {
:= .Type
if len() == 4 && [0] == 2 && [1] == 5 && [2] == 4 {
switch [3] {
continue
}
= append(, []AttributeTypeAndValue{})
}
}
= append(, .ToRDNSequence()...)
return .String()
}
func ( asn1.ObjectIdentifier, []AttributeTypeAndValue) bool {
for , := range {
if .Type.Equal() {
return true
}
}
return false
}
func ( *CertificateList) ( time.Time) bool {
return !.Before(.TBSCertList.NextUpdate)
}
type TBSCertificateList struct {
Raw asn1.RawContent
Version int `asn1:"optional,default:0"`
Signature AlgorithmIdentifier
Issuer RDNSequence
ThisUpdate time.Time
NextUpdate time.Time `asn1:"optional"`
RevokedCertificates []RevokedCertificate `asn1:"optional"`
Extensions []Extension `asn1:"tag:0,optional,explicit"`
}
type RevokedCertificate struct {
SerialNumber *big.Int
RevocationTime time.Time
Extensions []Extension `asn1:"optional"`
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |