Add critical bool arg to MarshalSubjectAltName to allow SANs to be critical (#367)

This commit is contained in:
Liam Murphy 2024-03-27 10:34:46 +11:00 committed by GitHub
parent e6ab626979
commit 5b3763098f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -149,8 +149,9 @@ func forEachSAN(extension []byte, callback func(ext asn1.RawValue) error) error
return nil
}
// MarshalSubjectAltName converts a SubjectAltName struct into a pkix.Extension.
func MarshalSubjectAltName(san *SubjectAltName) (pkix.Extension, error) {
// MarshalSubjectAltName converts a SubjectAltName struct into a pkix.Extension,
// allowing callers to specify if the extension is critical.
func MarshalSubjectAltName(san *SubjectAltName, critical bool) (pkix.Extension, error) {
var generalNames []asn1.RawValue
for _, permID := range san.PermanentIdentifiers {
val, err := marshalOtherName(oidPermanentIdentifier, permID)
@ -171,7 +172,8 @@ func MarshalSubjectAltName(san *SubjectAltName) (pkix.Extension, error) {
return pkix.Extension{}, err
}
return pkix.Extension{
Id: oid.SubjectAltName,
Value: val,
Id: oid.SubjectAltName,
Critical: critical,
Value: val,
}, nil
}