Skip to content

Commit 7def954

Browse files
authored
Merge pull request #38 from nanato12/feature/update-hmac-sha256
Update hmac & sha256 crates
2 parents a12ea60 + befa50b commit 7def954

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ actix-web = { version = "3", optional = true, default-features = false }
2121
base64 = "0.21.0"
2222
bytes = "0.4"
2323
chrono = "0.4"
24-
hmac = "0.7.1"
24+
hmac = "0.12.1"
2525
reqwest = { version = "0.11.14", features = ["blocking", "json"] }
2626
rocket = { version = "0.4", optional = true }
2727
serde = { version = "1.0", features = ["derive"] }
2828
serde_derive = "1.0.156"
2929
serde_json = "1.0"
30-
sha2 = "0.8"
30+
sha2 = "0.10.6"
3131

3232
[dev-dependencies]
3333
dotenv = "0.15.0"

examples/create_signature.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ use sha2::Sha256;
1010
pub fn create_signature(channel_secret: &str, body: &str) -> String {
1111
type HmacSha256 = Hmac<Sha256>;
1212

13-
let mut mac =
14-
HmacSha256::new_varkey(channel_secret.as_bytes()).expect("HMAC can take key of any size");
15-
mac.input(body.as_bytes());
16-
return encode(&mac.result().code().to_vec());
13+
let mut mac = HmacSha256::new_from_slice(channel_secret.as_bytes())
14+
.expect("HMAC can take key of any size");
15+
mac.update(body.as_bytes());
16+
return encode(&mac.finalize().into_bytes().to_vec());
1717
}
1818

1919
fn main() {

examples/echobot_rocket.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use line::support::rocket_support::{Body, Signature};
2020
fn callback(signature: Signature, body: Body) -> Status {
2121
// Get channel secret and access token by environment variable
2222
let channel_secret: &str =
23-
&env::var("LINE_CHANNEL_RECRET").expect("Failed getting LINE_CHANNEL_RECRET");
23+
&env::var("LINE_CHANNEL_SECRET").expect("Failed getting LINE_CHANNEL_SECRET");
2424
let access_token: &str =
2525
&env::var("LINE_CHANNEL_ACCESS_TOKEN").expect("Failed getting LINE_CHANNEL_ACCESS_TOKEN");
2626

src/webhook.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ use sha2::Sha256;
1818
pub fn validate_signature(channel_secret: &str, signature: &str, body: &str) -> bool {
1919
type HmacSha256 = Hmac<Sha256>;
2020

21-
let mut mac =
22-
HmacSha256::new_varkey(channel_secret.as_bytes()).expect("HMAC can take key of any size");
23-
mac.input(body.as_bytes());
24-
encode(&mac.result().code().to_vec()) == signature
21+
let mut mac = HmacSha256::new_from_slice(channel_secret.as_bytes())
22+
.expect("HMAC can take key of any size");
23+
mac.update(body.as_bytes());
24+
encode(&mac.finalize().into_bytes().to_vec()) == signature
2525
}

0 commit comments

Comments
 (0)