gitee.com/lh-her-team/common@v1.5.1/crypto/x509/utils.go (about) 1 package x509 2 3 import ( 4 "encoding/pem" 5 "fmt" 6 ) 7 8 func GetOUFromPEM(certPEM []byte) ([]string, error) { 9 pemBlock, _ := pem.Decode(certPEM) 10 if pemBlock == nil { 11 return nil, fmt.Errorf("fail to parse certificate") 12 } 13 cert, err := ParseCertificate(pemBlock.Bytes) 14 if err != nil { 15 return nil, fmt.Errorf("fail to parse certificate: [%v]", err) 16 } 17 return cert.Subject.OrganizationalUnit, nil 18 }