@@ -114,6 +114,9 @@ impl AlgoKind {
114114 ALGORITHM_OPTIONS_SHA256 => Sha256 ,
115115 ALGORITHM_OPTIONS_SHA384 => Sha384 ,
116116 ALGORITHM_OPTIONS_SHA512 => Sha512 ,
117+
118+ ALGORITHM_OPTIONS_SHAKE128 => Shake128 ,
119+ ALGORITHM_OPTIONS_SHAKE256 => Shake256 ,
117120 _ => return Err ( ChecksumError :: UnknownAlgorithm ( algo. as_ref ( ) . to_string ( ) ) . into ( ) ) ,
118121 } )
119122 }
@@ -247,8 +250,8 @@ pub enum SizedAlgoKind {
247250 Sha3 ( ShaLength ) ,
248251 // Note: we store Blake2b's length as BYTES.
249252 Blake2b ( Option < usize > ) ,
250- Shake128 ( usize ) ,
251- Shake256 ( usize ) ,
253+ Shake128 ( Option < usize > ) ,
254+ Shake256 ( Option < usize > ) ,
252255}
253256
254257impl SizedAlgoKind {
@@ -280,8 +283,8 @@ impl SizedAlgoKind {
280283 ( ak:: Sha1 , _) => Ok ( Self :: Sha1 ) ,
281284 ( ak:: Blake3 , _) => Ok ( Self :: Blake3 ) ,
282285
283- ( ak:: Shake128 , Some ( l ) ) => Ok ( Self :: Shake128 ( l) ) ,
284- ( ak:: Shake256 , Some ( l ) ) => Ok ( Self :: Shake256 ( l) ) ,
286+ ( ak:: Shake128 , l ) => Ok ( Self :: Shake128 ( l) ) ,
287+ ( ak:: Shake256 , l ) => Ok ( Self :: Shake256 ( l) ) ,
285288 ( ak:: Sha2 , Some ( l) ) => Ok ( Self :: Sha2 ( ShaLength :: try_from ( l) ?) ) ,
286289 ( ak:: Sha3 , Some ( l) ) => Ok ( Self :: Sha3 ( ShaLength :: try_from ( l) ?) ) ,
287290 ( algo @ ( ak:: Sha2 | ak:: Sha3 ) , None ) => {
@@ -298,7 +301,6 @@ impl SizedAlgoKind {
298301 ( ak:: Sha256 , None ) => Ok ( Self :: Sha2 ( ShaLength :: Len256 ) ) ,
299302 ( ak:: Sha384 , None ) => Ok ( Self :: Sha2 ( ShaLength :: Len384 ) ) ,
300303 ( ak:: Sha512 , None ) => Ok ( Self :: Sha2 ( ShaLength :: Len512 ) ) ,
301- ( _, None ) => Err ( ChecksumError :: LengthRequired ( kind. to_uppercase ( ) . into ( ) ) . into ( ) ) ,
302304 }
303305 }
304306
@@ -322,45 +324,49 @@ impl SizedAlgoKind {
322324 pub fn create_digest ( & self ) -> Box < dyn Digest + ' static > {
323325 use ShaLength :: * ;
324326 match self {
325- Self :: Sysv => Box :: new ( SysV :: new ( ) ) ,
326- Self :: Bsd => Box :: new ( Bsd :: new ( ) ) ,
327- Self :: Crc => Box :: new ( Crc :: new ( ) ) ,
328- Self :: Crc32b => Box :: new ( CRC32B :: new ( ) ) ,
329- Self :: Md5 => Box :: new ( Md5 :: new ( ) ) ,
330- Self :: Sm3 => Box :: new ( Sm3 :: new ( ) ) ,
331- Self :: Sha1 => Box :: new ( Sha1 :: new ( ) ) ,
332- Self :: Blake3 => Box :: new ( Blake3 :: new ( ) ) ,
333- Self :: Sha2 ( Len224 ) => Box :: new ( Sha224 :: new ( ) ) ,
334- Self :: Sha2 ( Len256 ) => Box :: new ( Sha256 :: new ( ) ) ,
335- Self :: Sha2 ( Len384 ) => Box :: new ( Sha384 :: new ( ) ) ,
336- Self :: Sha2 ( Len512 ) => Box :: new ( Sha512 :: new ( ) ) ,
337- Self :: Sha3 ( Len224 ) => Box :: new ( Sha3_224 :: new ( ) ) ,
338- Self :: Sha3 ( Len256 ) => Box :: new ( Sha3_256 :: new ( ) ) ,
339- Self :: Sha3 ( Len384 ) => Box :: new ( Sha3_384 :: new ( ) ) ,
340- Self :: Sha3 ( Len512 ) => Box :: new ( Sha3_512 :: new ( ) ) ,
341- Self :: Blake2b ( Some ( byte_len) ) => Box :: new ( Blake2b :: with_output_bytes ( * byte_len) ) ,
342- Self :: Blake2b ( None ) => Box :: new ( Blake2b :: new ( ) ) ,
343- Self :: Shake128 ( _) => Box :: new ( Shake128 :: new ( ) ) ,
344- Self :: Shake256 ( _) => Box :: new ( Shake256 :: new ( ) ) ,
327+ Self :: Sysv => Box :: new ( SysV :: default ( ) ) ,
328+ Self :: Bsd => Box :: new ( Bsd :: default ( ) ) ,
329+ Self :: Crc => Box :: new ( Crc :: default ( ) ) ,
330+ Self :: Crc32b => Box :: new ( CRC32B :: default ( ) ) ,
331+ Self :: Md5 => Box :: new ( Md5 :: default ( ) ) ,
332+ Self :: Sm3 => Box :: new ( Sm3 :: default ( ) ) ,
333+ Self :: Sha1 => Box :: new ( Sha1 :: default ( ) ) ,
334+ Self :: Blake3 => Box :: new ( Blake3 :: default ( ) ) ,
335+ Self :: Sha2 ( Len224 ) => Box :: new ( Sha224 :: default ( ) ) ,
336+ Self :: Sha2 ( Len256 ) => Box :: new ( Sha256 :: default ( ) ) ,
337+ Self :: Sha2 ( Len384 ) => Box :: new ( Sha384 :: default ( ) ) ,
338+ Self :: Sha2 ( Len512 ) => Box :: new ( Sha512 :: default ( ) ) ,
339+ Self :: Sha3 ( Len224 ) => Box :: new ( Sha3_224 :: default ( ) ) ,
340+ Self :: Sha3 ( Len256 ) => Box :: new ( Sha3_256 :: default ( ) ) ,
341+ Self :: Sha3 ( Len384 ) => Box :: new ( Sha3_384 :: default ( ) ) ,
342+ Self :: Sha3 ( Len512 ) => Box :: new ( Sha3_512 :: default ( ) ) ,
343+ Self :: Blake2b ( len_opt) => {
344+ Box :: new ( len_opt. map ( Blake2b :: with_output_bytes) . unwrap_or_default ( ) )
345+ }
346+ Self :: Shake128 ( len_opt) => {
347+ Box :: new ( len_opt. map ( Shake128 :: with_output_bits) . unwrap_or_default ( ) )
348+ }
349+ Self :: Shake256 ( len_opt) => {
350+ Box :: new ( len_opt. map ( Shake256 :: with_output_bits) . unwrap_or_default ( ) )
351+ }
345352 }
346353 }
347354
348355 pub fn bitlen ( & self ) -> usize {
349- use SizedAlgoKind :: * ;
350356 match self {
351- Sysv => 512 ,
352- Bsd => 1024 ,
353- Crc => 256 ,
354- Crc32b => 32 ,
355- Md5 => 128 ,
356- Sm3 => 512 ,
357- Sha1 => 160 ,
358- Blake3 => 256 ,
359- Sha2 ( len) => len. as_usize ( ) ,
360- Sha3 ( len) => len. as_usize ( ) ,
361- Blake2b ( len) => len. unwrap_or ( 512 ) ,
362- Shake128 ( len) => * len,
363- Shake256 ( len) => * len,
357+ Self :: Sysv => 512 ,
358+ Self :: Bsd => 1024 ,
359+ Self :: Crc => 256 ,
360+ Self :: Crc32b => 32 ,
361+ Self :: Md5 => 128 ,
362+ Self :: Sm3 => 512 ,
363+ Self :: Sha1 => 160 ,
364+ Self :: Blake3 => 256 ,
365+ Self :: Sha2 ( len) => len. as_usize ( ) ,
366+ Self :: Sha3 ( len) => len. as_usize ( ) ,
367+ Self :: Blake2b ( len) => len. unwrap_or ( Blake2b :: DEFAULT_BYTE_SIZE * 8 ) ,
368+ Self :: Shake128 ( len) => len. unwrap_or ( Shake128 :: DEFAULT_BIT_SIZE ) ,
369+ Self :: Shake256 ( len) => len. unwrap_or ( Shake256 :: DEFAULT_BIT_SIZE ) ,
364370 }
365371 }
366372 pub fn is_legacy ( & self ) -> bool {
0 commit comments