From 8634892aa6d5d59f73e50652dbe750df263853a3 Mon Sep 17 00:00:00 2001 From: Linus Nordberg Date: Fri, 25 Mar 2022 16:36:27 +0100 Subject: sign tree heads and leaves with SSHSIG --- pkg/types/encoding.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 pkg/types/encoding.go (limited to 'pkg/types/encoding.go') 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 + +} -- cgit v1.2.3