-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathencrypt_test.go
59 lines (45 loc) · 1.39 KB
/
encrypt_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package xmlenc
import (
"crypto/x509"
"encoding/pem"
"math/rand"
"testing"
"github.com/beevik/etree"
"gotest.tools/assert"
"gotest.tools/golden"
)
func TestCanEncryptOAEP(t *testing.T) {
t.Run("CBC", func(t *testing.T) {
RandReader = rand.New(rand.NewSource(0)) //nolint:gosec // deterministic random numbers for tests
pemBlock, _ := pem.Decode(golden.Get(t, "cert.pem"))
certificate, err := x509.ParseCertificate(pemBlock.Bytes)
assert.Check(t, err)
e := OAEP()
e.BlockCipher = AES128CBC
e.DigestMethod = &SHA1
el, err := e.Encrypt(certificate, golden.Get(t, "plaintext.xml"), nil)
assert.Check(t, err)
doc := etree.NewDocument()
doc.SetRoot(el)
doc.IndentTabs()
ciphertext, _ := doc.WriteToString()
golden.Assert(t, ciphertext, "ciphertext.xml")
})
t.Run("GCM", func(t *testing.T) {
RandReader = rand.New(rand.NewSource(0)) //nolint:gosec // deterministic random numbers for tests
cert := golden.Get(t, "cert.cert")
b, _ := pem.Decode(cert)
certificate, err := x509.ParseCertificate(b.Bytes)
assert.Check(t, err)
e := OAEP()
e.BlockCipher = AES128GCM
e.DigestMethod = &SHA1
el, err := e.Encrypt(certificate, golden.Get(t, "plaintext_gcm.xml"), []byte("1234567890AZ"))
assert.Check(t, err)
doc := etree.NewDocument()
doc.SetRoot(el)
doc.Indent(4)
ciphertext, _ := doc.WriteToString()
golden.Assert(t, ciphertext, "ciphertext_gcm.xml")
})
}