Prepare codebase for formatting

In preparation for running the formatter do minor refactorings and add a
bunch of `rustfmt::skip` directives.
This commit is contained in:
Tobin C. Harding 2022-11-03 11:09:32 +11:00
parent 7e3c8935b6
commit 41449e455d
7 changed files with 37 additions and 12 deletions

View File

@ -44,6 +44,7 @@ pub const SCHNORR_PUBLIC_KEY_SIZE: usize = 32;
pub const KEY_PAIR_SIZE: usize = 96; pub const KEY_PAIR_SIZE: usize = 96;
/// The Prime for the secp256k1 field element. /// The Prime for the secp256k1 field element.
#[rustfmt::skip]
pub const FIELD_SIZE: [u8; 32] = [ pub const FIELD_SIZE: [u8; 32] = [
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
@ -52,6 +53,7 @@ pub const FIELD_SIZE: [u8; 32] = [
]; ];
/// The order of the secp256k1 curve. /// The order of the secp256k1 curve.
#[rustfmt::skip]
pub const CURVE_ORDER: [u8; 32] = [ pub const CURVE_ORDER: [u8; 32] = [
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe,
@ -60,6 +62,7 @@ pub const CURVE_ORDER: [u8; 32] = [
]; ];
/// The X coordinate of the generator. /// The X coordinate of the generator.
#[rustfmt::skip]
pub const GENERATOR_X: [u8; 32] = [ pub const GENERATOR_X: [u8; 32] = [
0x79, 0xbe, 0x66, 0x7e, 0xf9, 0xdc, 0xbb, 0xac, 0x79, 0xbe, 0x66, 0x7e, 0xf9, 0xdc, 0xbb, 0xac,
0x55, 0xa0, 0x62, 0x95, 0xce, 0x87, 0x0b, 0x07, 0x55, 0xa0, 0x62, 0x95, 0xce, 0x87, 0x0b, 0x07,
@ -68,6 +71,7 @@ pub const GENERATOR_X: [u8; 32] = [
]; ];
/// The Y coordinate of the generator. /// The Y coordinate of the generator.
#[rustfmt::skip]
pub const GENERATOR_Y: [u8; 32] = [ pub const GENERATOR_Y: [u8; 32] = [
0x48, 0x3a, 0xda, 0x77, 0x26, 0xa3, 0xc4, 0x65, 0x48, 0x3a, 0xda, 0x77, 0x26, 0xa3, 0xc4, 0x65,
0x5d, 0xa4, 0xfb, 0xfc, 0x0e, 0x11, 0x08, 0xa8, 0x5d, 0xa4, 0xfb, 0xfc, 0x0e, 0x11, 0x08, 0xa8,

View File

@ -266,6 +266,7 @@ mod tests {
#[cfg(all(feature = "serde", any(feature = "alloc", feature = "std")))] #[cfg(all(feature = "serde", any(feature = "alloc", feature = "std")))]
fn serde() { fn serde() {
use serde_test::{Configure, Token, assert_tokens}; use serde_test::{Configure, Token, assert_tokens};
#[rustfmt::skip]
static BYTES: [u8; 32] = [ static BYTES: [u8; 32] = [
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7,

View File

@ -1,23 +1,21 @@
//! Structs and functionality related to the ECDSA signature algorithm. //! Structs and functionality related to the ECDSA signature algorithm.
use core::{fmt, str, ptr};
use crate::{Signing, Verification, Message, PublicKey, Secp256k1, SecretKey, from_hex, Error, ffi};
use crate::ffi::CPtr;
pub mod serialized_signature;
#[cfg(feature = "recovery")] #[cfg(feature = "recovery")]
mod recovery; mod recovery;
pub mod serialized_signature;
use core::{fmt, str, ptr};
#[cfg(feature = "recovery")] #[cfg(feature = "recovery")]
#[cfg_attr(docsrs, doc(cfg(feature = "recovery")))] #[cfg_attr(docsrs, doc(cfg(feature = "recovery")))]
pub use self::recovery::{RecoveryId, RecoverableSignature}; pub use self::recovery::{RecoverableSignature, RecoveryId};
pub use self::serialized_signature::SerializedSignature;
pub use serialized_signature::SerializedSignature; use crate::ffi::CPtr;
#[cfg(feature = "global-context")] #[cfg(feature = "global-context")]
use crate::SECP256K1; use crate::SECP256K1;
use crate::{
ffi, from_hex, Error, Message, PublicKey, Secp256k1, SecretKey, Signing, Verification,
};
/// An ECDSA signature /// An ECDSA signature
#[derive(Copy, Clone, PartialEq, Eq, Hash)] #[derive(Copy, Clone, PartialEq, Eq, Hash)]

View File

@ -266,6 +266,7 @@ mod tests {
#[test] #[test]
#[cfg(not(fuzzing))] // fixed sig vectors can't work with fuzz-sigs #[cfg(not(fuzzing))] // fixed sig vectors can't work with fuzz-sigs
#[cfg(all(feature="std", feature = "rand-std"))] #[cfg(all(feature="std", feature = "rand-std"))]
#[rustfmt::skip]
fn sign() { fn sign() {
let mut s = Secp256k1::new(); let mut s = Secp256k1::new();
s.randomize(&mut thread_rng()); s.randomize(&mut thread_rng());
@ -290,6 +291,7 @@ mod tests {
#[test] #[test]
#[cfg(not(fuzzing))] // fixed sig vectors can't work with fuzz-sigs #[cfg(not(fuzzing))] // fixed sig vectors can't work with fuzz-sigs
#[cfg(all(feature="std", feature = "rand-std"))] #[cfg(all(feature="std", feature = "rand-std"))]
#[rustfmt::skip]
fn sign_with_noncedata() { fn sign_with_noncedata() {
let mut s = Secp256k1::new(); let mut s = Secp256k1::new();
s.randomize(&mut thread_rng()); s.randomize(&mut thread_rng());
@ -390,6 +392,7 @@ mod tests {
#[test] #[test]
fn test_debug_output() { fn test_debug_output() {
#[rustfmt::skip]
let sig = RecoverableSignature::from_compact(&[ let sig = RecoverableSignature::from_compact(&[
0x66, 0x73, 0xff, 0xad, 0x21, 0x47, 0x74, 0x1f, 0x66, 0x73, 0xff, 0xad, 0x21, 0x47, 0x74, 0x1f,
0x04, 0x77, 0x2b, 0x6f, 0x92, 0x1f, 0x0b, 0xa6, 0x04, 0x77, 0x2b, 0x6f, 0x92, 0x1f, 0x0b, 0xa6,
@ -406,6 +409,7 @@ mod tests {
#[test] #[test]
fn test_recov_sig_serialize_compact() { fn test_recov_sig_serialize_compact() {
let recid_in = RecoveryId(1); let recid_in = RecoveryId(1);
#[rustfmt::skip]
let bytes_in = &[ let bytes_in = &[
0x66, 0x73, 0xff, 0xad, 0x21, 0x47, 0x74, 0x1f, 0x66, 0x73, 0xff, 0xad, 0x21, 0x47, 0x74, 0x1f,
0x04, 0x77, 0x2b, 0x6f, 0x92, 0x1f, 0x0b, 0xa6, 0x04, 0x77, 0x2b, 0x6f, 0x92, 0x1f, 0x0b, 0xa6,

View File

@ -713,7 +713,8 @@ impl serde::Serialize for PublicKey {
s.collect_str(self) s.collect_str(self)
} else { } else {
let mut tuple = s.serialize_tuple(constants::PUBLIC_KEY_SIZE)?; let mut tuple = s.serialize_tuple(constants::PUBLIC_KEY_SIZE)?;
for byte in self.serialize().iter() { // Serialize in compressed form. // Serialize in compressed form.
for byte in self.serialize().iter() {
tuple.serialize_element(&byte)?; tuple.serialize_element(&byte)?;
} }
tuple.end() tuple.end()
@ -1689,6 +1690,7 @@ mod test {
#[test] #[test]
#[cfg(any(feature = "alloc", feature = "std"))] #[cfg(any(feature = "alloc", feature = "std"))]
#[rustfmt::skip]
fn invalid_secret_key() { fn invalid_secret_key() {
// Zero // Zero
assert_eq!(SecretKey::from_slice(&[0; 32]), Err(InvalidSecretKey)); assert_eq!(SecretKey::from_slice(&[0; 32]), Err(InvalidSecretKey));
@ -1725,6 +1727,7 @@ mod test {
// group order, then decrement with repeated calls // group order, then decrement with repeated calls
// until it returns a valid key // until it returns a valid key
fn fill_bytes(&mut self, data: &mut [u8]) { fn fill_bytes(&mut self, data: &mut [u8]) {
#[rustfmt::skip]
let group_order: [u8; 32] = [ let group_order: [u8; 32] = [
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe,
@ -1824,6 +1827,7 @@ mod test {
#[test] #[test]
#[cfg(any(feature = "alloc", feature = "std"))] #[cfg(any(feature = "alloc", feature = "std"))]
fn test_display_output() { fn test_display_output() {
#[rustfmt::skip]
static SK_BYTES: [u8; 32] = [ static SK_BYTES: [u8; 32] = [
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
@ -2105,6 +2109,7 @@ mod test {
#[cfg(all(feature = "serde", any(feature = "alloc", feature = "std")))] #[cfg(all(feature = "serde", any(feature = "alloc", feature = "std")))]
fn test_serde() { fn test_serde() {
use serde_test::{Configure, Token, assert_tokens}; use serde_test::{Configure, Token, assert_tokens};
#[rustfmt::skip]
static SK_BYTES: [u8; 32] = [ static SK_BYTES: [u8; 32] = [
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7,
@ -2114,6 +2119,7 @@ mod test {
static SK_STR: &str = "01010101010101010001020304050607ffff0000ffff00006363636363636363"; static SK_STR: &str = "01010101010101010001020304050607ffff0000ffff00006363636363636363";
#[cfg(fuzzing)] #[cfg(fuzzing)]
#[rustfmt::skip]
static PK_BYTES: [u8; 33] = [ static PK_BYTES: [u8; 33] = [
0x02, 0x02,
0x18, 0x84, 0x57, 0x81, 0xf6, 0x31, 0xc4, 0x8f, 0x18, 0x84, 0x57, 0x81, 0xf6, 0x31, 0xc4, 0x8f,
@ -2134,6 +2140,7 @@ mod test {
#[cfg(fuzzing)] #[cfg(fuzzing)]
let pk = PublicKey::from_slice(&PK_BYTES).expect("pk"); let pk = PublicKey::from_slice(&PK_BYTES).expect("pk");
#[rustfmt::skip]
assert_tokens(&sk.compact(), &[ assert_tokens(&sk.compact(), &[
Token::Tuple{ len: 32 }, Token::Tuple{ len: 32 },
Token::U8(1), Token::U8(1), Token::U8(1), Token::U8(1), Token::U8(1), Token::U8(1), Token::U8(1), Token::U8(1), Token::U8(1), Token::U8(1), Token::U8(1), Token::U8(1), Token::U8(1), Token::U8(1), Token::U8(1), Token::U8(1),
@ -2147,6 +2154,7 @@ mod test {
assert_tokens(&sk.readable(), &[Token::Str(SK_STR)]); assert_tokens(&sk.readable(), &[Token::Str(SK_STR)]);
assert_tokens(&sk.readable(), &[Token::String(SK_STR)]); assert_tokens(&sk.readable(), &[Token::String(SK_STR)]);
#[rustfmt::skip]
assert_tokens(&pk.compact(), &[ assert_tokens(&pk.compact(), &[
Token::Tuple{ len: 33 }, Token::Tuple{ len: 33 },
Token::U8(0x02), Token::U8(0x02),
@ -2230,6 +2238,7 @@ mod test {
} }
} }
#[rustfmt::skip]
static SK_BYTES: [u8; 32] = [ static SK_BYTES: [u8; 32] = [
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7,
@ -2239,6 +2248,7 @@ mod test {
static SK_STR: &str = "01010101010101010001020304050607ffff0000ffff00006363636363636363"; static SK_STR: &str = "01010101010101010001020304050607ffff0000ffff00006363636363636363";
let sk = KeyPairWrapper(KeyPair::from_seckey_slice(&crate::SECP256K1, &SK_BYTES).unwrap()); let sk = KeyPairWrapper(KeyPair::from_seckey_slice(&crate::SECP256K1, &SK_BYTES).unwrap());
#[rustfmt::skip]
assert_tokens(&sk.compact(), &[ assert_tokens(&sk.compact(), &[
Token::Tuple{ len: 32 }, Token::Tuple{ len: 32 },
Token::U8(1), Token::U8(1), Token::U8(1), Token::U8(1), Token::U8(1), Token::U8(1), Token::U8(1), Token::U8(1), Token::U8(1), Token::U8(1), Token::U8(1), Token::U8(1), Token::U8(1), Token::U8(1), Token::U8(1), Token::U8(1),
@ -2257,6 +2267,7 @@ mod test {
fn keys() -> (SecretKey, PublicKey, KeyPair, XOnlyPublicKey) { fn keys() -> (SecretKey, PublicKey, KeyPair, XOnlyPublicKey) {
let secp = Secp256k1::new(); let secp = Secp256k1::new();
#[rustfmt::skip]
static SK_BYTES: [u8; 32] = [ static SK_BYTES: [u8; 32] = [
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
@ -2264,6 +2275,7 @@ mod test {
0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,
]; ];
#[rustfmt::skip]
static PK_BYTES: [u8; 32] = [ static PK_BYTES: [u8; 32] = [
0x18, 0x84, 0x57, 0x81, 0xf6, 0x31, 0xc4, 0x8f, 0x18, 0x84, 0x57, 0x81, 0xf6, 0x31, 0xc4, 0x8f,
0x1c, 0x97, 0x09, 0xe2, 0x30, 0x92, 0x06, 0x7d, 0x1c, 0x97, 0x09, 0xe2, 0x30, 0x92, 0x06, 0x7d,
@ -2405,6 +2417,7 @@ mod test {
fn test_serde_x_only_pubkey() { fn test_serde_x_only_pubkey() {
use serde_test::{Configure, Token, assert_tokens}; use serde_test::{Configure, Token, assert_tokens};
#[rustfmt::skip]
static SK_BYTES: [u8; 32] = [ static SK_BYTES: [u8; 32] = [
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7,
@ -2419,6 +2432,7 @@ mod test {
let kp = KeyPair::from_seckey_slice(&crate::SECP256K1, &SK_BYTES).unwrap(); let kp = KeyPair::from_seckey_slice(&crate::SECP256K1, &SK_BYTES).unwrap();
let (pk, _parity) = XOnlyPublicKey::from_keypair(&kp); let (pk, _parity) = XOnlyPublicKey::from_keypair(&kp);
#[rustfmt::skip]
assert_tokens(&pk.compact(), &[ assert_tokens(&pk.compact(), &[
Token::Tuple{ len: 32 }, Token::Tuple{ len: 32 },
Token::U8(0x18), Token::U8(0x84), Token::U8(0x57), Token::U8(0x81), Token::U8(0xf6), Token::U8(0x31), Token::U8(0xc4), Token::U8(0x8f), Token::U8(0x18), Token::U8(0x84), Token::U8(0x57), Token::U8(0x81), Token::U8(0xf6), Token::U8(0x31), Token::U8(0xc4), Token::U8(0x8f),

View File

@ -493,6 +493,7 @@ mod tests {
assert_tokens(&sig.readable(), &[Token::Str(SIG_STR)]); assert_tokens(&sig.readable(), &[Token::Str(SIG_STR)]);
assert_tokens(&sig.readable(), &[Token::String(SIG_STR)]); assert_tokens(&sig.readable(), &[Token::String(SIG_STR)]);
#[rustfmt::skip]
assert_tokens(&pk.compact(), &[ assert_tokens(&pk.compact(), &[
Token::Tuple{ len: 32 }, Token::Tuple{ len: 32 },
Token::U8(24), Token::U8(132), Token::U8(87), Token::U8(129), Token::U8(246), Token::U8(49), Token::U8(196), Token::U8(143), Token::U8(24), Token::U8(132), Token::U8(87), Token::U8(129), Token::U8(246), Token::U8(49), Token::U8(196), Token::U8(143),

View File

@ -11,6 +11,7 @@ use secp256k1::{Secp256k1, KeyPair};
// Arbitrary key data. // Arbitrary key data.
#[rustfmt::skip]
static SK_BYTES: [u8; 32] = [ static SK_BYTES: [u8; 32] = [
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x16, 0x17, 0x18, 0x19, 0x20, 0x21, 0x22, 0x23, 0x16, 0x17, 0x18, 0x19, 0x20, 0x21, 0x22, 0x23,
@ -18,6 +19,7 @@ static SK_BYTES: [u8; 32] = [
0x0f, 0x10, 0x1f, 0xa0, 0xa9, 0xaa, 0xaf, 0xff, 0x0f, 0x10, 0x1f, 0xa0, 0xa9, 0xaa, 0xaf, 0xff,
]; ];
#[rustfmt::skip]
static PK_BYTES: [u8; 33] = [ static PK_BYTES: [u8; 33] = [
0x02, 0x02,
0x18, 0x84, 0x57, 0x81, 0xf6, 0x31, 0xc4, 0x8f, 0x18, 0x84, 0x57, 0x81, 0xf6, 0x31, 0xc4, 0x8f,
@ -26,6 +28,7 @@ static PK_BYTES: [u8; 33] = [
0x4a, 0xc8, 0x87, 0xfe, 0x91, 0xdd, 0xd1, 0x66, 0x4a, 0xc8, 0x87, 0xfe, 0x91, 0xdd, 0xd1, 0x66,
]; ];
#[rustfmt::skip]
static XONLY_PK_BYTES: [u8; 32] = [ static XONLY_PK_BYTES: [u8; 32] = [
0x18, 0x84, 0x57, 0x81, 0xf6, 0x31, 0xc4, 0x8f, 0x18, 0x84, 0x57, 0x81, 0xf6, 0x31, 0xc4, 0x8f,
0x1c, 0x97, 0x09, 0xe2, 0x30, 0x92, 0x06, 0x7d, 0x1c, 0x97, 0x09, 0xe2, 0x30, 0x92, 0x06, 0x7d,