From f89b613cd170f54e81ecb1db65dc6d58cf02bd05 Mon Sep 17 00:00:00 2001 From: Morten Linderud Date: Sun, 6 Aug 2023 22:53:30 +0200 Subject: [PATCH] key_test: Add tests for comments Signed-off-by: Morten Linderud --- key/key_test.go | 47 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 9 deletions(-) diff --git a/key/key_test.go b/key/key_test.go index c3acb6e..946c098 100644 --- a/key/key_test.go +++ b/key/key_test.go @@ -57,9 +57,11 @@ func mustPrivate(data []byte) tpm2.TPM2BPrivate { func TestMarshalling(t *testing.T) { cases := []struct { - k *Key + text string + k *Key }{ { + text: "ecdsa/haspin", k: &Key{ Version: 1, PIN: HasPIN, @@ -69,6 +71,7 @@ func TestMarshalling(t *testing.T) { }, }, { + text: "ecdsa/nopin", k: &Key{ Version: 1, PIN: NoPIN, @@ -78,6 +81,18 @@ func TestMarshalling(t *testing.T) { }, }, { + text: "ecdsa/comment", + k: &Key{ + Version: 1, + PIN: HasPIN, + Type: tpm2.TPMAlgECDSA, + Public: mustPublic([]byte("public")), + Private: mustPrivate([]byte("private")), + Comment: []byte("This is a comment"), + }, + }, + { + text: "rsa/haspin", k: &Key{ Version: 1, PIN: HasPIN, @@ -87,6 +102,7 @@ func TestMarshalling(t *testing.T) { }, }, { + text: "rsa/nopin", k: &Key{ Version: 1, PIN: NoPIN, @@ -95,17 +111,30 @@ func TestMarshalling(t *testing.T) { Private: mustPrivate([]byte("private")), }, }, + { + text: "rsa/comment", + k: &Key{ + Version: 1, + PIN: HasPIN, + Type: tpm2.TPMAlgRSA, + Public: mustPublic([]byte("public")), + Private: mustPrivate([]byte("private")), + Comment: []byte("This is a comment"), + }, + }, } for _, c := range cases { - b := EncodeKey(c.k) - k, err := DecodeKey(b) - if err != nil { - t.Fatalf("test failed: %v", err) - } + t.Run(c.text, func(t *testing.T) { + b := EncodeKey(c.k) + k, err := DecodeKey(b) + if err != nil { + t.Fatalf("test failed: %v", err) + } - if !reflect.DeepEqual(k, c.k) { - t.Fatalf("keys are not the same") - } + if !reflect.DeepEqual(k, c.k) { + t.Fatalf("keys are not the same") + } + }) } }