blob: 7e8b4ab2969cc764cb5f97bb8541fcecf361036f [file] [log] [blame]
Scott Baker8461e152019-10-01 14:44:30 -07001package types
2
3import (
4 "github.com/jcmturner/gofork/encoding/asn1"
5)
6
7// Reference: https://www.ietf.org/rfc/rfc4120.txt
8// Section: 5.2.9
9
10// EncryptedData implements RFC 4120 type: https://tools.ietf.org/html/rfc4120#section-5.2.9
11type EncryptedData struct {
12 EType int32 `asn1:"explicit,tag:0"`
13 KVNO int `asn1:"explicit,optional,tag:1"`
14 Cipher []byte `asn1:"explicit,tag:2"`
15}
16
17// EncryptionKey implements RFC 4120 type: https://tools.ietf.org/html/rfc4120#section-5.2.9
18// AKA KeyBlock
19type EncryptionKey struct {
20 KeyType int32 `asn1:"explicit,tag:0"`
21 KeyValue []byte `asn1:"explicit,tag:1"`
22}
23
24// Checksum implements RFC 4120 type: https://tools.ietf.org/html/rfc4120#section-5.2.9
25type Checksum struct {
26 CksumType int32 `asn1:"explicit,tag:0"`
27 Checksum []byte `asn1:"explicit,tag:1"`
28}
29
30// Unmarshal bytes into the EncryptedData.
31func (a *EncryptedData) Unmarshal(b []byte) error {
32 _, err := asn1.Unmarshal(b, a)
33 return err
34}
35
36// Marshal the EncryptedData.
37func (a *EncryptedData) Marshal() ([]byte, error) {
38 edb, err := asn1.Marshal(*a)
39 if err != nil {
40 return edb, err
41 }
42 return edb, nil
43}
44
45// Unmarshal bytes into the EncryptionKey.
46func (a *EncryptionKey) Unmarshal(b []byte) error {
47 _, err := asn1.Unmarshal(b, a)
48 return err
49}
50
51// Unmarshal bytes into the Checksum.
52func (a *Checksum) Unmarshal(b []byte) error {
53 _, err := asn1.Unmarshal(b, a)
54 return err
55}