github.com/lestrrat-go/jwx/v2@v2.0.21/jwe/internal/concatkdf/concatkdf_test.go (about) 1 package concatkdf 2 3 import ( 4 "crypto" 5 "testing" 6 7 "github.com/lestrrat-go/jwx/v2/jwa" 8 "github.com/stretchr/testify/assert" 9 ) 10 11 // https://tools.ietf.org/html/rfc7518#appendix-C 12 func TestAppendix(t *testing.T) { 13 z := []byte{158, 86, 217, 29, 129, 113, 53, 211, 114, 131, 66, 131, 191, 132, 14 38, 156, 251, 49, 110, 163, 218, 128, 106, 72, 246, 218, 167, 121, 15 140, 254, 144, 196} 16 alg := []byte(jwa.A128GCM.String()) 17 apu := []byte{65, 108, 105, 99, 101} 18 apv := []byte{66, 111, 98} 19 pub := []byte{0, 0, 0, 128} 20 priv := []byte(nil) 21 expected := []byte{86, 170, 141, 234, 248, 35, 109, 32, 92, 34, 40, 205, 113, 167, 16, 26} 22 23 kdf := New(crypto.SHA256, alg, z, apu, apv, pub, priv) 24 25 out := make([]byte, 16) // 128bits 26 27 n, err := kdf.Read(out[:5]) 28 if !assert.Equal(t, 5, n, "first read bytes matches") || 29 !assert.NoError(t, err, "first read successful") { 30 return 31 } 32 33 n, err = kdf.Read(out[5:]) 34 if !assert.Equal(t, 11, n, "second read bytes matches") || 35 !assert.NoError(t, err, "second read successful") { 36 return 37 } 38 39 if !assert.Equal(t, expected, out, "generated value matches") { 40 return 41 } 42 }