@@ -249,34 +249,32 @@ impl UError for ChecksumError {
249249///
250250/// # Returns
251251///
252- /// Returns a UResult of a tuple containing the algorithm name, the hasher instance, and
253- /// the output length in bits or an Err if an unsupported output size is provided, or if
254- /// the `--bits` flag is missing.
255- pub fn create_sha3 ( bits : Option < usize > ) -> UResult < HashAlgorithm > {
252+ /// Returns a `UResult` with an `HashAlgorithm` or an `Err` if an unsupported
253+ /// output size is provided.
254+ pub fn create_sha3 ( bits : usize ) -> UResult < HashAlgorithm > {
256255 match bits {
257- Some ( 224 ) => Ok ( HashAlgorithm {
256+ 224 => Ok ( HashAlgorithm {
258257 name : "SHA3_224" ,
259258 create_fn : Box :: new ( || Box :: new ( Sha3_224 :: new ( ) ) ) ,
260259 bits : 224 ,
261260 } ) ,
262- Some ( 256 ) => Ok ( HashAlgorithm {
261+ 256 => Ok ( HashAlgorithm {
263262 name : "SHA3_256" ,
264263 create_fn : Box :: new ( || Box :: new ( Sha3_256 :: new ( ) ) ) ,
265264 bits : 256 ,
266265 } ) ,
267- Some ( 384 ) => Ok ( HashAlgorithm {
266+ 384 => Ok ( HashAlgorithm {
268267 name : "SHA3_384" ,
269268 create_fn : Box :: new ( || Box :: new ( Sha3_384 :: new ( ) ) ) ,
270269 bits : 384 ,
271270 } ) ,
272- Some ( 512 ) => Ok ( HashAlgorithm {
271+ 512 => Ok ( HashAlgorithm {
273272 name : "SHA3_512" ,
274273 create_fn : Box :: new ( || Box :: new ( Sha3_512 :: new ( ) ) ) ,
275274 bits : 512 ,
276275 } ) ,
277276
278- Some ( _) => Err ( ChecksumError :: InvalidOutputSizeForSha3 . into ( ) ) ,
279- None => Err ( ChecksumError :: BitsRequiredForSha3 . into ( ) ) ,
277+ _ => Err ( ChecksumError :: InvalidOutputSizeForSha3 . into ( ) ) ,
280278 }
281279}
282280
@@ -459,8 +457,10 @@ pub fn detect_algo(algo: &str, length: Option<usize>) -> UResult<HashAlgorithm>
459457 bits,
460458 } )
461459 }
462- //ALGORITHM_OPTIONS_SHA3 | "sha3" => (
463- _ if algo. starts_with ( "sha3" ) => create_sha3 ( length) ,
460+ _ if algo. starts_with ( "sha3" ) => {
461+ let bits = length. ok_or ( ChecksumError :: BitsRequiredForSha3 ) ?;
462+ create_sha3 ( bits)
463+ }
464464
465465 _ => Err ( ChecksumError :: UnknownAlgorithm . into ( ) ) ,
466466 }
0 commit comments