Struct Verifier

Source
pub struct Verifier<'v> { /* private fields */ }
Expand description

Represents PKCE code verifiers.

Refer to the module documentation for more information.

§Examples

use pkce_std::verifier::Verifier;

let string = "dGhhbmtzIGZvciByZWFkaW5nIGRvY3MhIH4gbmVraXQ";

let expected = Verifier::borrowed(string).unwrap();

let bytes = "thanks for reading docs! ~ nekit";

let verifier = Verifier::encode(bytes).unwrap();

// `verifier` and `expected` are compared in constant time!
assert_eq!(verifier, expected);

Implementations§

Source§

impl Verifier<'_>

Source

pub fn get(&self) -> &str

Returns the borrowed string.

Source§

impl Verifier<'_>

Source

pub fn generate(length: Length) -> Self

Generates random Self with specified length.

Source

pub fn generate_default() -> Self

Generates random Self with default length.

Source

pub fn generate_encode(count: Count) -> Self

Generates count random bytes length and encodes them into Self.

Source

pub fn generate_encode_default() -> Self

Generates random bytes of default length and encodes them into Self.

Source§

impl Verifier<'_>

Source

pub fn challenge_using(&self, method: Method) -> Challenge

Computes the Challenge of Self with the given Method.

Source

pub fn challenge(&self) -> Challenge

Computes the Challenge of Self with the default Method.

Source

pub fn verify(&self, challenge: &Challenge) -> bool

Verifies the given Challenge against Self.

Source§

impl<'v> Verifier<'v>

Source

pub fn new(value: Cow<'v, str>) -> Result<Self, Error>

Constructs Self, provided that the given value is valid.

§Errors

See Self::check for more information.

Source

pub const unsafe fn new_unchecked(value: Cow<'v, str>) -> Self

Constructs Self without checking the value.

§Safety

The caller must ensure that value is valid for Self.

The value can be checked using Self::check.

Source

pub fn borrowed(value: &'v str) -> Result<Self, Error>

Constructs Self from borrowed value, provided it is valid.

§Errors

See Self::new for more information.

Source

pub const unsafe fn borrowed_unchecked(value: &'v str) -> Self

Constructs Self from borrowed value without checking it.

§Safety

See Self::new_unchecked for more information.

Source

pub fn owned(value: String) -> Result<Self, Error>

Constructs Self from owned value, provided it is valid.

§Errors

See Self::new for more information.

Source

pub const unsafe fn owned_unchecked(value: String) -> Self

Constructs Self from owned value without checking it.

§Safety

See Self::new_unchecked for more information.

Source

pub const fn const_borrowed(value: &'v str) -> Result<Self, Error>

Similar to borrowed, but can be used in const contexts.

§Note

One may need to increase the recursion limit when using longer strings.

This is done via applying the recursion_limit attribute to the crate:

#![recursion_limit = "256"]
§Errors

See const_check_str for more information.

Source

pub const fn const_borrowed_ok(value: &'v str) -> Option<Self>

Similar to const_borrowed, but errors are discarded.

Source

pub const fn const_check_str(string: &str) -> Result<(), Error>

Constantly checks if the given string is valid for Self.

§Note

One may need to increase the recursion limit when checking longer strings.

This is done via applying the recursion_limit attribute to the crate:

#![recursion_limit = "256"]
§Errors

Returns Error if the string is invalid, which means either:

Source

pub fn check_str(string: &str) -> Result<(), Error>

Checks if the given string is valid for Self.

§Errors

Returns Error if the string is invalid, which means either:

Source

pub fn check<S: AsRef<str>>(value: S) -> Result<(), Error>

Similar to check_str, except it is generic over AsRef<str>.

§Errors

Any Error returned by check_str is propagated.

Source

pub fn take(self) -> Cow<'v, str>

Consumes Self and returns the contained string.

Source§

impl Verifier<'_>

Source

pub fn encode<B: AsRef<[u8]>>(bytes: B) -> Result<Self, Error>

Encodes the given bytes into Self, provided bytes has valid length.

§Errors

Returns count::Error if the length of bytes is invalid.

Source

pub unsafe fn encode_unchecked<B: AsRef<[u8]>>(bytes: B) -> Self

Encodes the given bytes into Self without checking bytes length.

§Safety

The caller must ensure that bytes has valid length.

The bytes can be checked using Count::check on its length.

Trait Implementations§

Source§

impl AsRef<str> for Verifier<'_>

Source§

fn as_ref(&self) -> &str

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'v> Clone for Verifier<'v>

Source§

fn clone(&self) -> Verifier<'v>

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
Source§

impl<'v> Debug for Verifier<'v>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Verifier<'_>

Available on crate feature serde only.
Source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Verifier<'_>

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Hash for Verifier<'_>

Source§

fn hash<H: Hasher>(&self, hasher: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl IntoStatic for Verifier<'_>

Available on crate feature static only.
Source§

type Static = Verifier<'static>

The type with 'static lifetimes.
Source§

fn into_static(self) -> Self::Static

Upgrades Self to Self::Static.
Source§

impl PartialEq for Verifier<'_>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Verifier<'_>

Available on crate feature serde only.
Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for Verifier<'_>

Auto Trait Implementations§

§

impl<'v> Freeze for Verifier<'v>

§

impl<'v> RefUnwindSafe for Verifier<'v>

§

impl<'v> Send for Verifier<'v>

§

impl<'v> Sync for Verifier<'v>

§

impl<'v> Unpin for Verifier<'v>

§

impl<'v> UnwindSafe for Verifier<'v>

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,