Cryptosystem.go 1.4 KB

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