go_S-MIME/timestamp/response.go

46 lines
998 B
Go
Raw Permalink Normal View History

package timestamp
import (
2022-10-22 10:03:53 +00:00
asn "git.ma-al.com/goc_marek/go_S-MIME/asn1"
cms "git.ma-al.com/goc_marek/go_S-MIME/cms/protocol"
)
2022-10-22 10:03:53 +00:00
// TimeStampResp ::= SEQUENCE {
// status PKIStatusInfo,
// timeStampToken TimeStampToken OPTIONAL }
type TimeStampResp struct {
Status PKIStatusInfo
TimeStampToken cms.ContentInfo `asn1:"optional"`
}
// ParseResponse parses a ASN.1 encoded TimeStampResp.
func ParseResponse(der []byte) (TimeStampResp, error) {
var resp TimeStampResp
rest, err := asn.Unmarshal(der, &resp)
if err != nil {
return resp, err
}
if len(rest) > 0 {
return resp, cms.ErrTrailingData
}
return resp, nil
}
// Info returns the timestampinfo from a response.
func (r TimeStampResp) Info() (TSTInfo, error) {
var nilInfo TSTInfo
if err := r.Status.GetError(); err != nil {
return nilInfo, err
}
sd, err := r.TimeStampToken.SignedDataContent()
if err != nil {
return nilInfo, err
}
return ParseInfo(sd.EncapContentInfo)
}