aboutsummaryrefslogtreecommitdiff
path: root/pkg/types/encoding_test.go
diff options
context:
space:
mode:
authorLinus Nordberg <linus@nordberg.se>2022-03-25 16:36:27 +0100
committerRasmus Dahlberg <rasmus@mullvad.net>2022-03-28 19:10:49 +0200
commit8634892aa6d5d59f73e50652dbe750df263853a3 (patch)
treeb979039d1c63107969f21ef5ce20dc9e827f2ab4 /pkg/types/encoding_test.go
parentace5e7c406dee2ca533d41f5271de0be7403a139 (diff)
sign tree heads and leaves with SSHSIG
Diffstat (limited to 'pkg/types/encoding_test.go')
-rw-r--r--pkg/types/encoding_test.go63
1 files changed, 63 insertions, 0 deletions
diff --git a/pkg/types/encoding_test.go b/pkg/types/encoding_test.go
new file mode 100644
index 0000000..e079a8c
--- /dev/null
+++ b/pkg/types/encoding_test.go
@@ -0,0 +1,63 @@
+package types
+
+import (
+ "bytes"
+ "testing"
+)
+
+func TestPutSSHString(t *testing.T) {
+ for _, tbl := range []struct {
+ desc string
+ in string
+ }{
+ {
+ desc: "valid",
+ in: "รถ foo is a bar",
+ },
+ } {
+ var b [128]byte
+ i := putSSHString(b[:], tbl.in)
+
+ if got, want := i, len(tbl.in)+4; got != want {
+ t.Errorf("%q: len: got %d but wanted %d in test", tbl.desc, got, want)
+ }
+
+ if got, want := b[4:4+len(tbl.in)], []byte(tbl.in); !bytes.Equal(got, want) {
+ t.Errorf("%q: got %x but wanted %x", tbl.desc, got, want)
+ }
+ }
+}
+
+func TestGetSSHString(t *testing.T) {
+ for _, tbl := range []struct {
+ desc string
+ in []byte
+ want string
+ wantErr bool
+ }{
+ {
+ desc: "valid",
+ in: []byte{0, 0, 0, 5, 65, 108, 108, 97, 110},
+ want: "Allan",
+ },
+ {
+ desc: "invalid: short",
+ in: []byte{0, 0, 0},
+ wantErr: true,
+ },
+ } {
+ str, err := getSSHString(tbl.in)
+
+ if got, want := err != nil, tbl.wantErr; got != want {
+ t.Errorf("%q: error: got %v but wanted %v: %v", tbl.desc, got, want, err)
+ }
+
+ if err != nil {
+ continue
+ }
+
+ if got, want := str, tbl.want; *got != want {
+ t.Errorf(`%q: got "%v" but wanted "%v"`, tbl.desc, *got, want)
+ }
+ }
+}