feat: udpates
This commit is contained in:
@@ -94,7 +94,7 @@ pub fn add_common_headers(request: &mut Request) {
|
||||
}
|
||||
}
|
||||
|
||||
fn get_timestamp() -> (String, String) {
|
||||
pub fn get_timestamp() -> (String, String) {
|
||||
let ymd_format = "yyyyMMdd";
|
||||
let ymd_hms_format = "yyyy-MM-dd'T'HH:mm:ss'Z'";
|
||||
let now = simpledateformat::get_utc_now();
|
||||
@@ -103,14 +103,14 @@ fn get_timestamp() -> (String, String) {
|
||||
(ymd, ymd_hms)
|
||||
}
|
||||
|
||||
fn digest_request_body(sign_algorithm: &SignAlgorithm, body: &Option<Vec<u8>>) -> String {
|
||||
pub fn digest_request_body(sign_algorithm: &SignAlgorithm, body: &Option<Vec<u8>>) -> String {
|
||||
match body {
|
||||
None => sign_algorithm.digest(&vec![]),
|
||||
Some(body) => sign_algorithm.digest(body),
|
||||
}
|
||||
}
|
||||
|
||||
fn get_host(endpoint: &str) -> String {
|
||||
pub fn get_host(endpoint: &str) -> String {
|
||||
let lower_endpoint = endpoint.to_ascii_lowercase();
|
||||
let skip_chars = if lower_endpoint.starts_with("http://") {
|
||||
7
|
||||
@@ -124,7 +124,7 @@ fn get_host(endpoint: &str) -> String {
|
||||
lower_endpoint.chars().skip(skip_chars).take_while(|c| *c != '/').collect()
|
||||
}
|
||||
|
||||
fn get_nonce() -> String {
|
||||
pub fn get_nonce() -> String {
|
||||
let seq = SEQ.fetch_add(1, Ordering::Relaxed);
|
||||
let now = SystemTime::now();
|
||||
let rand_bytes: [u8; 32] = random();
|
||||
@@ -133,7 +133,7 @@ fn get_nonce() -> String {
|
||||
"nonce-".to_string() + &secs_hex + "-" + &SignAlgorithm::Sha256.digest(seed.as_bytes())[0..32]
|
||||
}
|
||||
|
||||
fn get_authorization(sign_algorithm: &SignAlgorithm,
|
||||
pub fn get_authorization(sign_algorithm: &SignAlgorithm,
|
||||
access_key: &DerivedAccessKey,
|
||||
date: &str, region: &str, product: &str,
|
||||
pathname: &str,
|
||||
@@ -162,7 +162,7 @@ fn get_authorization(sign_algorithm: &SignAlgorithm,
|
||||
authorization
|
||||
}
|
||||
|
||||
fn get_signature(sign_algorithm: &SignAlgorithm,
|
||||
pub fn get_signature(sign_algorithm: &SignAlgorithm,
|
||||
signing_key: &[u8],
|
||||
pathname: &str,
|
||||
method: &str,
|
||||
@@ -196,7 +196,7 @@ fn get_signature(sign_algorithm: &SignAlgorithm,
|
||||
hex::encode(sign_algorithm.hmac_sign(string_to_sign.as_bytes(), signing_key))
|
||||
}
|
||||
|
||||
fn get_signing_key(sign_algorithm: &SignAlgorithm, secret: &str, date: &str, region: &str, product: &str) -> Vec<u8> {
|
||||
pub fn get_signing_key(sign_algorithm: &SignAlgorithm, secret: &str, date: &str, region: &str, product: &str) -> Vec<u8> {
|
||||
let sc1 = join_slices(ALIYUN_V4.as_bytes(), secret.as_bytes());
|
||||
let sc2 = sign_algorithm.hmac_sign(date.as_bytes(), &sc1);
|
||||
let sc3 = sign_algorithm.hmac_sign(region.as_bytes(), &sc2);
|
||||
@@ -204,7 +204,7 @@ fn get_signing_key(sign_algorithm: &SignAlgorithm, secret: &str, date: &str, reg
|
||||
sign_algorithm.hmac_sign(ALIYUN_V4_REQUEST.as_bytes(), &sc4)
|
||||
}
|
||||
|
||||
fn get_region(product: &str, endpoint: &str) -> String {
|
||||
pub fn get_region(product: &str, endpoint: &str) -> String {
|
||||
if product.is_empty() || endpoint.is_empty() {
|
||||
return REGION_CENTER.into();
|
||||
}
|
||||
@@ -216,7 +216,7 @@ fn get_region(product: &str, endpoint: &str) -> String {
|
||||
if region.is_empty() { REGION_CENTER.into() } else { region }
|
||||
}
|
||||
|
||||
fn build_canonicalized_resource(query: &BTreeMap<String, String>) -> String {
|
||||
pub fn build_canonicalized_resource(query: &BTreeMap<String, String>) -> String {
|
||||
let mut canonicalized_resources = Vec::with_capacity(query.len());
|
||||
for (key, value) in query {
|
||||
let mut resource = String::with_capacity(key.len() + 1 + value.len());
|
||||
@@ -242,7 +242,7 @@ fn build_canonicalized_headers(headers: &BTreeMap<String, String>) -> String {
|
||||
canonicalized_headers
|
||||
}
|
||||
|
||||
fn get_signed_headers(headers: &BTreeMap<String, String>) -> Vec<(String, &String)> {
|
||||
pub fn get_signed_headers(headers: &BTreeMap<String, String>) -> Vec<(String, &String)> {
|
||||
let mut signed_headers = Vec::with_capacity(headers.len());
|
||||
for (key, value) in headers {
|
||||
let lower_key = key.to_lowercase();
|
||||
|
||||
Reference in New Issue
Block a user