pub struct CaptchaManager { /* private fields */ }Implementations§
Source§impl CaptchaManager
impl CaptchaManager
Sourcepub fn new(
secret: String,
challenge_ttl: u64,
noise: NoiseOptions,
registry: Option<Arc<dyn ChallengeRegistry>>,
gen_opts: GenerationOptions,
samples: &SampleSet,
) -> Result<Self>
pub fn new( secret: String, challenge_ttl: u64, noise: NoiseOptions, registry: Option<Arc<dyn ChallengeRegistry>>, gen_opts: GenerationOptions, samples: &SampleSet, ) -> Result<Self>
secret must be at least 32 bytes. It is zeroized on drop.
Without a registry every challenge accepts nine guesses.
samples is decoded once here.
§Errors
Returns CaptchaError::InvalidInput if secret is shorter
than 32 bytes, if challenge_ttl is outside 1..=86400, or
if noise, gen_opts or samples are out of range.
Returns CaptchaError::Decode if a sample fails to decode.
Sourcepub fn generate_challenge<T: SpriteTarget>(&self) -> Result<CaptchaChallenge<T>>
pub fn generate_challenge<T: SpriteTarget>(&self) -> Result<CaptchaChallenge<T>>
§Errors
Returns CaptchaError::Decode or CaptchaError::Encode
when the sprite cannot be built, and CaptchaError::Clock
when the system clock predates the unix epoch.
Sourcepub fn verify_challenge(
&self,
challenge_id: &str,
selected: &[u8],
) -> Result<bool>
pub fn verify_challenge( &self, challenge_id: &str, selected: &[u8], ) -> Result<bool>
selected holds one index per round, in the order
the sprites were issued. Returns Ok(false) for
a well-formed guess that does not match.
§Errors
Returns CaptchaError::InvalidInput for a
challenge_id that is empty or longer than an
issued id, a selected length other than
GenerationOptions::rounds, or any index
outside 1..=9. Returns CaptchaError::Registry
when the registry refuses the id, including a
correct guess that lost a race to an earlier one.
Auto Trait Implementations§
impl !RefUnwindSafe for CaptchaManager
impl !UnwindSafe for CaptchaManager
impl Freeze for CaptchaManager
impl Send for CaptchaManager
impl Sync for CaptchaManager
impl Unpin for CaptchaManager
impl UnsafeUnpin for CaptchaManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.