alibaba_cloud_sdk_rust/sdk/auth/singers/
algorithms.rs

1#![allow(unused)]
2#![allow(non_upper_case_globals)]
3#![allow(non_snake_case)]
4#![allow(non_camel_case_types)]
5use base64::{engine::general_purpose, DecodeError, Engine as _};
6use ring::hmac;
7pub fn ShaHmac1(source: &str, secret: &str) -> String {
8    let key = hmac::Key::new(hmac::HMAC_SHA1_FOR_LEGACY_USE_ONLY, secret.as_bytes());
9    let signedBytes = hmac::sign(&key, source.as_bytes());
10    base64_encode(signedBytes)
11}
12
13pub fn base64_encode<T>(input: T) -> String
14where
15    T: AsRef<[u8]>,
16{
17    general_purpose::STANDARD.encode(input)
18}
19
20pub fn base64_decode<T>(input: T) -> Result<Vec<u8>, DecodeError>
21where
22    T: AsRef<[u8]>,
23{
24    general_purpose::STANDARD.decode(input)
25}