mirror of
https://github.com/lightningnetwork/lnd.git
synced 2024-11-19 09:53:54 +01:00
lnwire: add FuzzConvertFixedSignature test
Test conversion of fixed 64-byte signatures to DER-encoded signatures.
This commit is contained in:
parent
a6a7066454
commit
e198e6693f
@ -843,3 +843,39 @@ func FuzzParseRawSignature(f *testing.F) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// FuzzConvertFixedSignature tests that conversion of fixed 64-byte signatures
|
||||
// to DER-encoded signatures does not panic and that parsing and reconverting
|
||||
// the signatures does not mutate them.
|
||||
func FuzzConvertFixedSignature(f *testing.F) {
|
||||
f.Fuzz(func(t *testing.T, data []byte) {
|
||||
var sig Sig
|
||||
if len(data) > len(sig) {
|
||||
return
|
||||
}
|
||||
copy(sig[:], data)
|
||||
|
||||
derSig, err := sig.ToSignature()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
sig2, err := NewSigFromSignature(derSig)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to parse signature: %v", err)
|
||||
}
|
||||
|
||||
derSig2, err := sig2.ToSignature()
|
||||
if err != nil {
|
||||
t.Fatalf("failed to reconvert signature to DER: %v",
|
||||
err)
|
||||
}
|
||||
|
||||
derBytes := derSig.Serialize()
|
||||
derBytes2 := derSig2.Serialize()
|
||||
if !bytes.Equal(derBytes, derBytes2) {
|
||||
t.Fatalf("signature mismatch: %v != %v", derBytes,
|
||||
derBytes2)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user