@@ -1658,17 +1658,50 @@ impl<C: Verification> Secp256k1<C> {
1658
1658
#[ cfg( feature = "arbitrary" ) ]
1659
1659
impl < ' a > Arbitrary < ' a > for PublicKey {
1660
1660
fn arbitrary ( u : & mut Unstructured < ' a > ) -> arbitrary:: Result < Self > {
1661
- let mut bytes = [ 0u8 ; 33 ] ;
1661
+ Ok ( PublicKey :: from_x_only_public_key ( u. arbitrary ( ) ?, u. arbitrary ( ) ?) )
1662
+ }
1663
+ }
1664
+
1665
+ #[ cfg( feature = "arbitrary" ) ]
1666
+ impl < ' a > Arbitrary < ' a > for Parity {
1667
+ fn arbitrary ( u : & mut Unstructured < ' a > ) -> arbitrary:: Result < Self > {
1668
+ match bool:: arbitrary ( u) ? {
1669
+ true => Ok ( Parity :: Even ) ,
1670
+ false => Ok ( Parity :: Odd )
1671
+ }
1672
+ }
1673
+ }
1674
+
1675
+ #[ cfg( feature = "arbitrary" ) ]
1676
+ impl < ' a > Arbitrary < ' a > for SecretKey {
1677
+ fn arbitrary ( u : & mut Unstructured < ' a > ) -> arbitrary:: Result < Self > {
1678
+ let mut bytes = [ 0u8 ; constants:: SECRET_KEY_SIZE ] ;
1662
1679
loop {
1663
1680
// Unstructured::fill_buffer pads the buffer with zeroes if it runs out of data
1664
- if u. len ( ) < 33 {
1681
+ if u. len ( ) < constants :: SECRET_KEY_SIZE {
1665
1682
return Err ( arbitrary:: Error :: NotEnoughData ) ;
1666
1683
}
1684
+ u. fill_buffer ( & mut bytes[ ..] ) ?;
1667
1685
1668
- bytes[ 0 ] = if u. arbitrary :: < bool > ( ) ? { 0x02 } else { 0x03 } ;
1669
- u. fill_buffer ( & mut bytes[ 1 ..] ) ?;
1686
+ if let Ok ( sk) = SecretKey :: from_byte_array ( bytes) {
1687
+ return Ok ( sk) ;
1688
+ }
1689
+ }
1690
+ }
1691
+ }
1692
+
1693
+ #[ cfg( feature = "arbitrary" ) ]
1694
+ impl < ' a > Arbitrary < ' a > for XOnlyPublicKey {
1695
+ fn arbitrary ( u : & mut Unstructured < ' a > ) -> arbitrary:: Result < Self > {
1696
+ let mut bytes = [ 0u8 ; 32 ] ;
1697
+ loop {
1698
+ // Unstructured::fill_buffer pads the buffer with zeroes if it runs out of data
1699
+ if u. len ( ) < 32 {
1700
+ return Err ( arbitrary:: Error :: NotEnoughData ) ;
1701
+ }
1670
1702
1671
- if let Ok ( pk) = PublicKey :: from_slice ( & bytes) {
1703
+ u. fill_buffer ( & mut bytes[ ..] ) ?;
1704
+ if let Ok ( pk) = XOnlyPublicKey :: from_byte_array ( bytes) {
1672
1705
return Ok ( pk) ;
1673
1706
}
1674
1707
}
0 commit comments