Skip to content

Commit f15968d

Browse files
committed
using rust crypto's to replace ring's
1 parent 7afa546 commit f15968d

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ gitlab = { repository = "https://gitlab.com/huangjj27/tls_sig_api", branch = "pr
1919

2020
[dependencies]
2121
base64 = "0.10"
22-
ring = "0.16"
22+
hmac = "0.7"
23+
sha2 = "0.8"
2324
serde_json = { version = "1.0", features = ["preserve_order"] }
2425
deflate = "0.8"
2526
chrono = "0.4"

src/lib.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use chrono::{DateTime, Duration, Utc};
22
use deflate::{deflate_bytes_zlib_conf, Compression};
33
use log::*;
4-
use ring::hmac;
4+
use sha2::Sha256;
5+
use hmac::{Hmac, Mac};
56
use serde_json::json;
67

78
pub struct TlsSigApiVer2 {
@@ -108,8 +109,10 @@ impl TlsSigApiVer2 {
108109

109110
debug!("raw_content_to_be_signed: {}", raw_content_to_be_signed);
110111

111-
let key = hmac::Key::new(hmac::HMAC_SHA256, self.secret.as_bytes());
112-
let digest = hmac::sign(&key, raw_content_to_be_signed.as_bytes());
112+
let mut mac = Hmac::<Sha256>::new_varkey(self.secret.as_bytes())
113+
.expect("HMAC can take key of any size");
114+
mac.input(raw_content_to_be_signed.as_bytes());
115+
let digest = mac.result().code();
113116

114117
base64::encode_config(digest.as_ref(), base64::STANDARD)
115118
}

0 commit comments

Comments
 (0)