1
- // Copyright 2020 Contributors to the Parsec project.
1
+ // Copyright 2021 Contributors to the Parsec project.
2
2
// SPDX-License-Identifier: Apache-2.0
3
3
use super :: Provider ;
4
4
use parsec_interface:: operations:: psa_algorithm:: Hash ;
@@ -11,18 +11,21 @@ impl Provider {
11
11
op : psa_hash_compute:: Operation ,
12
12
) -> Result < psa_hash_compute:: Result > {
13
13
let mut hash = vec ! [ 0u8 ; op. alg. hash_length( ) ] ;
14
- let message = op. input . to_vec ( ) ;
15
14
match op. alg {
16
- Hash :: Sha256 => match rust_cryptoauthlib:: atcab_sha ( message, & mut hash) {
17
- rust_cryptoauthlib:: AtcaStatus :: AtcaSuccess => {
18
- Ok ( psa_hash_compute:: Result { hash : hash. into ( ) } )
15
+ Hash :: Sha256 => {
16
+ let message = op. input . to_vec ( ) ;
17
+ let err = rust_cryptoauthlib:: atcab_sha ( message, & mut hash) ;
18
+ match err {
19
+ rust_cryptoauthlib:: AtcaStatus :: AtcaSuccess => {
20
+ Ok ( psa_hash_compute:: Result { hash : hash. into ( ) } )
21
+ }
22
+ _ => {
23
+ let error = ResponseStatus :: PsaErrorGenericError ;
24
+ format_error ! ( "Hash computation failed " , err) ;
25
+ Err ( error)
26
+ }
19
27
}
20
- err => {
21
- let error = ResponseStatus :: PsaErrorGenericError ;
22
- format_error ! ( "Hash computation failed " , err) ;
23
- Err ( error)
24
- }
25
- } ,
28
+ }
26
29
_ => {
27
30
let error = ResponseStatus :: PsaErrorNotSupported ;
28
31
format_error ! ( "Unsupported hash algorithm " , error) ;
0 commit comments