@@ -284,19 +284,12 @@ pub enum BBLength {
284284}
285285
286286impl BBLength {
287- pub ( crate ) fn as_bits ( self ) -> usize {
287+ pub fn as_bits ( self ) -> usize {
288288 match self {
289289 BBLength :: Byte ( n) => n * 8 ,
290290 BBLength :: Bit ( n) => n,
291291 }
292292 }
293-
294- pub ( crate ) fn as_bytes ( self ) -> usize {
295- match self {
296- BBLength :: Byte ( n) => n,
297- BBLength :: Bit ( n) => n. div_ceil ( 8 ) ,
298- }
299- }
300293}
301294
302295/// Represents an actual determined algorithm.
@@ -320,9 +313,9 @@ pub enum SizedAlgoKind {
320313}
321314
322315impl SizedAlgoKind {
323- pub fn from_unsized ( kind : AlgoKind , output_length : Option < BBLength > ) -> UResult < Self > {
316+ pub fn from_unsized ( kind : AlgoKind , output_bitlen : Option < usize > ) -> UResult < Self > {
324317 use AlgoKind as ak;
325- match ( kind, output_length ) {
318+ match ( kind, output_bitlen ) {
326319 (
327320 ak:: Sysv
328321 | ak:: Bsd
@@ -347,19 +340,15 @@ impl SizedAlgoKind {
347340 ( ak:: Sha1 , _) => Ok ( Self :: Sha1 ) ,
348341
349342 ( ak:: Blake2b , l) => Ok ( Self :: Blake2b ( XOFLength :: from_bits (
350- l. map_or ( Blake2b :: DEFAULT_BIT_SIZE , BBLength :: as_bits ) ,
343+ l. unwrap_or ( Blake2b :: DEFAULT_BIT_SIZE ) ,
351344 ) ) ) ,
352345 ( ak:: Blake3 , l) => Ok ( Self :: Blake3 ( XOFLength :: from_bits (
353- l. map_or ( Blake3 :: DEFAULT_BIT_SIZE , BBLength :: as_bits ) ,
346+ l. unwrap_or ( Blake3 :: DEFAULT_BIT_SIZE ) ,
354347 ) ) ) ,
355- ( ak:: Shake128 , l) => Ok ( Self :: Shake128 (
356- l. map ( BBLength :: as_bits) . map ( XOFLength :: from_bits) ,
357- ) ) ,
358- ( ak:: Shake256 , l) => Ok ( Self :: Shake256 (
359- l. map ( BBLength :: as_bits) . map ( XOFLength :: from_bits) ,
360- ) ) ,
361- ( ak:: Sha2 , Some ( l) ) => Ok ( Self :: Sha2 ( ShaLength :: try_from ( l. as_bits ( ) ) ?) ) ,
362- ( ak:: Sha3 , Some ( l) ) => Ok ( Self :: Sha3 ( ShaLength :: try_from ( l. as_bits ( ) ) ?) ) ,
348+ ( ak:: Shake128 , l) => Ok ( Self :: Shake128 ( l. map ( XOFLength :: from_bits) ) ) ,
349+ ( ak:: Shake256 , l) => Ok ( Self :: Shake256 ( l. map ( XOFLength :: from_bits) ) ) ,
350+ ( ak:: Sha2 , Some ( l) ) => Ok ( Self :: Sha2 ( ShaLength :: try_from ( l) ?) ) ,
351+ ( ak:: Sha3 , Some ( l) ) => Ok ( Self :: Sha3 ( ShaLength :: try_from ( l) ?) ) ,
363352 ( algo @ ( ak:: Sha2 | ak:: Sha3 ) , None ) => {
364353 Err ( ChecksumError :: LengthRequiredForSha ( algo. to_lowercase ( ) . into ( ) ) . into ( ) )
365354 }
0 commit comments