github.com/hyperledger/aries-framework-go@v0.3.2/pkg/didcomm/packer/legacy/authcrypt/authcrypt.go (about) 1 /* 2 Copyright SecureKey Technologies Inc. All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0 5 */ 6 7 package authcrypt 8 9 import ( 10 "crypto/rand" 11 "io" 12 13 "github.com/hyperledger/aries-framework-go/pkg/didcomm/packer" 14 "github.com/hyperledger/aries-framework-go/pkg/kms" 15 ) 16 17 // Packer represents an Authcrypt Pack/Unpacker that outputs/reads legacy Aries envelopes. 18 type Packer struct { 19 randSource io.Reader 20 kms kms.KeyManager 21 } 22 23 // encodingType is the `typ` string identifier in a message that identifies the format as being legacy. 24 const encodingType string = "JWM/1.0" 25 26 // New will create a Packer that encrypts messages using the legacy Aries format. 27 // Note: legacy Packer does not support XChacha20Poly1035 (XC20P), only Chacha20Poly1035 (C20P). 28 func New(ctx packer.Provider) *Packer { 29 k := ctx.KMS() 30 31 return &Packer{ 32 randSource: rand.Reader, 33 kms: k, 34 } 35 } 36 37 // legacyEnvelope is the full payload envelope for the JSON message. 38 type legacyEnvelope struct { 39 Protected string `json:"protected,omitempty"` 40 IV string `json:"iv,omitempty"` 41 CipherText string `json:"ciphertext,omitempty"` 42 Tag string `json:"tag,omitempty"` 43 } 44 45 // protected is the protected header of the JSON envelope. 46 type protected struct { 47 Enc string `json:"enc,omitempty"` 48 Typ string `json:"typ,omitempty"` 49 Alg string `json:"alg,omitempty"` 50 Recipients []recipient `json:"recipients,omitempty"` 51 } 52 53 // recipient holds the data for a recipient in the envelope header. 54 type recipient struct { 55 EncryptedKey string `json:"encrypted_key,omitempty"` 56 Header recipientHeader `json:"header,omitempty"` 57 } 58 59 // recipientHeader holds the header data for a recipient. 60 type recipientHeader struct { 61 KID string `json:"kid,omitempty"` 62 Sender string `json:"sender,omitempty"` 63 IV string `json:"iv,omitempty"` 64 } 65 66 // EncodingType returns the type of the encoding, as in the `Typ` field of the envelope header. 67 func (p *Packer) EncodingType() string { 68 return encodingType 69 }