MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / TestSign

Function TestSign

crypto/asymmetric/signature_test.go:51–99  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

49}
50
51func TestSign(t *testing.T) {
52 tests := []struct {
53 name string
54 key []byte
55 }{
56 {
57 name: "Test curve",
58 key: []byte{
59 0xea, 0xf0, 0x2c, 0xa3, 0x48, 0xc5, 0x24, 0xe6,
60 0x39, 0x26, 0x55, 0xba, 0x4d, 0x29, 0x60, 0x3c,
61 0xd1, 0xa7, 0x34, 0x7d, 0x9d, 0x65, 0xcf, 0xe9,
62 0x3c, 0xe1, 0xeb, 0xff, 0xdc, 0xa2, 0x26, 0x94,
63 },
64 },
65 }
66
67 for _, test := range tests {
68 priv, pub := PrivKeyFromBytes(test.key)
69 hash := []byte("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")
70 sig, err := priv.Sign(hash)
71
72 if err != nil {
73 t.Errorf("%s could not sign: %v", test.name, err)
74 continue
75 }
76
77 if !sig.Verify(hash, pub) {
78 t.Errorf("%s could not verify: %v", test.name, err)
79 continue
80 }
81
82 serializedKey := priv.Serialize()
83 if !bytes.Equal(serializedKey, test.key) {
84 t.Errorf("%s unexpected serialized bytes - got: %x, want: %x", test.name,
85 serializedKey, test.key)
86 }
87
88 serializedSig := sig.Serialize()
89 targetSig, err := ParseDERSignature(serializedSig, btcec.S256())
90 if err != nil {
91 t.Errorf("%s could not serialized: %v", test.name, err)
92 continue
93 }
94 if !reflect.DeepEqual(sig, targetSig) {
95 t.Errorf("%s unexpected serialized bytes - got: %x, want: %x", test.name,
96 targetSig, sig)
97 }
98 }
99}
100
101func TestSignature_MarshalBinary(t *testing.T) {
102 Convey("marshal unmarshal signature", t, func() {

Callers

nothing calls this directly

Calls 6

PrivKeyFromBytesFunction · 0.85
ParseDERSignatureFunction · 0.85
ErrorfMethod · 0.80
SignMethod · 0.65
VerifyMethod · 0.65
SerializeMethod · 0.45

Tested by

no test coverage detected