Skip to content

Commit

Permalink
Switch to using data-encoding instead of base64+hex crates (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
randombit authored Oct 8, 2023
1 parent 6c41a8c commit d2814b7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ rust-version = "1.57"
[dependencies]
serde = { version = "1", features = ["derive"] }
serde_json = "1"
hex = "0.4"
base64 = "0.21"
data-encoding = "2"

num-bigint = { version = "0.4", optional = true }
16 changes: 9 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@
//! println!(
//! "Test:{} Key:{} AAD:{} PT:{} CT:{} Tag:{}",
//! test.tc_id,
//! hex::encode(test.key),
//! hex::encode(test.aad),
//! hex::encode(test.pt),
//! hex::encode(test.ct),
//! hex::encode(test.tag)
//! data_encoding::HEXLOWER.encode(&test.key),
//! data_encoding::HEXLOWER.encode(&test.aad),
//! data_encoding::HEXLOWER.encode(&test.pt),
//! data_encoding::HEXLOWER.encode(&test.ct),
//! data_encoding::HEXLOWER.encode(&test.tag)
//! );
//! }
//! }
Expand Down Expand Up @@ -91,7 +91,9 @@ impl std::error::Error for WycheproofError {}

fn vec_from_hex<'de, D: Deserializer<'de>>(deserializer: D) -> Result<Vec<u8>, D::Error> {
let s: &str = Deserialize::deserialize(deserializer)?;
hex::decode(s).map_err(D::Error::custom)
data_encoding::HEXLOWER
.decode(s.as_bytes())
.map_err(D::Error::custom)
}

fn combine_header<'de, D: Deserializer<'de>>(deserializer: D) -> Result<String, D::Error> {
Expand Down Expand Up @@ -497,7 +499,7 @@ impl ByteString {

impl fmt::Debug for ByteString {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "\"{}\"", hex::encode(&self.value))
write!(f, "\"{}\"", data_encoding::HEXLOWER.encode(&self.value))
}
}

Expand Down
5 changes: 2 additions & 3 deletions src/test_keys.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use super::*;
use base64::Engine;

fn int_from_base64<'de, D: Deserializer<'de>>(deserializer: D) -> Result<LargeInteger, D::Error> {
let s: &str = Deserialize::deserialize(deserializer)?;
let bytes = base64::engine::general_purpose::URL_SAFE_NO_PAD
.decode(s)
let bytes = data_encoding::BASE64URL_NOPAD
.decode(s.as_bytes())
.map_err(D::Error::custom)?;
Ok(LargeInteger::new(bytes))
}
Expand Down

0 comments on commit d2814b7

Please sign in to comment.