diff --git a/crates/horizon-protocol/src/crypto.rs b/crates/horizon-protocol/src/crypto.rs index b5b6fa447..bd0244b07 100644 --- a/crates/horizon-protocol/src/crypto.rs +++ b/crates/horizon-protocol/src/crypto.rs @@ -172,7 +172,11 @@ pub fn java_hex_digest(digest: &[u8]) -> String { let hex: String = magnitude.iter().map(|b| format!("{b:02x}")).collect(); let hex = hex.trim_start_matches('0'); let hex = if hex.is_empty() { "0" } else { hex }; - if negative { format!("-{hex}") } else { hex.to_owned() } + if negative { + format!("-{hex}") + } else { + hex.to_owned() + } } /// The server id sent to the session service when joining an online-mode @@ -181,7 +185,10 @@ pub fn java_hex_digest(digest: &[u8]) -> String { pub fn server_hash(server_id: &str, secret: &[u8], public_key: &[u8]) -> String { let mut sha = Sha1::new(); // ISO-8859-1: characters above U+00FF become '?' like String.getBytes. - let latin1: Vec = server_id.chars().map(|c| u8::try_from(u32::from(c)).unwrap_or(b'?')).collect(); + let latin1: Vec = server_id + .chars() + .map(|c| u8::try_from(u32::from(c)).unwrap_or(b'?')) + .collect(); sha.update(&latin1); sha.update(secret); sha.update(public_key); diff --git a/crates/horizon-protocol/src/rsa.rs b/crates/horizon-protocol/src/rsa.rs index cbc256c06..57443e4fd 100644 --- a/crates/horizon-protocol/src/rsa.rs +++ b/crates/horizon-protocol/src/rsa.rs @@ -150,7 +150,9 @@ fn der(input: &[u8]) -> Result<(u8, &[u8], &[u8])> { if n == 0 || n > 4 || rest.len() < n { return Err(bad()); } - let len = rest[..n].iter().fold(0usize, |l, b| l << 8 | usize::from(*b)); + let len = rest[..n] + .iter() + .fold(0usize, |l, b| l << 8 | usize::from(*b)); rest = &rest[n..]; len }; @@ -219,8 +221,11 @@ impl RsaPublicKey { let limbs = self.size().div_ceil(4); let mont = Mont::new(Big::from_be_bytes(&self.modulus, limbs)); let m = Big::from_be_bytes(block, limbs); - mont.pow(&m, &Big::from_be_bytes(exponent, limbs.max(exponent.len().div_ceil(4)))) - .to_be_bytes(self.size()) + mont.pow( + &m, + &Big::from_be_bytes(exponent, limbs.max(exponent.len().div_ceil(4))), + ) + .to_be_bytes(self.size()) } /// RSAES-PKCS1-v1_5 (RFC 8017 7.2.1) with random non-zero padding. pub fn encrypt(&self, message: &[u8]) -> Result> { @@ -249,7 +254,11 @@ pub(crate) mod tests { use super::*; pub fn hex(s: &str) -> Vec { - let s = if s.len() % 2 == 1 { format!("0{s}") } else { s.to_owned() }; + let s = if s.len() % 2 == 1 { + format!("0{s}") + } else { + s.to_owned() + }; (0..s.len()) .step_by(2) .map(|i| u8::from_str_radix(&s[i..i + 2], 16).unwrap())