Struct qiniu_credential::GotCredential
source · [−]pub struct GotCredential(_);
Expand description
获取的认证信息
该数据结构目前和认证信息相同,可以和认证信息相互转换,但之后可能会添加更多字段
Implementations
sourceimpl GotCredential
impl GotCredential
sourcepub fn credential(&self) -> &Credential
pub fn credential(&self) -> &Credential
获取认证信息
sourcepub fn credential_mut(&mut self) -> &mut Credential
pub fn credential_mut(&mut self) -> &mut Credential
获取认证信息的可变引用
sourcepub fn into_credential(self) -> Credential
pub fn into_credential(self) -> Credential
转换为认证信息
Methods from Deref<Target = Credential>
sourcepub fn access_key(&self) -> &AccessKey
pub fn access_key(&self) -> &AccessKey
获取认证信息的 AccessKey
sourcepub fn secret_key(&self) -> &SecretKey
pub fn secret_key(&self) -> &SecretKey
获取认证信息的 SecretKey
sourcepub fn sign(&self, data: &[u8]) -> String
pub fn sign(&self, data: &[u8]) -> String
使用七牛签名算法对数据进行签名
use qiniu_credential::{Credential, prelude::*};
let credential = Credential::new("abcdefghklmnopq", "1234567890");
assert_eq!(
credential.get(Default::default())?.sign(b"hello"),
"abcdefghklmnopq:b84KVc-LroDiz0ebUANfdzSRxa0="
);
sourcepub fn sign_reader(&self, reader: &mut dyn Read) -> IoResult<String>
pub fn sign_reader(&self, reader: &mut dyn Read) -> IoResult<String>
使用七牛签名算法对输入流数据进行签名
use qiniu_credential::{Credential, prelude::*};
use std::io::Cursor;
let credential = Credential::new("abcdefghklmnopq", "1234567890");
assert_eq!(
credential
.get(Default::default())?
.sign_reader(&mut Cursor::new(b"world"))?,
"abcdefghklmnopq:VjgXt0P_nCxHuaTfiFz-UjDJ1AQ="
);
sourcepub fn sign_with_data(&self, data: &[u8]) -> String
pub fn sign_with_data(&self, data: &[u8]) -> String
使用七牛签名算法对数据进行签名,并同时给出签名和原数据
use qiniu_credential::{Credential, prelude::*};
use std::io::Cursor;
let credential = Credential::new("abcdefghklmnopq", "1234567890");
assert_eq!(
credential.get(Default::default())?.sign_with_data(b"hello"),
"abcdefghklmnopq:BZYt5uVRy1RVt5ZTXbaIt2ROVMA=:aGVsbG8="
);
使用七牛签名算法 V1 对 HTTP 请求(请求体为内存数据)进行签名,返回 Authorization 的值
use qiniu_credential::{Credential, HeaderValue, prelude::*};
use mime::APPLICATION_WWW_FORM_URLENCODED;
use std::io::Cursor;
let credential = Credential::new("abcdefghklmnopq", "1234567890");
let authorization = credential
.get(Default::default())?
.authorization_v1_for_request(
&"http://upload.qiniup.com/".parse()?,
Some(&HeaderValue::from_str(APPLICATION_WWW_FORM_URLENCODED.as_ref())?),
b"name=test&language=go"
);
使用七牛签名算法 V1 对 HTTP 请求(请求体为输入流)进行签名,返回 Authorization 的值
use qiniu_credential::{Credential, HeaderValue, prelude::*};
use std::io::Cursor;
use mime::APPLICATION_WWW_FORM_URLENCODED;
let credential = Credential::new("abcdefghklmnopq", "1234567890");
let authorization = credential
.get(Default::default())?
.authorization_v1_for_request_with_body_reader(
&"http://upload.qiniup.com/".parse()?,
Some(&HeaderValue::from_str(APPLICATION_WWW_FORM_URLENCODED.as_ref())?),
&mut Cursor::new(b"name=test&language=go")
)?;
使用七牛签名算法 V2 对 HTTP 请求(请求体为内存数据)进行签名,返回 Authorization 的值
use qiniu_credential::{Credential, Method, HeaderMap, HeaderValue, prelude::*};
use http::header::CONTENT_TYPE;
use mime::APPLICATION_JSON;
let credential = Credential::new("abcdefghklmnopq", "1234567890");
let mut headers = HeaderMap::new();
headers.insert(CONTENT_TYPE, HeaderValue::from_str(APPLICATION_JSON.as_ref())?);
let authorization = credential
.get(Default::default())?
.authorization_v2_for_request(
&Method::GET,
&"http://upload.qiniup.com/".parse()?,
&headers,
&b"{\"name\":\"test\"}"[..],
);
使用七牛签名算法 V2 对 HTTP 请求(请求体为输入流)进行签名,返回 Authorization 的值
use qiniu_credential::{Credential, Method, HeaderMap, HeaderValue, prelude::*};
use http::header::CONTENT_TYPE;
use mime::APPLICATION_JSON;
use std::io::Cursor;
let credential = Credential::new("abcdefghklmnopq", "1234567890");
let mut headers = HeaderMap::new();
headers.insert(CONTENT_TYPE, HeaderValue::from_str(APPLICATION_JSON.as_ref())?);
let authorization = credential
.get(Default::default())?
.authorization_v2_for_request_with_body_reader(
&Method::GET,
&"http://upload.qiniup.com/".parse()?,
&headers,
&mut Cursor::new(b"{\"name\":\"test\"}")
)?;
sourcepub fn sign_download_url(&self, url: Uri, lifetime: Duration) -> Uri
pub fn sign_download_url(&self, url: Uri, lifetime: Duration) -> Uri
对对象的下载 URL 签名,可以生成私有存储空间的下载地址
use qiniu_credential::{Credential, prelude::*};
use std::time::Duration;
let credential = Credential::new("abcdefghklmnopq", "1234567890");
let url = "http://www.qiniu.com/?go=1".parse()?;
let url = credential
.get(Default::default())?
.sign_download_url(url, Duration::from_secs(1_234_567_890 + 3600));
assert_eq!(
url.to_string(),
"http://www.qiniu.com/?go=1&e=1234571490&token=abcdefghklmnopq%3AKjQtlGAkEOhSwtFjJfYtYa2-reE%3D",
);
Ok(())
}
sourcepub async fn sign_async_reader(
&self,
reader: &mut (dyn AsyncRead + Send + Unpin)
) -> IoResult<String>
This is supported on crate feature async
only.
pub async fn sign_async_reader(
&self,
reader: &mut (dyn AsyncRead + Send + Unpin)
) -> IoResult<String>
async
only.使用七牛签名算法对异步输入流数据进行签名
use qiniu_credential::{Credential, prelude::*};
use futures_lite::io::Cursor;
let credential = Credential::new("abcdefghklmnopq", "1234567890");
assert_eq!(
credential
.async_get(Default::default()).await?
.sign_async_reader(&mut Cursor::new(b"world")).await?,
"abcdefghklmnopq:VjgXt0P_nCxHuaTfiFz-UjDJ1AQ="
);
This is supported on crate feature async
only.
async
only.使用七牛签名算法 V1 对 HTTP 请求(请求体为异步输入流)进行签名,返回 Authorization 的值
use qiniu_credential::{Credential, HeaderValue, prelude::*};
use mime::APPLICATION_WWW_FORM_URLENCODED;
use futures_lite::io::Cursor;
let credential = Credential::new("abcdefghklmnopq", "1234567890");
let authorization = credential
.async_get(Default::default()).await?
.authorization_v1_for_request_with_async_body_reader(
&"http://upload.qiniup.com/".parse()?,
Some(&HeaderValue::from_str(APPLICATION_WWW_FORM_URLENCODED.as_ref())?),
&mut Cursor::new(b"name=test&language=go")
).await?;
This is supported on crate feature async
only.
async
only.使用七牛签名算法 V2 对 HTTP 请求(请求体为异步输入流)进行签名,返回 Authorization 的值
use qiniu_credential::{Credential, Method, HeaderMap, HeaderValue, prelude::*};
use http::header::CONTENT_TYPE;
use mime::APPLICATION_JSON;
use futures_lite::io::Cursor;
#[async_std::main]
let credential = Credential::new("abcdefghklmnopq", "1234567890");
let mut headers = HeaderMap::new();
headers.insert(CONTENT_TYPE, HeaderValue::from_str(APPLICATION_JSON.as_ref())?);
let authorization = credential
.async_get(Default::default()).await?
.authorization_v2_for_request_with_async_body_reader(
&Method::GET,
&"http://upload.qiniup.com/".parse()?,
&headers,
&mut Cursor::new(b"{\"name\":\"test\"}")
).await?;
Trait Implementations
sourceimpl Clone for GotCredential
impl Clone for GotCredential
sourcefn clone(&self) -> GotCredential
fn clone(&self) -> GotCredential
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl CredentialProvider for GotCredential
impl CredentialProvider for GotCredential
sourcefn get(&self, _opts: GetOptions) -> IoResult<GotCredential>
fn get(&self, _opts: GetOptions) -> IoResult<GotCredential>
返回七牛认证信息
sourcefn async_get(
&self,
opts: GetOptions
) -> Pin<Box<dyn Future<Output = IoResult<GotCredential>> + Send + '_>>
fn async_get(
&self,
opts: GetOptions
) -> Pin<Box<dyn Future<Output = IoResult<GotCredential>> + Send + '_>>
async
only.异步返回七牛认证信息
sourceimpl Debug for GotCredential
impl Debug for GotCredential
sourceimpl Deref for GotCredential
impl Deref for GotCredential
type Target = Credential
type Target = Credential
The resulting type after dereferencing.
sourceimpl DerefMut for GotCredential
impl DerefMut for GotCredential
sourceimpl From<Credential> for GotCredential
impl From<Credential> for GotCredential
sourcefn from(credential: Credential) -> Self
fn from(credential: Credential) -> Self
Converts to this type from the input type.
sourceimpl From<GotCredential> for Credential
impl From<GotCredential> for Credential
sourcefn from(result: GotCredential) -> Self
fn from(result: GotCredential) -> Self
Converts to this type from the input type.
sourceimpl PartialEq<GotCredential> for GotCredential
impl PartialEq<GotCredential> for GotCredential
sourcefn eq(&self, other: &GotCredential) -> bool
fn eq(&self, other: &GotCredential) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &GotCredential) -> bool
fn ne(&self, other: &GotCredential) -> bool
This method tests for !=
.
impl Eq for GotCredential
impl StructuralEq for GotCredential
impl StructuralPartialEq for GotCredential
Auto Trait Implementations
impl RefUnwindSafe for GotCredential
impl Send for GotCredential
impl Sync for GotCredential
impl Unpin for GotCredential
impl UnwindSafe for GotCredential
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more