| 1 | package timestamp |
| 2 | |
| 3 | import ( |
| 4 | "crypto/x509/pkix" |
| 5 | "encoding/asn1" |
| 6 | "math/big" |
| 7 | "time" |
| 8 | ) |
| 9 | |
| 10 | // http://www.ietf.org/rfc/rfc3161.txt |
| 11 | // 2.4.1. Request Format |
| 12 | type request struct { |
| 13 | Version int |
| 14 | MessageImprint messageImprint |
| 15 | ReqPolicy asn1.ObjectIdentifier `asn1:"optional"` |
| 16 | Nonce *big.Int `asn1:"optional"` |
| 17 | CertReq bool `asn1:"optional,default:false"` |
| 18 | Extensions []pkix.Extension `asn1:"tag:0,optional"` |
| 19 | } |
| 20 | |
| 21 | type messageImprint struct { |
| 22 | HashAlgorithm pkix.AlgorithmIdentifier |
| 23 | HashedMessage []byte |
| 24 | } |
| 25 | |
| 26 | // 2.4.2. Response Format |
| 27 | type response struct { |
| 28 | Status pkiStatusInfo |
| 29 | TimeStampToken asn1.RawValue `asn1:"optional"` |
| 30 | } |
| 31 | |
| 32 | type pkiStatusInfo struct { |
| 33 | Status Status |
| 34 | StatusString []string `asn1:"optional,utf8"` |
| 35 | FailInfo asn1.BitString `asn1:"optional"` |
| 36 | } |
| 37 | |
| 38 | func (s pkiStatusInfo) FailureInfo() FailureInfo { |
| 39 | fi := []FailureInfo{BadAlgorithm, BadRequest, BadDataFormat, TimeNotAvailable, |
| 40 | UnacceptedPolicy, UnacceptedExtension, AddInfoNotAvailable, SystemFailure} |
| 41 | |
| 42 | for _, f := range fi { |
| 43 | if s.FailInfo.At(int(f)) != 0 { |
| 44 | return f |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | return UnknownFailureInfo |
| 49 | } |
| 50 | |
| 51 | // eContent within SignedData is TSTInfo |
| 52 | type tstInfo struct { |
| 53 | Version int |
| 54 | Policy asn1.ObjectIdentifier |
| 55 | MessageImprint messageImprint |
| 56 | SerialNumber *big.Int |
| 57 | Time time.Time `asn1:"generalized"` |
| 58 | Accuracy accuracy `asn1:"optional"` |
| 59 | Ordering bool `asn1:"optional,default:false"` |
| 60 | Nonce *big.Int `asn1:"optional"` |
| 61 | TSA asn1.RawValue `asn1:"tag:0,optional"` |
| 62 | Extensions []pkix.Extension `asn1:"tag:1,optional"` |
| 63 | } |
| 64 | |
| 65 | // accuracy within TSTInfo |
| 66 | type accuracy struct { |
| 67 | Seconds int64 `asn1:"optional"` |
| 68 | Milliseconds int64 `asn1:"tag:0,optional"` |
| 69 | Microseconds int64 `asn1:"tag:1,optional"` |
| 70 | } |
| 71 | |
| 72 | type qcStatement struct { |
| 73 | StatementID asn1.ObjectIdentifier |
| 74 | StatementInfo asn1.RawValue `asn1:"optional"` |
| 75 | } |