From 9835e2ae736235810b4ea1c162ca5e65c547e770 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 18 May 2024 04:49:50 +0200 Subject: Merging upstream version 1.71.1+dfsg1. Signed-off-by: Daniel Baumann --- vendor/gix-hash/src/oid.rs | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) (limited to 'vendor/gix-hash/src/oid.rs') diff --git a/vendor/gix-hash/src/oid.rs b/vendor/gix-hash/src/oid.rs index 92ded0f87..20d4fb4b6 100644 --- a/vendor/gix-hash/src/oid.rs +++ b/vendor/gix-hash/src/oid.rs @@ -1,4 +1,4 @@ -use std::{convert::TryInto, fmt}; +use std::{convert::TryInto, fmt, hash}; use crate::{ObjectId, SIZE_OF_SHA1_DIGEST}; @@ -14,15 +14,27 @@ use crate::{ObjectId, SIZE_OF_SHA1_DIGEST}; /// hash `[`kind()`][oid::kind()]`. /// We expect to have quite a few bits available for such 'conflict resolution' as most hashes aren't longer /// than 64 bytes. -#[derive(PartialEq, Eq, Hash, Ord, PartialOrd)] +#[derive(PartialEq, Eq, Ord, PartialOrd)] #[repr(transparent)] #[allow(non_camel_case_types)] -#[cfg_attr(feature = "serde1", derive(serde::Serialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize))] pub struct oid { bytes: [u8], } -/// A utility able to format itself with the given amount of characters in hex +// False positive: +// Using an automatic implementation of `Hash` for `oid` would lead to +// it attempting to hash the length of the slice first. On 32 bit systems +// this can lead to issues with the custom `gix_hashtable` `Hasher` implementation, +// and it currently ends up being discarded there anyway. +#[allow(clippy::derived_hash_with_manual_eq)] +impl hash::Hash for oid { + fn hash(&self, state: &mut H) { + state.write(self.as_bytes()) + } +} + +/// A utility able to format itself with the given amount of characters in hex. #[derive(PartialEq, Eq, Hash, Ord, PartialOrd)] pub struct HexDisplay<'a> { inner: &'a oid, @@ -79,7 +91,7 @@ impl oid { Self::from_bytes(value) } - /// Only from code that statically assures correct sizes using array conversions + /// Only from code that statically assures correct sizes using array conversions. pub(crate) fn from_bytes(value: &[u8]) -> &Self { #[allow(unsafe_code)] unsafe { @@ -90,13 +102,13 @@ impl oid { /// Access impl oid { - /// The kind of hash used for this Digest + /// The kind of hash used for this Digest. #[inline] pub fn kind(&self) -> crate::Kind { crate::Kind::from_len_in_bytes(self.bytes.len()) } - /// The first byte of the hash, commonly used to partition a set of `Id`s + /// The first byte of the hash, commonly used to partition a set of `Id`s. #[inline] pub fn first_byte(&self) -> u8 { self.bytes[0] @@ -140,7 +152,7 @@ impl oid { num_hex_bytes } - /// Write ourselves to `out` in hexadecimal notation + /// Write ourselves to `out` in hexadecimal notation. #[inline] pub fn write_hex_to(&self, mut out: impl std::io::Write) -> std::io::Result<()> { let mut hex = crate::Kind::hex_buf(); @@ -193,9 +205,9 @@ impl PartialEq for &oid { } /// Manually created from a version that uses a slice, and we forcefully try to convert it into a borrowed array of the desired size -/// Could be improved by fitting this into serde +/// Could be improved by fitting this into serde. /// Unfortunately the serde::Deserialize derive wouldn't work for borrowed arrays. -#[cfg(feature = "serde1")] +#[cfg(feature = "serde")] impl<'de: 'a, 'a> serde::Deserialize<'de> for &'a oid { fn deserialize(deserializer: D) -> Result>::Error> where -- cgit v1.2.3