Loading crates/tor-dirmgr/src/authority.rs +2 −3 Original line number Diff line number Diff line Loading @@ -59,9 +59,8 @@ impl Authority { pub(crate) fn default_authorities() -> Vec<Authority> { /// Build an authority; panic if input is bad. fn auth(name: &str, key: &str) -> Authority { let v3ident = hex::decode(key).expect("Built-in authority identity had bad hex!?"); let v3ident = RsaIdentity::from_bytes(&v3ident) .expect("Built-in authority identity had wrong length!?"); let v3ident = RsaIdentity::from_hex(key).expect("Built-in authority identity had bad hex!?"); AuthorityBuilder::new() .name(name) .v3ident(v3ident) Loading crates/tor-dirmgr/src/config.rs +1 −3 Original line number Diff line number Diff line Loading @@ -331,9 +331,7 @@ mod fallbacks { pub(crate) fn default_fallbacks() -> Vec<super::FallbackDir> { /// Build a fallback directory; panic if input is bad. fn fallback(rsa: &str, ed: &str, ports: &[&str]) -> FallbackDir { let rsa = hex::decode(rsa).expect("Bad hex in built-in fallback list"); let rsa = RsaIdentity::from_bytes(&rsa).expect("Wrong length in built-in fallback list"); let rsa = RsaIdentity::from_hex(rsa).expect("Bad hex in built-in fallback list"); let ed = base64::decode_config(ed, base64::STANDARD_NO_PAD) .expect("Bad hex in built-in fallback list"); let ed = Loading crates/tor-dirmgr/src/state.rs +1 −2 Original line number Diff line number Diff line Loading @@ -1005,8 +1005,7 @@ mod test { datetime!(2020-08-07 12:42:45 UTC).into() } fn rsa(s: &str) -> RsaIdentity { let k = hex::decode(s).unwrap(); RsaIdentity::from_bytes(&k[..]).unwrap() RsaIdentity::from_hex(s).unwrap() } fn test_authorities() -> Vec<Authority> { fn a(s: &str) -> Authority { Loading crates/tor-dirmgr/src/storage/sqlite.rs +4 −8 Original line number Diff line number Diff line Loading @@ -608,20 +608,16 @@ impl Drop for Unlinker { /// Convert a hexadecimal sha3-256 digest from the database into an array. fn digest_from_hex(s: &str) -> Result<[u8; 32]> { hex::decode(s) .map_err(Error::BadHexInCache)? .try_into() .map_err(|_| Error::CacheCorruption("Invalid digest in database")) let mut bytes = [0_u8; 32]; hex::decode_to_slice(s, &mut bytes[..]).map_err(Error::BadHexInCache)?; Ok(bytes) } /// Convert a hexadecimal sha3-256 "digest string" as used in the /// digest column from the database into an array. fn digest_from_dstr(s: &str) -> Result<[u8; 32]> { if let Some(stripped) = s.strip_prefix("sha3-256-") { hex::decode(stripped) .map_err(Error::BadHexInCache)? .try_into() .map_err(|_| Error::CacheCorruption("Invalid digest in database")) digest_from_hex(stripped) } else { Err(Error::CacheCorruption("Invalid digest in database")) } Loading Loading
crates/tor-dirmgr/src/authority.rs +2 −3 Original line number Diff line number Diff line Loading @@ -59,9 +59,8 @@ impl Authority { pub(crate) fn default_authorities() -> Vec<Authority> { /// Build an authority; panic if input is bad. fn auth(name: &str, key: &str) -> Authority { let v3ident = hex::decode(key).expect("Built-in authority identity had bad hex!?"); let v3ident = RsaIdentity::from_bytes(&v3ident) .expect("Built-in authority identity had wrong length!?"); let v3ident = RsaIdentity::from_hex(key).expect("Built-in authority identity had bad hex!?"); AuthorityBuilder::new() .name(name) .v3ident(v3ident) Loading
crates/tor-dirmgr/src/config.rs +1 −3 Original line number Diff line number Diff line Loading @@ -331,9 +331,7 @@ mod fallbacks { pub(crate) fn default_fallbacks() -> Vec<super::FallbackDir> { /// Build a fallback directory; panic if input is bad. fn fallback(rsa: &str, ed: &str, ports: &[&str]) -> FallbackDir { let rsa = hex::decode(rsa).expect("Bad hex in built-in fallback list"); let rsa = RsaIdentity::from_bytes(&rsa).expect("Wrong length in built-in fallback list"); let rsa = RsaIdentity::from_hex(rsa).expect("Bad hex in built-in fallback list"); let ed = base64::decode_config(ed, base64::STANDARD_NO_PAD) .expect("Bad hex in built-in fallback list"); let ed = Loading
crates/tor-dirmgr/src/state.rs +1 −2 Original line number Diff line number Diff line Loading @@ -1005,8 +1005,7 @@ mod test { datetime!(2020-08-07 12:42:45 UTC).into() } fn rsa(s: &str) -> RsaIdentity { let k = hex::decode(s).unwrap(); RsaIdentity::from_bytes(&k[..]).unwrap() RsaIdentity::from_hex(s).unwrap() } fn test_authorities() -> Vec<Authority> { fn a(s: &str) -> Authority { Loading
crates/tor-dirmgr/src/storage/sqlite.rs +4 −8 Original line number Diff line number Diff line Loading @@ -608,20 +608,16 @@ impl Drop for Unlinker { /// Convert a hexadecimal sha3-256 digest from the database into an array. fn digest_from_hex(s: &str) -> Result<[u8; 32]> { hex::decode(s) .map_err(Error::BadHexInCache)? .try_into() .map_err(|_| Error::CacheCorruption("Invalid digest in database")) let mut bytes = [0_u8; 32]; hex::decode_to_slice(s, &mut bytes[..]).map_err(Error::BadHexInCache)?; Ok(bytes) } /// Convert a hexadecimal sha3-256 "digest string" as used in the /// digest column from the database into an array. fn digest_from_dstr(s: &str) -> Result<[u8; 32]> { if let Some(stripped) = s.strip_prefix("sha3-256-") { hex::decode(stripped) .map_err(Error::BadHexInCache)? .try_into() .map_err(|_| Error::CacheCorruption("Invalid digest in database")) digest_from_hex(stripped) } else { Err(Error::CacheCorruption("Invalid digest in database")) } Loading