diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 18:31:44 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 18:31:44 +0000 |
commit | c23a457e72abe608715ac76f076f47dc42af07a5 (patch) | |
tree | 2772049aaf84b5c9d0ed12ec8d86812f7a7904b6 /vendor/gix-hash/src/object_id.rs | |
parent | Releasing progress-linux version 1.73.0+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-c23a457e72abe608715ac76f076f47dc42af07a5.tar.xz rustc-c23a457e72abe608715ac76f076f47dc42af07a5.zip |
Merging upstream version 1.74.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/gix-hash/src/object_id.rs')
-rw-r--r-- | vendor/gix-hash/src/object_id.rs | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/vendor/gix-hash/src/object_id.rs b/vendor/gix-hash/src/object_id.rs index 8bf19a744..fe1b2e9ba 100644 --- a/vendor/gix-hash/src/object_id.rs +++ b/vendor/gix-hash/src/object_id.rs @@ -40,8 +40,8 @@ pub mod decode { pub enum Error { #[error("A hash sized {0} hexadecimal characters is invalid")] InvalidHexEncodingLength(usize), - #[error("Invalid character {c} at position {index}")] - Invalid { c: char, index: usize }, + #[error("Invalid character encountered")] + Invalid, } /// Hash decoding @@ -50,16 +50,19 @@ pub mod decode { /// /// Such a buffer can be obtained using [`oid::write_hex_to(buffer)`][super::oid::write_hex_to()] pub fn from_hex(buffer: &[u8]) -> Result<ObjectId, Error> { - use hex::FromHex; match buffer.len() { - 40 => Ok(ObjectId::Sha1(<[u8; 20]>::from_hex(buffer).map_err( - |err| match err { - hex::FromHexError::InvalidHexCharacter { c, index } => Error::Invalid { c, index }, - hex::FromHexError::OddLength | hex::FromHexError::InvalidStringLength => { - unreachable!("BUG: This is already checked") - } - }, - )?)), + 40 => Ok({ + ObjectId::Sha1({ + let mut buf = [0; 20]; + faster_hex::hex_decode(buffer, &mut buf).map_err(|err| match err { + faster_hex::Error::InvalidChar => Error::Invalid, + faster_hex::Error::InvalidLength(_) => { + unreachable!("BUG: This is already checked") + } + })?; + buf + }) + }), len => Err(Error::InvalidHexEncodingLength(len)), } } |