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_format = "yyyyMMdd";
|
||||||
let ymd_hms_format = "yyyy-MM-dd'T'HH:mm:ss'Z'";
|
let ymd_hms_format = "yyyy-MM-dd'T'HH:mm:ss'Z'";
|
||||||
let now = simpledateformat::get_utc_now();
|
let now = simpledateformat::get_utc_now();
|
||||||
@@ -103,14 +103,14 @@ fn get_timestamp() -> (String, String) {
|
|||||||
(ymd, ymd_hms)
|
(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 {
|
match body {
|
||||||
None => sign_algorithm.digest(&vec![]),
|
None => sign_algorithm.digest(&vec![]),
|
||||||
Some(body) => sign_algorithm.digest(body),
|
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 lower_endpoint = endpoint.to_ascii_lowercase();
|
||||||
let skip_chars = if lower_endpoint.starts_with("http://") {
|
let skip_chars = if lower_endpoint.starts_with("http://") {
|
||||||
7
|
7
|
||||||
@@ -124,7 +124,7 @@ fn get_host(endpoint: &str) -> String {
|
|||||||
lower_endpoint.chars().skip(skip_chars).take_while(|c| *c != '/').collect()
|
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 seq = SEQ.fetch_add(1, Ordering::Relaxed);
|
||||||
let now = SystemTime::now();
|
let now = SystemTime::now();
|
||||||
let rand_bytes: [u8; 32] = random();
|
let rand_bytes: [u8; 32] = random();
|
||||||
@@ -133,14 +133,14 @@ fn get_nonce() -> String {
|
|||||||
"nonce-".to_string() + &secs_hex + "-" + &SignAlgorithm::Sha256.digest(seed.as_bytes())[0..32]
|
"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,
|
access_key: &DerivedAccessKey,
|
||||||
date: &str, region: &str, product: &str,
|
date: &str, region: &str, product: &str,
|
||||||
pathname: &str,
|
pathname: &str,
|
||||||
method: &str,
|
method: &str,
|
||||||
query: &BTreeMap<String, String>,
|
query: &BTreeMap<String, String>,
|
||||||
headers: &BTreeMap<String, String>,
|
headers: &BTreeMap<String, String>,
|
||||||
payload: &str) -> String {
|
payload: &str) -> String {
|
||||||
let signature = get_signature(sign_algorithm, &access_key.derived_access_key_secret,
|
let signature = get_signature(sign_algorithm, &access_key.derived_access_key_secret,
|
||||||
pathname, method, query, headers, payload);
|
pathname, method, query, headers, payload);
|
||||||
let signed_headers_str = get_signed_headers(headers).iter().map(|(k, _)| k.as_str()).collect::<Vec<_>>().join(";");
|
let signed_headers_str = get_signed_headers(headers).iter().map(|(k, _)| k.as_str()).collect::<Vec<_>>().join(";");
|
||||||
@@ -162,13 +162,13 @@ fn get_authorization(sign_algorithm: &SignAlgorithm,
|
|||||||
authorization
|
authorization
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_signature(sign_algorithm: &SignAlgorithm,
|
pub fn get_signature(sign_algorithm: &SignAlgorithm,
|
||||||
signing_key: &[u8],
|
signing_key: &[u8],
|
||||||
pathname: &str,
|
pathname: &str,
|
||||||
method: &str,
|
method: &str,
|
||||||
query: &BTreeMap<String, String>,
|
query: &BTreeMap<String, String>,
|
||||||
headers: &BTreeMap<String, String>,
|
headers: &BTreeMap<String, String>,
|
||||||
payload: &str) -> String {
|
payload: &str) -> String {
|
||||||
let canonical_uri = if pathname.is_empty() { "/" } else { pathname };
|
let canonical_uri = if pathname.is_empty() { "/" } else { pathname };
|
||||||
let canonicalized_resource = build_canonicalized_resource(query);
|
let canonicalized_resource = build_canonicalized_resource(query);
|
||||||
let canonicalized_headers = build_canonicalized_headers(headers);
|
let canonicalized_headers = build_canonicalized_headers(headers);
|
||||||
@@ -196,7 +196,7 @@ fn get_signature(sign_algorithm: &SignAlgorithm,
|
|||||||
hex::encode(sign_algorithm.hmac_sign(string_to_sign.as_bytes(), signing_key))
|
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 sc1 = join_slices(ALIYUN_V4.as_bytes(), secret.as_bytes());
|
||||||
let sc2 = sign_algorithm.hmac_sign(date.as_bytes(), &sc1);
|
let sc2 = sign_algorithm.hmac_sign(date.as_bytes(), &sc1);
|
||||||
let sc3 = sign_algorithm.hmac_sign(region.as_bytes(), &sc2);
|
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)
|
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() {
|
if product.is_empty() || endpoint.is_empty() {
|
||||||
return REGION_CENTER.into();
|
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 }
|
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());
|
let mut canonicalized_resources = Vec::with_capacity(query.len());
|
||||||
for (key, value) in query {
|
for (key, value) in query {
|
||||||
let mut resource = String::with_capacity(key.len() + 1 + value.len());
|
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
|
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());
|
let mut signed_headers = Vec::with_capacity(headers.len());
|
||||||
for (key, value) in headers {
|
for (key, value) in headers {
|
||||||
let lower_key = key.to_lowercase();
|
let lower_key = key.to_lowercase();
|
||||||
|
|||||||
Reference in New Issue
Block a user