github.com/bigzoro/my_simplechain@v0.0.0-20240315012955-8ad0a2a29bb9/core/access_contoller/crypto/x509/utils.go (about) 1 /* 2 Copyright (C) BABEC. All rights reserved. 3 Copyright (C) THL A29 Limited, a Tencent company. All rights reserved. 4 5 SPDX-License-Identifier: Apache-2.0 6 */ 7 package x509 8 9 import ( 10 "encoding/pem" 11 "fmt" 12 ) 13 14 func GetOUFromPEM(certPEM []byte) ([]string, error) { 15 pemBlock, _ := pem.Decode(certPEM) 16 if pemBlock == nil { 17 return nil, fmt.Errorf("fail to parse certificate") 18 } 19 cert, err := ParseCertificate(pemBlock.Bytes) 20 if err != nil { 21 return nil, fmt.Errorf("fail to parse certificate: [%v]", err) 22 } 23 return cert.Subject.OrganizationalUnit, nil 24 }