Agent

Struct Agent 

Source
pub struct Agent { /* private fields */ }
Expand description

加解密功能代理。是加解密方法的数据结构载体。

Implementations§

Source§

impl Agent

Source

pub fn new(token: &str, key: &str) -> Self

使用给定的Token和AES加密Key初始化代理。参数key为BASE64编码后的字符串。

Source

pub fn generate_signature(&self, inputs: &[&str]) -> String

根据请求数据生成签名,用于校验微信服务器的请求是否合规。输入数据不需要包含Token。

§Example
use wecom_crypto::Agent;

let agent = Agent::new("a", "cGCVnNJRgRu6wDgo7gxG2diBovGnRQq1Tqy4Rm4V4qF");
assert_eq!(
    agent.generate_signature(&["0", "c", "b"]),
    "a8addbc99f8b3f51d2adbceb605d650b9a8940e2"
)
Source

pub fn encrypt(&self, input: &Source) -> String

加密给定的数据结构体。加密后的字符串为BASE64编码后的数据。

Source

pub fn decrypt(&self, encoded: &str) -> Result<Source, CryptoError>

解密BASE64编码的加密数据。解密后的数据为Source类型。

Trait Implementations§

Source§

impl Clone for Agent

Source§

fn clone(&self) -> Agent

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl Freeze for Agent

§

impl RefUnwindSafe for Agent

§

impl Send for Agent

§

impl Sync for Agent

§

impl Unpin for Agent

§

impl UnwindSafe for Agent

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V