forked from coreos/etcd-ca
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cert_info.go
34 lines (26 loc) · 870 Bytes
/
cert_info.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
package pkix
import (
"math/big"
)
// CertificateAuthorityInfo includes extra information required for CA
type CertificateAuthorityInfo struct {
// SerialNumber that has been used so far
// Recorded to ensure all serial numbers issued by the CA are different
SerialNumber *big.Int
}
func NewCertificateAuthorityInfo(serialNumber int64) *CertificateAuthorityInfo {
return &CertificateAuthorityInfo{big.NewInt(serialNumber)}
}
func NewCertificateAuthorityInfoFromJSON(data []byte) (*CertificateAuthorityInfo, error) {
i := big.NewInt(0)
if err := i.UnmarshalJSON(data); err != nil {
return nil, err
}
return &CertificateAuthorityInfo{i}, nil
}
func (n *CertificateAuthorityInfo) IncSerialNumber() {
n.SerialNumber.Add(n.SerialNumber, big.NewInt(1))
}
func (n *CertificateAuthorityInfo) Export() ([]byte, error) {
return n.SerialNumber.MarshalJSON()
}