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 May 3, 2024
1 parent bf12d97 commit 318f32c
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 318f32c

Please sign in to comment.