diff options
author | Martin Fischer <martin@push-f.com> | 2021-12-23 15:55:41 +0100 |
---|---|---|
committer | Martin Fischer <martin@push-f.com> | 2021-12-23 23:05:10 +0100 |
commit | 4061b03b3be49ae4fab026a92c463f837173831b (patch) | |
tree | ff061dff7f93408139f362fbac0356fb3d5d6664 | |
parent | 460150079f7bbf868c42d0c3c10119a15e9d6b84 (diff) |
upgrade hmac and sha2
-rw-r--r-- | Cargo.toml | 4 | ||||
-rw-r--r-- | src/security/signed.rs | 8 |
2 files changed, 6 insertions, 6 deletions
@@ -28,9 +28,9 @@ hyper = { version = "0.14", optional = true } serde_json = { version = "1.0", optional = true } base64 = { version = "0.13", optional = true } -hmac = { version = "0.10", optional = true } +hmac = { version = "0.12", optional = true } rand = { version = "0.8", optional = true } -sha2 = { version = "0.9", optional = true } +sha2 = { version = "0.10", optional = true } [package.metadata.docs.rs] all-features = true diff --git a/src/security/signed.rs b/src/security/signed.rs index 2954954..080bed2 100644 --- a/src/security/signed.rs +++ b/src/security/signed.rs @@ -1,4 +1,4 @@ -use hmac::{Hmac, Mac, NewMac}; +use hmac::{Hmac, Mac}; use sha2::Sha256; const SIGNED_KEY_LEN: usize = 32; @@ -42,7 +42,7 @@ impl Key { /// Signs the value providing integrity and authenticity. pub fn sign(&self, value: &str) -> String { // Compute HMAC-SHA256 of the cookie's value. - let mut mac = Hmac::<Sha256>::new_varkey(&self.0).expect("good key"); + let mut mac = Hmac::<Sha256>::new_from_slice(&self.0).expect("good key"); mac.update(value.as_bytes()); // Cookie's new value is [MAC | original-value]. @@ -63,9 +63,9 @@ impl Key { let digest = base64::decode(digest_str).map_err(|_| "bad base64 digest")?; // Perform the verification. - let mut mac = Hmac::<Sha256>::new_varkey(&self.0).expect("good key"); + let mut mac = Hmac::<Sha256>::new_from_slice(&self.0).expect("good key"); mac.update(value.as_bytes()); - mac.verify(&digest) + mac.verify_slice(&digest) .map(|_| value.to_string()) .map_err(|_| "value did not verify".to_string()) } |