5
5
//! Otherwise, a minimal yet performant implementation is used instead for a decent trade-off between compile times and run-time performance.
6
6
#[ cfg( all( feature = "rustsha1" , not( feature = "fast-sha1" ) ) ) ]
7
7
mod _impl {
8
- use super :: Sha1Digest ;
8
+ use super :: Digest ;
9
9
10
10
/// A implementation of the Sha1 hash, which can be used once.
11
11
#[ derive( Default , Clone ) ]
@@ -17,22 +17,20 @@ mod _impl {
17
17
self . 0 . update ( bytes) ;
18
18
}
19
19
/// Finalize the hash and produce a digest.
20
- pub fn digest ( self ) -> Sha1Digest {
20
+ pub fn digest ( self ) -> Digest {
21
21
self . 0 . digest ( ) . bytes ( )
22
22
}
23
23
}
24
24
}
25
25
26
- /// A 20 bytes digest produced by a [`Sha1 `] hash implementation.
26
+ /// A hash- digest produced by a [`Hasher `] hash implementation.
27
27
#[ cfg( any( feature = "fast-sha1" , feature = "rustsha1" ) ) ]
28
- pub type Sha1Digest = [ u8 ; 20 ] ;
28
+ pub type Digest = [ u8 ; 20 ] ;
29
29
30
30
#[ cfg( feature = "fast-sha1" ) ]
31
31
mod _impl {
32
32
use sha1:: Digest ;
33
33
34
- use super :: Sha1Digest ;
35
-
36
34
/// A implementation of the Sha1 hash, which can be used once.
37
35
#[ derive( Default , Clone ) ]
38
36
pub struct Sha1 ( sha1:: Sha1 ) ;
@@ -43,14 +41,14 @@ mod _impl {
43
41
self . 0 . update ( bytes) ;
44
42
}
45
43
/// Finalize the hash and produce a digest.
46
- pub fn digest ( self ) -> Sha1Digest {
44
+ pub fn digest ( self ) -> super :: Digest {
47
45
self . 0 . finalize ( ) . into ( )
48
46
}
49
47
}
50
48
}
51
49
52
50
#[ cfg( any( feature = "rustsha1" , feature = "fast-sha1" ) ) ]
53
- pub use _impl:: Sha1 ;
51
+ pub use _impl:: Sha1 as Hasher ;
54
52
55
53
/// Compute a CRC32 hash from the given `bytes`, returning the CRC32 hash.
56
54
///
@@ -76,9 +74,9 @@ pub fn crc32(bytes: &[u8]) -> u32 {
76
74
77
75
/// Produce a hasher suitable for the given kind of hash.
78
76
#[ 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 {
80
78
match kind {
81
- gix_hash:: Kind :: Sha1 => Sha1 :: default ( ) ,
79
+ gix_hash:: Kind :: Sha1 => Hasher :: default ( ) ,
82
80
}
83
81
}
84
82
@@ -127,7 +125,7 @@ pub fn bytes(
127
125
pub fn bytes_with_hasher (
128
126
read : & mut dyn std:: io:: Read ,
129
127
num_bytes_from_start : u64 ,
130
- mut hasher : Sha1 ,
128
+ mut hasher : Hasher ,
131
129
progress : & mut dyn crate :: progress:: Progress ,
132
130
should_interrupt : & std:: sync:: atomic:: AtomicBool ,
133
131
) -> std:: io:: Result < gix_hash:: ObjectId > {
@@ -160,12 +158,12 @@ pub fn bytes_with_hasher(
160
158
161
159
#[ cfg( any( feature = "rustsha1" , feature = "fast-sha1" ) ) ]
162
160
mod write {
163
- use crate :: hash:: Sha1 ;
161
+ use crate :: hash:: Hasher ;
164
162
165
163
/// A utility to automatically generate a hash while writing into an inner writer.
166
164
pub struct Write < T > {
167
165
/// The hash implementation.
168
- pub hash : Sha1 ,
166
+ pub hash : Hasher ,
169
167
/// The inner writer.
170
168
pub inner : T ,
171
169
}
@@ -194,7 +192,7 @@ mod write {
194
192
match object_hash {
195
193
gix_hash:: Kind :: Sha1 => Write {
196
194
inner,
197
- hash : Sha1 :: default ( ) ,
195
+ hash : Hasher :: default ( ) ,
198
196
} ,
199
197
}
200
198
}
0 commit comments