From 3bb99b02e492f367d89132103b477ec516d406b1 Mon Sep 17 00:00:00 2001 From: bkioshn Date: Thu, 11 Jul 2024 18:51:28 +0700 Subject: [PATCH] fix: linter and spelling --- .../c509-certificate/src/c509_big_uint.rs | 19 +++++++++++-------- .../c509-certificate/src/c509_time.rs | 5 +++-- .../c509-certificate/src/lib.rs | 2 +- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/catalyst-gateway-crates/c509-certificate/src/c509_big_uint.rs b/catalyst-gateway-crates/c509-certificate/src/c509_big_uint.rs index 66d5f4b3e18..8448c1ab5f8 100644 --- a/catalyst-gateway-crates/c509-certificate/src/c509_big_uint.rs +++ b/catalyst-gateway-crates/c509-certificate/src/c509_big_uint.rs @@ -1,5 +1,7 @@ //! C509 Unwrapped CBOR Unsigned Bignum +// cspell: words Bignum bignum + use minicbor::{encode::Write, Decode, Decoder, Encode, Encoder}; /// A struct representing an unwrapped CBOR unsigned bignum. @@ -8,6 +10,7 @@ pub struct UnwrappedBigUint(u64); impl UnwrappedBigUint { /// Create a new instance of `UnwrappedBigUint`. + #[must_use] pub fn new(uint: u64) -> Self { Self(uint) } @@ -22,7 +25,7 @@ impl Encode<()> for UnwrappedBigUint { let significant_bytes = bytes .iter() .skip_while(|&&b| b == 0) - .cloned() + .copied() .collect::>(); e.bytes(&significant_bytes)?; @@ -34,7 +37,7 @@ impl Decode<'_, ()> for UnwrappedBigUint { fn decode(d: &mut Decoder<'_>, _ctx: &mut ()) -> Result { let bytes = d.bytes()?; // Turn bytes into u64 - let b = bytes.iter().fold(0, |acc, &b| (acc << 8) | b as u64); + let b = bytes.iter().fold(0, |acc, &b| (acc << 8) | u64::from(b)); Ok(UnwrappedBigUint::new(b)) } } @@ -50,15 +53,15 @@ mod test_big_uint { fn test_encode_decode() { let mut buffer = Vec::new(); let mut encoder = minicbor::Encoder::new(&mut buffer); - let b_uint = UnwrappedBigUint::new(128269); + let b_uint = UnwrappedBigUint::new(128_269); b_uint .encode(&mut encoder, &mut ()) .expect("Failed to encode UnwrappedBigUint"); assert_eq!(hex::encode(buffer.clone()), "4301f50d"); let mut decoder = minicbor::Decoder::new(&buffer); - let decoded_b_uint = - UnwrappedBigUint::decode(&mut decoder, &mut ()).expect("Failed to decode UnwrappedBigUint"); + let decoded_b_uint = UnwrappedBigUint::decode(&mut decoder, &mut ()) + .expect("Failed to decode UnwrappedBigUint"); assert_eq!(decoded_b_uint, b_uint); } @@ -69,15 +72,15 @@ mod test_big_uint { fn test_encode_decode_2() { let mut buffer = Vec::new(); let mut encoder = minicbor::Encoder::new(&mut buffer); - let b_uint = UnwrappedBigUint::new(9112578475118446130); + let b_uint = UnwrappedBigUint::new(9_112_578_475_118_446_130); b_uint .encode(&mut encoder, &mut ()) .expect("Failed to encode UnwrappedBigUint"); assert_eq!(hex::encode(buffer.clone()), "487e7661d7b54e4632"); let mut decoder = minicbor::Decoder::new(&buffer); - let decoded_b_uint = - UnwrappedBigUint::decode(&mut decoder, &mut ()).expect("Failed to decode UnwrappedBigUint"); + let decoded_b_uint = UnwrappedBigUint::decode(&mut decoder, &mut ()) + .expect("Failed to decode UnwrappedBigUint"); assert_eq!(decoded_b_uint, b_uint); } diff --git a/catalyst-gateway-crates/c509-certificate/src/c509_time.rs b/catalyst-gateway-crates/c509-certificate/src/c509_time.rs index 0774c3bb649..c382775b704 100644 --- a/catalyst-gateway-crates/c509-certificate/src/c509_time.rs +++ b/catalyst-gateway-crates/c509-certificate/src/c509_time.rs @@ -7,10 +7,11 @@ use minicbor::{encode::Write, Decode, Decoder, Encode, Encoder}; pub struct Time(i64); /// No expiration date in seconds since the Unix epoch. -const NO_EXP_DATE: i64 = 253402300799; +const NO_EXP_DATE: i64 = 253_402_300_799; impl Time { /// Create a new instance of `Time`. + #[must_use] pub fn new(time: i64) -> Self { Self(time) } @@ -76,7 +77,7 @@ mod test_time { fn test_encode_decode() { let mut buffer = Vec::new(); let mut encoder = minicbor::Encoder::new(&mut buffer); - let time = Time::new(1672531200); + let time = Time::new(1_672_531_200); time.encode(&mut encoder, &mut ()) .expect("Failed to encode Time"); assert_eq!(hex::encode(buffer.clone()), "1a63b0cd00"); diff --git a/catalyst-gateway-crates/c509-certificate/src/lib.rs b/catalyst-gateway-crates/c509-certificate/src/lib.rs index a7d7037e74e..2f5ab831506 100644 --- a/catalyst-gateway-crates/c509-certificate/src/lib.rs +++ b/catalyst-gateway-crates/c509-certificate/src/lib.rs @@ -6,10 +6,10 @@ //! Please refer to the [C509 Certificate](https://datatracker.ietf.org/doc/draft-ietf-cose-cbor-encoded-cert/09/) for more information. use wasm_bindgen::prelude::wasm_bindgen; +pub mod c509_big_uint; pub mod c509_extensions; pub mod c509_general_names; pub mod c509_oid; -pub mod c509_big_uint; pub mod c509_time; mod tables;