aboutsummaryrefslogtreecommitdiff
path: root/types
diff options
context:
space:
mode:
authorRasmus Dahlberg <rasmus.dahlberg@kau.se>2021-02-23 12:07:34 +0100
committerRasmus Dahlberg <rasmus.dahlberg@kau.se>2021-02-23 12:07:34 +0100
commit2e8e42b09a1b2c7bd8e3557fd286a969a2fa0caf (patch)
tree0e68c5ed7181ff8e32b701dc9afe4aa2b2f265d3 /types
parent7ca509cc468e8bff5188ff06b87f758fca8ae39a (diff)
reordered functions
Diffstat (limited to 'types')
-rw-r--r--types/namespace.go26
-rw-r--r--types/namespace_test.go24
2 files changed, 25 insertions, 25 deletions
diff --git a/types/namespace.go b/types/namespace.go
index 3c6b90a..376ebcd 100644
--- a/types/namespace.go
+++ b/types/namespace.go
@@ -62,6 +62,19 @@ func (n *Namespace) Fingerprint() (*[NamespaceFingerprintSize]byte, error) {
}
}
+// Verify checks that signature is valid over message for this namespace
+func (ns *Namespace) Verify(message, signature []byte) error {
+ switch ns.Format {
+ case NamespaceFormatEd25519V1:
+ if !ed25519.Verify(ed25519.PublicKey(ns.Ed25519V1.Namespace[:]), message, signature) {
+ return fmt.Errorf("ed25519 signature verification failed")
+ }
+ default:
+ return fmt.Errorf("namespace not supported: %v", ns.Format)
+ }
+ return nil
+}
+
// NewNamespaceEd25519V1 returns an new Ed25519V1 namespace based on a
// verification key.
func NewNamespaceEd25519V1(vk []byte) (*Namespace, error) {
@@ -76,16 +89,3 @@ func NewNamespaceEd25519V1(vk []byte) (*Namespace, error) {
Ed25519V1: &ed25519v1,
}, nil
}
-
-// Verify checks that signature is valid over message for this namespace
-func (ns *Namespace) Verify(message, signature []byte) error {
- switch ns.Format {
- case NamespaceFormatEd25519V1:
- if !ed25519.Verify(ed25519.PublicKey(ns.Ed25519V1.Namespace[:]), message, signature) {
- return fmt.Errorf("ed25519 signature verification failed")
- }
- default:
- return fmt.Errorf("namespace not supported: %v", ns.Format)
- }
- return nil
-}
diff --git a/types/namespace_test.go b/types/namespace_test.go
index cd151d8..c38d295 100644
--- a/types/namespace_test.go
+++ b/types/namespace_test.go
@@ -76,6 +76,18 @@ func TestFingerprint(t *testing.T) {
}
}
+func TestVerify(t *testing.T) {
+ var tests []testCaseNamespace
+ tests = append(tests, test_cases_verify(t)...)
+ tests = append(tests, test_cases_verify_ed25519v1(t)...)
+ for _, table := range tests {
+ err := table.namespace.Verify(table.msg, table.sig)
+ 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)
+ }
+ }
+}
+
func TestNewNamespaceEd25519V1(t *testing.T) {
size := 32 // verification key size
for _, table := range []struct {
@@ -110,18 +122,6 @@ func TestNewNamespaceEd25519V1(t *testing.T) {
}
}
-func TestVerify(t *testing.T) {
- var tests []testCaseNamespace
- tests = append(tests, test_cases_verify(t)...)
- tests = append(tests, test_cases_verify_ed25519v1(t)...)
- for _, table := range tests {
- err := table.namespace.Verify(table.msg, table.sig)
- 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)
- }
- }
-}
-
// testCaseNamespace is a common test case used for Namespace.Verify() tests
type testCaseNamespace struct {
description string