Skip to content

Commit

Permalink
fix: linter and spelling
Browse files Browse the repository at this point in the history
  • Loading branch information
bkioshn committed Jul 11, 2024
1 parent 0a45251 commit 3bb99b0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
19 changes: 11 additions & 8 deletions catalyst-gateway-crates/c509-certificate/src/c509_big_uint.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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)
}
Expand All @@ -22,7 +25,7 @@ impl Encode<()> for UnwrappedBigUint {
let significant_bytes = bytes
.iter()
.skip_while(|&&b| b == 0)
.cloned()
.copied()
.collect::<Vec<u8>>();

e.bytes(&significant_bytes)?;
Expand All @@ -34,7 +37,7 @@ impl Decode<'_, ()> for UnwrappedBigUint {
fn decode(d: &mut Decoder<'_>, _ctx: &mut ()) -> Result<Self, minicbor::decode::Error> {
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))
}
}
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand Down
5 changes: 3 additions & 2 deletions catalyst-gateway-crates/c509-certificate/src/c509_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion catalyst-gateway-crates/c509-certificate/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 3bb99b0

Please sign in to comment.