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