/
p12_crl.go
58 lines (44 loc) · 1.37 KB
/
p12_crl.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
package pkcs12
import (
"errors"
"encoding/asn1"
)
type CRLBagData struct {
Id asn1.ObjectIdentifier
Data []byte `asn1:"tag:0,explicit"`
}
type CRLBagEntry struct {}
func NewCRLBagEntry() *CRLBagEntry {
return &CRLBagEntry{}
}
func (this *CRLBagEntry) DecodeCertBag(asn1Data []byte) (cert []byte, err error) {
bag := new(CRLBagData)
if err := unmarshal(asn1Data, bag); err != nil {
return nil, errors.New("pkcs12: error decoding crl bag: " + err.Error())
}
if !bag.Id.Equal(oidCertTypeX509CRL) {
return nil, NotImplementedError("crl: oid is not support")
}
return bag.Data, nil
}
func (this *CRLBagEntry) EncodeCertBag(cert []byte) (asn1Data []byte, err error) {
var bag CRLBagData
bag.Id = oidCertTypeX509CRL
bag.Data = cert
if asn1Data, err = asn1.Marshal(bag); err != nil {
return nil, errors.New("pkcs12: error encoding crl bag: " + err.Error())
}
return asn1Data, nil
}
func (this *CRLBagEntry) MakeCertBag(certBytes []byte, attributes []PKCS12Attribute) (certBag *SafeBag, err error) {
certBag = new(SafeBag)
certBag.Id = oidCRLBag
certBag.Value.Class = 2
certBag.Value.Tag = 0
certBag.Value.IsCompound = true
if certBag.Value.Bytes, err = this.EncodeCertBag(certBytes); err != nil {
return nil, err
}
certBag.Attributes = attributes
return
}