mirror of
https://github.com/tailscale/tailscale.git
synced 2025-10-09 08:01:31 +00:00
tka: Use strict decoding settings, implement Unserialize()
Signed-off-by: Tom DNetto <tom@tailscale.com>
This commit is contained in:
@@ -7,6 +7,8 @@ package tka
|
||||
import (
|
||||
"crypto/ed25519"
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
)
|
||||
|
||||
func TestSigDirect(t *testing.T) {
|
||||
@@ -32,3 +34,24 @@ func TestSigDirect(t *testing.T) {
|
||||
t.Fatalf("verifySignature() failed: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSigSerializeUnserialize(t *testing.T) {
|
||||
nodeKeyPub := []byte{1, 2, 3, 4}
|
||||
pub, priv := testingKey25519(t, 1)
|
||||
key := Key{Kind: Key25519, Public: pub, Votes: 2}
|
||||
sig := NodeKeySignature{
|
||||
SigKind: SigDirect,
|
||||
KeyID: key.ID(),
|
||||
Pubkey: nodeKeyPub,
|
||||
}
|
||||
sigHash := sig.sigHash()
|
||||
sig.Signature = ed25519.Sign(priv, sigHash[:])
|
||||
|
||||
var decoded NodeKeySignature
|
||||
if err := decoded.Unserialize(sig.Serialize()); err != nil {
|
||||
t.Fatalf("Unserialize() failed: %v", err)
|
||||
}
|
||||
if diff := cmp.Diff(sig, decoded); diff != "" {
|
||||
t.Errorf("unmarshalled version differs (-want, +got):\n%s", diff)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user