@@ -3,12 +3,15 @@ use hmac::digest::{Digest, KeyInit};
33use hmac:: { Hmac , Mac } ;
44use rand:: distr:: uniform:: Error ;
55use rand:: Rng ;
6+ #[ cfg( feature = "sha1" ) ]
67use sha1:: Sha1 ;
7- use sha2:: { Sha256 , Sha512 } ;
8+ use sha2:: { Sha256 , Sha384 , Sha512 } ;
89use std:: collections:: HashMap ;
910
11+ #[ cfg( feature = "sha1" ) ]
1012type HmacSha1 = Hmac < Sha1 > ;
1113type HmacSha256 = Hmac < Sha256 > ;
14+ type HmacSha384 = Hmac < Sha384 > ;
1215type HmacSha512 = Hmac < Sha512 > ;
1316pub type ParamsMapType = HashMap < String , String > ;
1417
@@ -27,8 +30,10 @@ pub fn random_int(max: u64) -> Result<u64, Error> {
2730
2831pub fn hash_function ( altcha_algorithm : & AltchaAlgorithm , data : & str ) -> String {
2932 match altcha_algorithm {
33+ #[ cfg( feature = "sha1" ) ]
3034 AltchaAlgorithm :: Sha1 => hash_str_to_hex :: < Sha1 > ( data) ,
3135 AltchaAlgorithm :: Sha256 => hash_str_to_hex :: < Sha256 > ( data) ,
36+ AltchaAlgorithm :: Sha384 => hash_str_to_hex :: < Sha384 > ( data) ,
3237 AltchaAlgorithm :: Sha512 => hash_str_to_hex :: < Sha512 > ( data) ,
3338 }
3439}
@@ -40,8 +45,10 @@ fn hash_str_to_hex<Hash: Digest>(data: &str) -> String {
4045
4146pub fn hmac_function ( altcha_algorithm : & AltchaAlgorithm , data : & str , key : & str ) -> String {
4247 match altcha_algorithm {
48+ #[ cfg( feature = "sha1" ) ]
4349 AltchaAlgorithm :: Sha1 => hmac_from_slice_to_hex_str :: < HmacSha1 > ( data, key) ,
4450 AltchaAlgorithm :: Sha256 => hmac_from_slice_to_hex_str :: < HmacSha256 > ( data, key) ,
51+ AltchaAlgorithm :: Sha384 => hmac_from_slice_to_hex_str :: < HmacSha384 > ( data, key) ,
4552 AltchaAlgorithm :: Sha512 => hmac_from_slice_to_hex_str :: < HmacSha512 > ( data, key) ,
4653 }
4754}
0 commit comments