package nebula import ( "encoding/json" "errors" "testing" ) func TestSigned(t *testing.T) { type msg struct { A int B string C bool } a := msg{1, "FOO", true} signedA, err := Sign(a, hostPrivCredsA.SigningPrivateKey) if err != nil { t.Fatal(err) } signedJSON, err := json.Marshal(signedA) if err != nil { t.Fatal(err) } t.Log(string(signedJSON)) var signedB Signed[msg] if err := json.Unmarshal(signedJSON, &signedB); err != nil { t.Fatal(err) } _, err = signedB.Unwrap(hostPubCredsB.SigningKey) if !errors.Is(err, ErrInvalidSignature) { t.Fatalf("expected ErrInvalidSignature but got: %v", err) } b, err := signedB.Unwrap(hostPubCredsA.SigningKey) if err != nil { t.Fatal(err) } if a != b { t.Fatalf("expected:%+v, got:%+v", a, b) } }