github.com/jcmturner/gokrb5/v8@v8.4.4/types/Cryptosystem_test.go (about) 1 package types 2 3 import ( 4 "encoding/hex" 5 "testing" 6 7 "github.com/jcmturner/gokrb5/v8/iana" 8 "github.com/jcmturner/gokrb5/v8/test/testdata" 9 "github.com/stretchr/testify/assert" 10 ) 11 12 func TestUnmarshalEncryptedData(t *testing.T) { 13 t.Parallel() 14 var a EncryptedData 15 b, err := hex.DecodeString(testdata.MarshaledKRB5enc_data) 16 if err != nil { 17 t.Fatalf("Test vector read error: %v", err) 18 } 19 err = a.Unmarshal(b) 20 if err != nil { 21 t.Fatalf("Unmarshal error: %v", err) 22 } 23 assert.Equal(t, testdata.TEST_ETYPE, a.EType, "Encrypted data Etype not as expected") 24 assert.Equal(t, iana.PVNO, a.KVNO, "Encrypted data KVNO not as expected") 25 assert.Equal(t, []byte(testdata.TEST_CIPHERTEXT), a.Cipher, "Ecrypted data ciphertext not as expected") 26 } 27 28 func TestUnmarshalEncryptedData_MSBsetkvno(t *testing.T) { 29 t.Parallel() 30 var a EncryptedData 31 b, err := hex.DecodeString(testdata.MarshaledKRB5enc_dataMSBSetkvno) 32 if err != nil { 33 t.Fatalf("Test vector read error: %v", err) 34 } 35 err = a.Unmarshal(b) 36 if err != nil { 37 t.Fatalf("Unmarshal error: %v", err) 38 } 39 assert.Equal(t, testdata.TEST_ETYPE, a.EType, "Encrypted data Etype not as expected") 40 assert.Equal(t, -16777216, a.KVNO, "Encrypted data KVNO not as expected") 41 assert.Equal(t, []byte(testdata.TEST_CIPHERTEXT), a.Cipher, "Ecrypted data ciphertext not as expected") 42 } 43 44 func TestUnmarshalEncryptedData_kvno_neg1(t *testing.T) { 45 t.Parallel() 46 var a EncryptedData 47 b, err := hex.DecodeString(testdata.MarshaledKRB5enc_dataKVNONegOne) 48 if err != nil { 49 t.Fatalf("Test vector read error: %v", err) 50 } 51 err = a.Unmarshal(b) 52 if err != nil { 53 t.Fatalf("Unmarshal error: %v", err) 54 } 55 assert.Equal(t, testdata.TEST_ETYPE, a.EType, "Encrypted data Etype not as expected") 56 assert.Equal(t, -1, a.KVNO, "Encrypted data KVNO not as expected") 57 assert.Equal(t, []byte(testdata.TEST_CIPHERTEXT), a.Cipher, "Ecrypted data ciphertext not as expected") 58 } 59 60 func TestUnmarshalEncryptionKey(t *testing.T) { 61 t.Parallel() 62 var a EncryptionKey 63 b, err := hex.DecodeString(testdata.MarshaledKRB5keyblock) 64 if err != nil { 65 t.Fatalf("Test vector read error: %v", err) 66 } 67 err = a.Unmarshal(b) 68 if err != nil { 69 t.Fatalf("Unmarshal error: %v", err) 70 } 71 assert.Equal(t, int32(1), a.KeyType, "Key type not as expected") 72 assert.Equal(t, []byte("12345678"), a.KeyValue, "Key value not as expected") 73 } 74 75 func TestMarshalEncryptedData(t *testing.T) { 76 t.Parallel() 77 var a EncryptedData 78 b, err := hex.DecodeString(testdata.MarshaledKRB5enc_data) 79 if err != nil { 80 t.Fatalf("Test vector read error: %v", err) 81 } 82 err = a.Unmarshal(b) 83 if err != nil { 84 t.Fatalf("Unmarshal error: %v", err) 85 } 86 mb, err := a.Marshal() 87 if err != nil { 88 t.Fatalf("Marshal of ticket errored: %v", err) 89 } 90 assert.Equal(t, b, mb, "Marshal bytes of Encrypted Data not as expected") 91 }