Skip to content

Commit

Permalink
feat: specific error for not found attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
secDre4mer committed Apr 8, 2024
1 parent c372611 commit b018e1a
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,12 +350,20 @@ func getCertFromCertsByIssuerAndSerial(certs []*x509.Certificate, ias issuerAndS
return nil
}

type AttributeNotFoundError struct {
AttributeType asn1.ObjectIdentifier
}

func (a AttributeNotFoundError) Error() string {
return fmt.Sprintf("pkcs7: attribute %s does not exist", a.AttributeType)
}

func unmarshalAttribute(attrs []attribute, attributeType asn1.ObjectIdentifier, out interface{}) error {
for _, attr := range attrs {
if attr.Type.Equal(attributeType) {
_, err := asn1.Unmarshal(attr.Value.Bytes, out)
return err
}
}
return errors.New("pkcs7: attribute type not in attributes")
return AttributeNotFoundError{AttributeType: attributeType}
}

0 comments on commit b018e1a

Please sign in to comment.