pub struct AuthRateLimiter { /* private fields */ }Expand description
Per-IP auth attempt tracker with sliding window and lockout.
Implementations§
Source§impl AuthRateLimiter
impl AuthRateLimiter
pub fn new() -> Self
Sourcepub fn check_rate_limit(
&self,
key: &str,
peer_is_loopback: bool,
) -> Result<(), RateLimitError>
pub fn check_rate_limit( &self, key: &str, peer_is_loopback: bool, ) -> Result<(), RateLimitError>
Check whether the client identified by key is allowed to attempt auth.
peer_is_loopback must reflect the socket peer (never a value
derived from client-supplied headers). When true, rate limiting is
skipped — local administrators may retry freely. Trusting a
header-derived loopback value would let an attacker spoof
X-Forwarded-For: 127.0.0.1 to bypass the lockout.
Does not record a new attempt — call [record_attempt] after
verifying the attempt actually happened (regardless of success/failure).
Sourcepub fn record_attempt(&self, key: &str, peer_is_loopback: bool)
pub fn record_attempt(&self, key: &str, peer_is_loopback: bool)
Record a new authentication attempt for key.
See check_rate_limit for peer_is_loopback
semantics. Only the socket peer may be trusted as loopback.
Sourcepub fn is_locked_out(&self, key: &str, peer_is_loopback: bool) -> bool
pub fn is_locked_out(&self, key: &str, peer_is_loopback: bool) -> bool
Check whether key is currently locked out, without recording anything.
See check_rate_limit for peer_is_loopback
semantics. Only the socket peer may be trusted as loopback.
Trait Implementations§
Source§impl Debug for AuthRateLimiter
impl Debug for AuthRateLimiter
Auto Trait Implementations§
impl !Freeze for AuthRateLimiter
impl !RefUnwindSafe for AuthRateLimiter
impl Send for AuthRateLimiter
impl Sync for AuthRateLimiter
impl Unpin for AuthRateLimiter
impl UnsafeUnpin for AuthRateLimiter
impl UnwindSafe for AuthRateLimiter
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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for 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 more