@@ -115,6 +115,8 @@ impl AlgoKind {
115115 ALGORITHM_OPTIONS_SHA384 => Sha384 ,
116116 ALGORITHM_OPTIONS_SHA512 => Sha512 ,
117117
118+ // Extensions not in GNU as of version 9.10
119+ ALGORITHM_OPTIONS_BLAKE3 => Blake3 ,
118120 ALGORITHM_OPTIONS_SHAKE128 => Shake128 ,
119121 ALGORITHM_OPTIONS_SHAKE256 => Shake256 ,
120122 _ => return Err ( ChecksumError :: UnknownAlgorithm ( algo. as_ref ( ) . to_string ( ) ) . into ( ) ) ,
@@ -245,11 +247,12 @@ pub enum SizedAlgoKind {
245247 Md5 ,
246248 Sm3 ,
247249 Sha1 ,
248- Blake3 ,
249250 Sha2 ( ShaLength ) ,
250251 Sha3 ( ShaLength ) ,
251252 // Note: we store Blake2b's length as BYTES.
252253 Blake2b ( Option < usize > ) ,
254+ // Note: we store Blake3's length as BYTES.
255+ Blake3 ( Option < usize > ) ,
253256 Shake128 ( Option < usize > ) ,
254257 Shake256 ( Option < usize > ) ,
255258}
@@ -266,7 +269,6 @@ impl SizedAlgoKind {
266269 | ak:: Md5
267270 | ak:: Sm3
268271 | ak:: Sha1
269- | ak:: Blake3
270272 | ak:: Sha224
271273 | ak:: Sha256
272274 | ak:: Sha384
@@ -281,8 +283,8 @@ impl SizedAlgoKind {
281283 ( ak:: Md5 , _) => Ok ( Self :: Md5 ) ,
282284 ( ak:: Sm3 , _) => Ok ( Self :: Sm3 ) ,
283285 ( ak:: Sha1 , _) => Ok ( Self :: Sha1 ) ,
284- ( ak:: Blake3 , _) => Ok ( Self :: Blake3 ) ,
285286
287+ ( ak:: Blake3 , l) => Ok ( Self :: Blake3 ( l) ) ,
286288 ( ak:: Shake128 , l) => Ok ( Self :: Shake128 ( l) ) ,
287289 ( ak:: Shake256 , l) => Ok ( Self :: Shake256 ( l) ) ,
288290 ( ak:: Sha2 , Some ( l) ) => Ok ( Self :: Sha2 ( ShaLength :: try_from ( l) ?) ) ,
@@ -305,19 +307,22 @@ impl SizedAlgoKind {
305307 }
306308
307309 pub fn to_tag ( self ) -> String {
308- use SizedAlgoKind :: * ;
309310 match self {
310- Md5 => "MD5" . into ( ) ,
311- Sm3 => "SM3" . into ( ) ,
312- Sha1 => "SHA1" . into ( ) ,
313- Blake3 => "BLAKE3" . into ( ) ,
314- Sha2 ( len) => format ! ( "SHA{}" , len. as_usize( ) ) ,
315- Sha3 ( len) => format ! ( "SHA3-{}" , len. as_usize( ) ) ,
316- Blake2b ( Some ( byte_len) ) => format ! ( "BLAKE2b-{}" , byte_len * 8 ) ,
317- Blake2b ( None ) => "BLAKE2b" . into ( ) ,
318- Shake128 ( _) => "SHAKE128" . into ( ) ,
319- Shake256 ( _) => "SHAKE256" . into ( ) ,
320- Sysv | Bsd | Crc | Crc32b => panic ! ( "Should not be used for tagging" ) ,
311+ Self :: Md5 => "MD5" . into ( ) ,
312+ Self :: Sm3 => "SM3" . into ( ) ,
313+ Self :: Sha1 => "SHA1" . into ( ) ,
314+ Self :: Sha2 ( len) => format ! ( "SHA{}" , len. as_usize( ) ) ,
315+ Self :: Sha3 ( len) => format ! ( "SHA3-{}" , len. as_usize( ) ) ,
316+ Self :: Blake2b ( Some ( byte_len) ) => format ! ( "BLAKE2b-{}" , byte_len * 8 ) ,
317+ Self :: Blake2b ( None ) => "BLAKE2b" . into ( ) ,
318+ Self :: Blake3 ( byte_len) => {
319+ format ! ( "BLAKE3-{}" , byte_len. unwrap_or( Blake3 :: DEFAULT_BYTE_SIZE ) )
320+ }
321+ Self :: Shake128 ( _) => "SHAKE128" . into ( ) ,
322+ Self :: Shake256 ( _) => "SHAKE256" . into ( ) ,
323+ Self :: Sysv | Self :: Bsd | Self :: Crc | Self :: Crc32b => {
324+ panic ! ( "Should not be used for tagging" )
325+ }
321326 }
322327 }
323328
@@ -331,7 +336,6 @@ impl SizedAlgoKind {
331336 Self :: Md5 => Box :: new ( Md5 :: default ( ) ) ,
332337 Self :: Sm3 => Box :: new ( Sm3 :: default ( ) ) ,
333338 Self :: Sha1 => Box :: new ( Sha1 :: default ( ) ) ,
334- Self :: Blake3 => Box :: new ( Blake3 :: default ( ) ) ,
335339 Self :: Sha2 ( Len224 ) => Box :: new ( Sha224 :: default ( ) ) ,
336340 Self :: Sha2 ( Len256 ) => Box :: new ( Sha256 :: default ( ) ) ,
337341 Self :: Sha2 ( Len384 ) => Box :: new ( Sha384 :: default ( ) ) ,
@@ -343,6 +347,9 @@ impl SizedAlgoKind {
343347 Self :: Blake2b ( len_opt) => {
344348 Box :: new ( len_opt. map ( Blake2b :: with_output_bytes) . unwrap_or_default ( ) )
345349 }
350+ Self :: Blake3 ( len_opt) => {
351+ Box :: new ( len_opt. map ( Blake3 :: with_output_bytes) . unwrap_or_default ( ) )
352+ }
346353 Self :: Shake128 ( len_opt) => {
347354 Box :: new ( len_opt. map ( Shake128 :: with_output_bits) . unwrap_or_default ( ) )
348355 }
@@ -361,7 +368,7 @@ impl SizedAlgoKind {
361368 Self :: Md5 => 128 ,
362369 Self :: Sm3 => 512 ,
363370 Self :: Sha1 => 160 ,
364- Self :: Blake3 => 256 ,
371+ Self :: Blake3 ( len ) => len . unwrap_or ( Blake3 :: DEFAULT_BYTE_SIZE ) * 8 ,
365372 Self :: Sha2 ( len) => len. as_usize ( ) ,
366373 Self :: Sha3 ( len) => len. as_usize ( ) ,
367374 Self :: Blake2b ( len) => len. unwrap_or ( Blake2b :: DEFAULT_BYTE_SIZE * 8 ) ,
0 commit comments