lnwire: add FuzzConvertFixedSignature test

Test conversion of fixed 64-byte signatures to DER-encoded signatures.
This commit is contained in:
Matt Morehouse 2023-04-28 10:20:08 -05:00
parent a6a7066454
commit e198e6693f
No known key found for this signature in database
GPG Key ID: CC8ECA224831C982

View File

@ -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)
}
})
}