Skip to content

Commit

Permalink
Hello encode/decode. (#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelquigley committed Aug 18, 2021
1 parent be1687f commit 014ec42
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions hello.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package dilithium

import (
"github.com/openziti/dilithium/util"
"github.com/pkg/errors"
)

type hello struct {
version uint32
}

func encodeHello(hello hello, data []byte) (n uint32, err error) {
dataSize := len(data)
if dataSize < 4 {
return 0, errors.Errorf("hello too large [%d < 4]", dataSize)
}
util.WriteUint32(data, hello.version)
return 4, nil
}

func decodeHello(data []byte) (hello, uint32, error) {
dataSize := len(data)
if dataSize < 5 {
return hello{}, 0, errors.Errorf("short hello decode buffer [%d < 4]", dataSize)
}
return hello{util.ReadUint32(data)}, 4, nil
}

0 comments on commit 014ec42

Please sign in to comment.