@@ -4,7 +4,10 @@ use std::{
44 ops:: Deref ,
55} ;
66
7- use crate :: { borrowed:: oid, Kind , EMPTY_BLOB_SHA1 , EMPTY_TREE_SHA1 , SIZE_OF_SHA1_DIGEST } ;
7+ use crate :: { borrowed:: oid, Kind } ;
8+
9+ #[ cfg( feature = "sha1" ) ]
10+ use crate :: { EMPTY_BLOB_SHA1 , EMPTY_TREE_SHA1 , SIZE_OF_SHA1_DIGEST } ;
811
912#[ cfg( feature = "sha256" ) ]
1013use crate :: { EMPTY_BLOB_SHA256 , EMPTY_TREE_SHA256 , SIZE_OF_SHA256_DIGEST } ;
@@ -15,6 +18,7 @@ use crate::{EMPTY_BLOB_SHA256, EMPTY_TREE_SHA256, SIZE_OF_SHA256_DIGEST};
1518#[ non_exhaustive]
1619pub enum ObjectId {
1720 /// A SHA1 hash digest
21+ #[ cfg( feature = "sha1" ) ]
1822 Sha1 ( [ u8 ; SIZE_OF_SHA1_DIGEST ] ) ,
1923 /// A SHA256 hash digest
2024 #[ cfg( feature = "sha256" ) ]
@@ -38,7 +42,10 @@ impl Hash for ObjectId {
3842pub mod decode {
3943 use std:: str:: FromStr ;
4044
41- use crate :: { object_id:: ObjectId , SIZE_OF_SHA1_DIGEST , SIZE_OF_SHA1_HEX_DIGEST } ;
45+ use crate :: object_id:: ObjectId ;
46+
47+ #[ cfg( feature = "sha1" ) ]
48+ use crate :: { SIZE_OF_SHA1_DIGEST , SIZE_OF_SHA1_HEX_DIGEST } ;
4249
4350 #[ cfg( feature = "sha256" ) ]
4451 use crate :: { SIZE_OF_SHA256_DIGEST , SIZE_OF_SHA256_HEX_DIGEST } ;
@@ -62,6 +69,7 @@ pub mod decode {
6269 /// Such a buffer can be obtained using [`oid::write_hex_to(buffer)`][super::oid::write_hex_to()]
6370 pub fn from_hex ( buffer : & [ u8 ] ) -> Result < ObjectId , Error > {
6471 match buffer. len ( ) {
72+ #[ cfg( feature = "sha1" ) ]
6573 SIZE_OF_SHA1_HEX_DIGEST => Ok ( {
6674 ObjectId :: Sha1 ( {
6775 let mut buf = [ 0 ; SIZE_OF_SHA1_DIGEST ] ;
@@ -107,6 +115,7 @@ impl ObjectId {
107115 #[ inline]
108116 pub fn kind ( & self ) -> Kind {
109117 match self {
118+ #[ cfg( feature = "sha1" ) ]
110119 ObjectId :: Sha1 ( _) => Kind :: Sha1 ,
111120 #[ cfg( feature = "sha256" ) ]
112121 ObjectId :: Sha256 ( _) => Kind :: Sha256 ,
@@ -116,6 +125,7 @@ impl ObjectId {
116125 #[ inline]
117126 pub fn as_slice ( & self ) -> & [ u8 ] {
118127 match self {
128+ #[ cfg( feature = "sha1" ) ]
119129 Self :: Sha1 ( b) => b. as_ref ( ) ,
120130 #[ cfg( feature = "sha256" ) ]
121131 Self :: Sha256 ( b) => b. as_ref ( ) ,
@@ -125,6 +135,7 @@ impl ObjectId {
125135 #[ inline]
126136 pub fn as_mut_slice ( & mut self ) -> & mut [ u8 ] {
127137 match self {
138+ #[ cfg( feature = "sha1" ) ]
128139 Self :: Sha1 ( b) => b. as_mut ( ) ,
129140 #[ cfg( feature = "sha256" ) ]
130141 Self :: Sha256 ( b) => b. as_mut ( ) ,
@@ -135,6 +146,7 @@ impl ObjectId {
135146 #[ inline]
136147 pub const fn empty_blob ( hash : Kind ) -> ObjectId {
137148 match hash {
149+ #[ cfg( feature = "sha1" ) ]
138150 Kind :: Sha1 => ObjectId :: Sha1 ( * EMPTY_BLOB_SHA1 ) ,
139151 #[ cfg( feature = "sha256" ) ]
140152 Kind :: Sha256 => ObjectId :: Sha256 ( * EMPTY_BLOB_SHA256 ) ,
@@ -145,6 +157,7 @@ impl ObjectId {
145157 #[ inline]
146158 pub const fn empty_tree ( hash : Kind ) -> ObjectId {
147159 match hash {
160+ #[ cfg( feature = "sha1" ) ]
148161 Kind :: Sha1 => ObjectId :: Sha1 ( * EMPTY_TREE_SHA1 ) ,
149162 #[ cfg( feature = "sha256" ) ]
150163 Kind :: Sha256 => ObjectId :: Sha256 ( * EMPTY_TREE_SHA256 ) ,
@@ -156,6 +169,7 @@ impl ObjectId {
156169 #[ doc( alias = "zero" , alias = "git2" ) ]
157170 pub const fn null ( kind : Kind ) -> ObjectId {
158171 match kind {
172+ #[ cfg( feature = "sha1" ) ]
159173 Kind :: Sha1 => Self :: null_sha1 ( ) ,
160174 #[ cfg( feature = "sha256" ) ]
161175 Kind :: Sha256 => Self :: null_sha256 ( ) ,
@@ -167,6 +181,7 @@ impl ObjectId {
167181 #[ doc( alias = "is_zero" , alias = "git2" ) ]
168182 pub fn is_null ( & self ) -> bool {
169183 match self {
184+ #[ cfg( feature = "sha1" ) ]
170185 ObjectId :: Sha1 ( digest) => & digest[ ..] == oid:: null_sha1 ( ) . as_bytes ( ) ,
171186 #[ cfg( feature = "sha256" ) ]
172187 ObjectId :: Sha256 ( digest) => & digest[ ..] == oid:: null_sha256 ( ) . as_bytes ( ) ,
@@ -193,6 +208,7 @@ impl ObjectId {
193208 /// Use `Self::try_from(bytes)` for a fallible version.
194209 pub fn from_bytes_or_panic ( bytes : & [ u8 ] ) -> Self {
195210 match bytes. len ( ) {
211+ #[ cfg( feature = "sha1" ) ]
196212 SIZE_OF_SHA1_DIGEST => Self :: Sha1 ( bytes. try_into ( ) . expect ( "prior length validation" ) ) ,
197213 #[ cfg( feature = "sha256" ) ]
198214 SIZE_OF_SHA256_DIGEST => Self :: Sha256 ( bytes. try_into ( ) . expect ( "prior length validation" ) ) ,
@@ -205,6 +221,7 @@ impl ObjectId {
205221impl ObjectId {
206222 /// Instantiate an `ObjectId` from a 20 bytes SHA1 digest.
207223 #[ inline]
224+ #[ cfg( feature = "sha1" ) ]
208225 fn new_sha1 ( id : [ u8 ; SIZE_OF_SHA1_DIGEST ] ) -> Self {
209226 ObjectId :: Sha1 ( id)
210227 }
@@ -220,6 +237,7 @@ impl ObjectId {
220237 ///
221238 /// Panics if the slice doesn't have a length of 20.
222239 #[ inline]
240+ #[ cfg( feature = "sha1" ) ]
223241 pub ( crate ) fn from_20_bytes ( b : & [ u8 ] ) -> ObjectId {
224242 let mut id = [ 0 ; SIZE_OF_SHA1_DIGEST ] ;
225243 id. copy_from_slice ( b) ;
@@ -239,6 +257,7 @@ impl ObjectId {
239257
240258 /// Returns an `ObjectId` representing a SHA1 whose memory is zeroed.
241259 #[ inline]
260+ #[ cfg( feature = "sha1" ) ]
242261 pub ( crate ) const fn null_sha1 ( ) -> ObjectId {
243262 ObjectId :: Sha1 ( [ 0u8 ; SIZE_OF_SHA1_DIGEST ] )
244263 }
@@ -254,6 +273,7 @@ impl ObjectId {
254273impl std:: fmt:: Debug for ObjectId {
255274 fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
256275 match self {
276+ #[ cfg( feature = "sha1" ) ]
257277 ObjectId :: Sha1 ( _hash) => f. write_str ( "Sha1(" ) ?,
258278 #[ cfg( feature = "sha256" ) ]
259279 ObjectId :: Sha256 ( _) => f. write_str ( "Sha256(" ) ?,
@@ -265,6 +285,7 @@ impl std::fmt::Debug for ObjectId {
265285 }
266286}
267287
288+ #[ cfg( feature = "sha1" ) ]
268289impl From < [ u8 ; SIZE_OF_SHA1_DIGEST ] > for ObjectId {
269290 fn from ( v : [ u8 ; SIZE_OF_SHA1_DIGEST ] ) -> Self {
270291 Self :: new_sha1 ( v)
@@ -281,6 +302,7 @@ impl From<[u8; SIZE_OF_SHA256_DIGEST]> for ObjectId {
281302impl From < & oid > for ObjectId {
282303 fn from ( v : & oid ) -> Self {
283304 match v. kind ( ) {
305+ #[ cfg( feature = "sha1" ) ]
284306 Kind :: Sha1 => ObjectId :: from_20_bytes ( v. as_bytes ( ) ) ,
285307 #[ cfg( feature = "sha256" ) ]
286308 Kind :: Sha256 => ObjectId :: from_32_bytes ( v. as_bytes ( ) ) ,
0 commit comments