|
1 | 1 | use aes::cipher::{BlockDecryptMut, BlockEncryptMut, KeyIvInit}; |
2 | | -use base64::{engine::general_purpose::STANDARD as BASE64, Engine}; |
| 2 | +use base64::{Engine, engine::general_purpose::STANDARD as BASE64}; |
3 | 3 | use rand::Rng; |
4 | 4 | use sha1::{Digest, Sha1}; |
5 | 5 |
|
@@ -38,7 +38,12 @@ fn compute_signature(token: &str, timestamp: &str, nonce: &str) -> String { |
38 | 38 | /// |
39 | 39 | /// Used to verify incoming encrypted messages and sign outgoing encrypted messages. |
40 | 40 | /// Algorithm: SHA1(sort([token, timestamp, nonce, encrypt_msg])) |
41 | | -pub fn compute_msg_signature(token: &str, timestamp: &str, nonce: &str, encrypt_msg: &str) -> String { |
| 41 | +pub fn compute_msg_signature( |
| 42 | + token: &str, |
| 43 | + timestamp: &str, |
| 44 | + nonce: &str, |
| 45 | + encrypt_msg: &str, |
| 46 | +) -> String { |
42 | 47 | let mut parts = [token, timestamp, nonce, encrypt_msg]; |
43 | 48 | parts.sort(); |
44 | 49 | let input = parts.join(""); |
@@ -307,8 +312,20 @@ mod tests { |
307 | 312 | let encrypt_msg = "encrypted_content"; |
308 | 313 |
|
309 | 314 | let sig = compute_msg_signature(token, timestamp, nonce, encrypt_msg); |
310 | | - assert!(check_msg_signature(token, &sig, timestamp, nonce, encrypt_msg)); |
311 | | - assert!(!check_msg_signature(token, "wrong", timestamp, nonce, encrypt_msg)); |
| 315 | + assert!(check_msg_signature( |
| 316 | + token, |
| 317 | + &sig, |
| 318 | + timestamp, |
| 319 | + nonce, |
| 320 | + encrypt_msg |
| 321 | + )); |
| 322 | + assert!(!check_msg_signature( |
| 323 | + token, |
| 324 | + "wrong", |
| 325 | + timestamp, |
| 326 | + nonce, |
| 327 | + encrypt_msg |
| 328 | + )); |
312 | 329 | } |
313 | 330 |
|
314 | 331 | #[test] |
|
0 commit comments