Scott Baker | 8461e15 | 2019-10-01 14:44:30 -0700 | [diff] [blame] | 1 | package types |
| 2 | |
| 3 | import ( |
| 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 |
| 11 | type 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 |
| 19 | type 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 |
| 25 | type Checksum struct { |
| 26 | CksumType int32 `asn1:"explicit,tag:0"` |
| 27 | Checksum []byte `asn1:"explicit,tag:1"` |
| 28 | } |
| 29 | |
| 30 | // Unmarshal bytes into the EncryptedData. |
| 31 | func (a *EncryptedData) Unmarshal(b []byte) error { |
| 32 | _, err := asn1.Unmarshal(b, a) |
| 33 | return err |
| 34 | } |
| 35 | |
| 36 | // Marshal the EncryptedData. |
| 37 | func (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. |
| 46 | func (a *EncryptionKey) Unmarshal(b []byte) error { |
| 47 | _, err := asn1.Unmarshal(b, a) |
| 48 | return err |
| 49 | } |
| 50 | |
| 51 | // Unmarshal bytes into the Checksum. |
| 52 | func (a *Checksum) Unmarshal(b []byte) error { |
| 53 | _, err := asn1.Unmarshal(b, a) |
| 54 | return err |
| 55 | } |