-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
be1687f
commit 014ec42
Showing
1 changed file
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |