aboutsummaryrefslogtreecommitdiff
path: root/pkg/types/encoding.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.go
parentace5e7c406dee2ca533d41f5271de0be7403a139 (diff)
sign tree heads and leaves with SSHSIG
Diffstat (limited to 'pkg/types/encoding.go')
-rw-r--r--pkg/types/encoding.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/pkg/types/encoding.go b/pkg/types/encoding.go
new file mode 100644
index 0000000..54a1ac6
--- /dev/null
+++ b/pkg/types/encoding.go
@@ -0,0 +1,31 @@
+package types
+
+import (
+ "encoding/binary"
+ "fmt"
+)
+
+// RFC4251, section 5
+
+func putSSHString(b []byte, str string) int {
+ l := len(str)
+
+ i := 0
+ binary.BigEndian.PutUint32(b[i:i+4], uint32(l))
+ i += 4
+ copy(b[i:i+l], str)
+ i += l
+
+ return i
+}
+
+func getSSHString(b []byte) (*string, error) {
+ if len(b) < 4 {
+ return nil, fmt.Errorf("types: invalid SSH string")
+ }
+
+ l := binary.BigEndian.Uint32(b[:4])
+ str := string(b[4 : 4+l])
+ return &str, nil
+
+}