Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EncryptedContent needs to be implicitly tagged and not explicit (updated) #18

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions encrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
18 changes: 18 additions & 0 deletions encrypt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"crypto/x509"
"crypto/x509/pkix"
"encoding/asn1"
"reflect"
"testing"
)

Expand Down Expand Up @@ -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)
}
}
Loading