This commit is contained in:
2019-11-28 00:51:05 +08:00
parent b0ec510880
commit 730b3b7728
3 changed files with 22 additions and 4 deletions

View File

@@ -11,6 +11,7 @@ use crypto::{
};
pub const OSS_VERB_GET: &str = "GET";
pub const OSS_VERB_PUT: &str = "PUT";
// https://help.aliyun.com/document_detail/31952.html
pub struct OSSClient<'a> {
@@ -28,6 +29,10 @@ impl<'a> OSSClient<'a> {
}
}
pub fn generate_signed_put_url(&self, bucket_name: &str, key: &str, expire_in_seconds: u64) -> String {
self.generate_signed_url(OSS_VERB_PUT, bucket_name, key, expire_in_seconds, true)
}
pub fn generate_signed_get_url(&self, bucket_name: &str, key: &str, expire_in_seconds: u64) -> String {
self.generate_signed_url(OSS_VERB_GET, bucket_name, key, expire_in_seconds, true)
}
@@ -51,6 +56,7 @@ impl<'a> OSSClient<'a> {
signed_url.push_str("&Signature=");
let to_be_signed = get_to_be_signed(verb, expire_secs, bucket_name, key);
println!("{}", &to_be_signed);
let signature = to_base64(calc_hmac_sha1(self.access_key_secret.as_bytes(), to_be_signed.as_bytes()));
signed_url.push_str(&urlencoding::encode(signature.as_str()));