Skip to content

Commit cdf2a63

Browse files
committed
fix!: rename hash::Sha1 to hash::Hasher and Sha1Digest to Digest.
That way, one day we can turn this type into a compatible one which produce different kinds of hashes as well.
1 parent c545d71 commit cdf2a63

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

gix-features/src/hash.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//! Otherwise, a minimal yet performant implementation is used instead for a decent trade-off between compile times and run-time performance.
66
#[cfg(all(feature = "rustsha1", not(feature = "fast-sha1")))]
77
mod _impl {
8-
use super::Sha1Digest;
8+
use super::Digest;
99

1010
/// A implementation of the Sha1 hash, which can be used once.
1111
#[derive(Default, Clone)]
@@ -17,22 +17,20 @@ mod _impl {
1717
self.0.update(bytes);
1818
}
1919
/// Finalize the hash and produce a digest.
20-
pub fn digest(self) -> Sha1Digest {
20+
pub fn digest(self) -> Digest {
2121
self.0.digest().bytes()
2222
}
2323
}
2424
}
2525

26-
/// A 20 bytes digest produced by a [`Sha1`] hash implementation.
26+
/// A hash-digest produced by a [`Hasher`] hash implementation.
2727
#[cfg(any(feature = "fast-sha1", feature = "rustsha1"))]
28-
pub type Sha1Digest = [u8; 20];
28+
pub type Digest = [u8; 20];
2929

3030
#[cfg(feature = "fast-sha1")]
3131
mod _impl {
3232
use sha1::Digest;
3333

34-
use super::Sha1Digest;
35-
3634
/// A implementation of the Sha1 hash, which can be used once.
3735
#[derive(Default, Clone)]
3836
pub struct Sha1(sha1::Sha1);
@@ -43,14 +41,14 @@ mod _impl {
4341
self.0.update(bytes);
4442
}
4543
/// Finalize the hash and produce a digest.
46-
pub fn digest(self) -> Sha1Digest {
44+
pub fn digest(self) -> super::Digest {
4745
self.0.finalize().into()
4846
}
4947
}
5048
}
5149

5250
#[cfg(any(feature = "rustsha1", feature = "fast-sha1"))]
53-
pub use _impl::Sha1;
51+
pub use _impl::Sha1 as Hasher;
5452

5553
/// Compute a CRC32 hash from the given `bytes`, returning the CRC32 hash.
5654
///
@@ -76,9 +74,9 @@ pub fn crc32(bytes: &[u8]) -> u32 {
7674

7775
/// Produce a hasher suitable for the given kind of hash.
7876
#[cfg(any(feature = "rustsha1", feature = "fast-sha1"))]
79-
pub fn hasher(kind: gix_hash::Kind) -> Sha1 {
77+
pub fn hasher(kind: gix_hash::Kind) -> Hasher {
8078
match kind {
81-
gix_hash::Kind::Sha1 => Sha1::default(),
79+
gix_hash::Kind::Sha1 => Hasher::default(),
8280
}
8381
}
8482

@@ -127,7 +125,7 @@ pub fn bytes(
127125
pub fn bytes_with_hasher(
128126
read: &mut dyn std::io::Read,
129127
num_bytes_from_start: u64,
130-
mut hasher: Sha1,
128+
mut hasher: Hasher,
131129
progress: &mut dyn crate::progress::Progress,
132130
should_interrupt: &std::sync::atomic::AtomicBool,
133131
) -> std::io::Result<gix_hash::ObjectId> {
@@ -160,12 +158,12 @@ pub fn bytes_with_hasher(
160158

161159
#[cfg(any(feature = "rustsha1", feature = "fast-sha1"))]
162160
mod write {
163-
use crate::hash::Sha1;
161+
use crate::hash::Hasher;
164162

165163
/// A utility to automatically generate a hash while writing into an inner writer.
166164
pub struct Write<T> {
167165
/// The hash implementation.
168-
pub hash: Sha1,
166+
pub hash: Hasher,
169167
/// The inner writer.
170168
pub inner: T,
171169
}
@@ -194,7 +192,7 @@ mod write {
194192
match object_hash {
195193
gix_hash::Kind::Sha1 => Write {
196194
inner,
197-
hash: Sha1::default(),
195+
hash: Hasher::default(),
198196
},
199197
}
200198
}

gix-features/tests/hash.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
use gix_features::hash::Sha1;
1+
use gix_features::hash::Hasher;
22

33
#[cfg(not(feature = "fast-sha1"))]
44
#[test]
55
fn size_of_sha1() {
6-
assert_eq!(std::mem::size_of::<Sha1>(), 96);
6+
assert_eq!(std::mem::size_of::<Hasher>(), 96);
77
}
88

99
#[cfg(feature = "fast-sha1")]
1010
#[test]
1111
fn size_of_sha1() {
1212
assert_eq!(
13-
std::mem::size_of::<Sha1>(),
13+
std::mem::size_of::<Hasher>(),
1414
if cfg!(target_arch = "x86") { 96 } else { 104 }
1515
);
1616
}

0 commit comments

Comments
 (0)