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<'_>
impl Verifier<'_>
Sourcepub fn generate_default() -> Self
pub fn generate_default() -> Self
Generates random Self with default length.
Sourcepub fn generate_encode(count: Count) -> Self
pub fn generate_encode(count: Count) -> Self
Generates count random bytes length and encodes them into Self.
Sourcepub fn generate_encode_default() -> Self
pub fn generate_encode_default() -> Self
Generates random bytes of default length and encodes them into Self.
Source§impl<'v> Verifier<'v>
impl<'v> Verifier<'v>
Sourcepub fn new(value: Cow<'v, str>) -> Result<Self, Error>
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.
Sourcepub const unsafe fn new_unchecked(value: Cow<'v, str>) -> Self
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.
Sourcepub const unsafe fn borrowed_unchecked(value: &'v str) -> Self
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.
Sourcepub const unsafe fn owned_unchecked(value: String) -> Self
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.
Sourcepub const fn const_borrowed(value: &'v str) -> Result<Self, Error>
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.
Sourcepub const fn const_borrowed_ok(value: &'v str) -> Option<Self>
pub const fn const_borrowed_ok(value: &'v str) -> Option<Self>
Similar to const_borrowed, but errors are discarded.
Sourcepub const fn const_check_str(string: &str) -> Result<(), Error>
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:
- the length of the string is invalid (see
Length::check); - the string contains invalid character(s) (see
string::check).
Sourcepub fn check_str(string: &str) -> Result<(), Error>
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:
- the length of the string is invalid (see
Length::check); - the string contains invalid character(s) (see
string::check).
Source§impl Verifier<'_>
impl Verifier<'_>
Sourcepub fn encode<B: AsRef<[u8]>>(bytes: B) -> Result<Self, Error>
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.
Sourcepub unsafe fn encode_unchecked<B: AsRef<[u8]>>(bytes: B) -> Self
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<'de> Deserialize<'de> for Verifier<'_>
Available on crate feature serde only.
impl<'de> Deserialize<'de> for Verifier<'_>
serde only.Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Source§impl IntoStatic for Verifier<'_>
Available on crate feature static only.
impl IntoStatic for Verifier<'_>
static only.Source§fn into_static(self) -> Self::Static
fn into_static(self) -> Self::Static
Self to Self::Static.