Refactor - now wireguard based. (#7)
This commit is contained in:
38
peer/multicast/packet_test.go
Normal file
38
peer/multicast/packet_test.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package multicast
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"testing"
|
||||
|
||||
"golang.org/x/crypto/nacl/sign"
|
||||
)
|
||||
|
||||
func TestPacket(t *testing.T) {
|
||||
pub, priv, err := sign.GenerateKey(rand.Reader)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
p := Packet{
|
||||
PeerIP: 10,
|
||||
WGPubKey: [32]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2},
|
||||
WGPort: 44,
|
||||
Timestamp: 12948893,
|
||||
}
|
||||
|
||||
buf := make([]byte, BufferSize)
|
||||
signed := p.Marshal(buf, priv)
|
||||
if len(signed) != SignedPacketSize {
|
||||
t.Fatalf("signed length = %d, want %d", len(signed), SignedPacketSize)
|
||||
}
|
||||
|
||||
got := Unmarshal(signed)
|
||||
if got.PeerIP != p.PeerIP || got.WGPubKey != p.WGPubKey ||
|
||||
got.WGPort != p.WGPort || got.Timestamp != p.Timestamp {
|
||||
t.Fatalf("round-trip mismatch:\n got %+v\nwant %+v", got, p)
|
||||
}
|
||||
|
||||
if !got.Verify(nil, pub) {
|
||||
t.Error("signature did not verify")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user