@@ -20,9 +20,7 @@ use std::ops::Add;
20
20
use url:: form_urlencoded:: Serializer ;
21
21
use url:: percent_encoding:: utf8_percent_encode;
22
22
23
- use crypto:: hmac:: Hmac ;
24
- use crypto:: mac:: Mac ;
25
- use crypto:: sha2:: Sha256 ;
23
+ use ring:: hmac;
26
24
27
25
mod client;
28
26
pub use self :: client:: Client ;
@@ -35,7 +33,7 @@ fn send_event_prepare(
35
33
namespace : & str ,
36
34
event_hub : & str ,
37
35
policy_name : & str ,
38
- hmac : & mut Hmac < Sha256 > ,
36
+ signing_key : & hmac :: SigningKey ,
39
37
event_body : & str ,
40
38
duration : Duration ,
41
39
) -> Result < hyper:: client:: FutureResponse , AzureError > {
@@ -48,7 +46,7 @@ fn send_event_prepare(
48
46
debug ! ( "url == {:?}" , url) ;
49
47
50
48
// generate sas signature based on key name, key value, url and duration.
51
- let sas = generate_signature ( policy_name, hmac , & url. to_string ( ) , duration) ;
49
+ let sas = generate_signature ( policy_name, signing_key , & url. to_string ( ) , duration) ;
52
50
debug ! ( "sas == {}" , sas) ;
53
51
54
52
let client = hyper:: Client :: configure ( )
@@ -73,7 +71,7 @@ fn send_event(
73
71
namespace : & str ,
74
72
event_hub : & str ,
75
73
policy_name : & str ,
76
- hmac : & mut Hmac < Sha256 > ,
74
+ hmac : & hmac :: SigningKey ,
77
75
event_body : & str ,
78
76
duration : Duration ,
79
77
) -> impl Future < Item = ( ) , Error = AzureError > {
@@ -94,7 +92,7 @@ fn send_event(
94
92
95
93
fn generate_signature (
96
94
policy_name : & str ,
97
- hmac : & mut Hmac < Sha256 > ,
95
+ signing_key : & hmac :: SigningKey ,
98
96
url : & str ,
99
97
ttl : Duration ,
100
98
) -> String {
@@ -107,10 +105,9 @@ fn generate_signature(
107
105
let str_to_sign = format ! ( "{}\n {}" , url_encoded, expiry) ;
108
106
debug ! ( "str_to_sign == {:?}" , str_to_sign) ;
109
107
110
- hmac. reset ( ) ;
111
- hmac. input ( str_to_sign. as_bytes ( ) ) ;
108
+ let sig = hmac:: sign ( signing_key, str_to_sign. as_bytes ( ) ) ;
112
109
let sig = {
113
- let sig = base64:: encode ( hmac . result ( ) . code ( ) ) ;
110
+ let sig = base64:: encode ( sig . as_ref ( ) ) ;
114
111
debug ! ( "sig == {}" , sig) ;
115
112
let mut ser = Serializer :: new ( String :: new ( ) ) ;
116
113
ser. append_pair ( "sig" , & sig) ;
0 commit comments