From 666e41811bdd46e24ced8ddd3448243ecb2f45c3 Mon Sep 17 00:00:00 2001 From: Rasmus Dahlberg Date: Tue, 23 Feb 2021 11:07:00 +0100 Subject: added namespace fingerprint --- types/namespace_test.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'types/namespace_test.go') diff --git a/types/namespace_test.go b/types/namespace_test.go index da18b13..e7e89ad 100644 --- a/types/namespace_test.go +++ b/types/namespace_test.go @@ -97,6 +97,44 @@ func TestNamespaceString(t *testing.T) { } } +func TestFingerprint(t *testing.T) { + for _, table := range []struct { + description string + namespace *Namespace + wantErr bool + wantFpr [NamespaceFingerprintSize]byte + }{ + { + description: "invalid: no fingerprint for type", + namespace: &Namespace{ + Format: NamespaceFormatReserved, + }, + wantErr: true, + }, + { + description: "valid: ed25519_v1", + namespace: mustInitNamespaceEd25519V1(t, 0xaf), + wantFpr: func() (ret [NamespaceFingerprintSize]byte) { + for i, _ := range ret { + ret[i] = 0xaf + } + return + }(), + }, + } { + fpr, err := table.namespace.Fingerprint() + if got, want := err != nil, table.wantErr; got != want { + t.Errorf("got error %v but wanted %v in test %q: %v", got, want, table.description, err) + } + if err != nil { + continue + } + if got, want := *fpr, table.wantFpr; !bytes.Equal(got[:], want[:]) { + t.Errorf("got fpr %v but wanted %v in test %q", got, want, table.description) + } + } +} + func TestVerify(t *testing.T) { var tests []testCaseNamespace tests = append(tests, test_cases_verify(t)...) -- cgit v1.2.3