diff --git a/encrypt.go b/encrypt.go index 4c02e40..a5c96e7 100644 --- a/encrypt.go +++ b/encrypt.go @@ -443,8 +443,7 @@ func EncryptUsingPSK(content []byte, key []byte) ([]byte, error) { } func marshalEncryptedContent(content []byte) asn1.RawValue { - asn1Content, _ := asn1.Marshal(content) - return asn1.RawValue{Tag: 0, Class: 2, Bytes: asn1Content, IsCompound: true} + return asn1.RawValue{Bytes: content, Class: 2, IsCompound: false} } func encryptKey(key []byte, recipient *x509.Certificate, algorithm asn1.ObjectIdentifier, hash crypto.Hash) ([]byte, error) { diff --git a/encrypt_test.go b/encrypt_test.go index 826cb5a..f91011d 100644 --- a/encrypt_test.go +++ b/encrypt_test.go @@ -6,6 +6,7 @@ import ( "crypto/x509" "crypto/x509/pkix" "encoding/asn1" + "reflect" "testing" ) @@ -144,3 +145,20 @@ func Test_getParametersForKeyEncryptionAlgorithm(t *testing.T) { }) } } + +func Test_marshalEncryptedContent(t *testing.T) { + content := []byte{} + got := marshalEncryptedContent(content) + + expected := asn1.RawValue{Class: 2, Tag: 0, IsCompound: false, Bytes: []byte{}, FullBytes: nil} + if !reflect.DeepEqual(expected, got) { + t.Errorf("marshalEncryptedContent() = %v, want %v", got, expected) + } + + content = []byte{34, 165, 121, 103, 15, 109, 119, 147, 39, 236, 212, 103, 143, 164, 172, 22} + got = marshalEncryptedContent(content) + expected = asn1.RawValue{Class: 2, Tag: 0, IsCompound: false, Bytes: []byte{34, 165, 121, 103, 15, 109, 119, 147, 39, 236, 212, 103, 143, 164, 172, 22}, FullBytes: nil} + if !reflect.DeepEqual(expected, got) { + t.Errorf("marshalEncryptedContent() = %v, want %v", got, expected) + } +}