pub struct DMSCJWTRevocationList { /* private fields */ }Expand description
JWT token revocation list for managing invalidated tokens.
This struct provides functionality to revoke JWT tokens and check if tokens have been revoked. It uses concurrent data structures for thread-safe access.
§Usage
The revocation list can be used to implement token invalidation scenarios:
- User logout (revoke specific token)
- Password change (revoke all user tokens)
- Security incidents (bulk revocation)
§Storage
By default, revoked tokens are stored in-memory. For production use, consider integrating with Redis or a database-backed storage solution to persist revocations across application restarts.
Implementations§
Source§impl DMSCJWTRevocationList
impl DMSCJWTRevocationList
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new JWT revocation list with default capacity.
This constructor initializes an empty revocation list with the default maximum capacity for storing revoked tokens.
§Returns
A new instance of DMSCJWTRevocationList
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Creates a new JWT revocation list with specified capacity.
This constructor allows specifying the maximum number of revoked tokens that can be stored. When the capacity is exceeded, oldest revoked tokens are automatically removed.
§Parameters
capacity: Maximum number of revoked tokens to store
§Returns
A new instance of DMSCJWTRevocationList with specified capacity
Source§impl DMSCJWTRevocationList
impl DMSCJWTRevocationList
Sourcepub fn revoke_token(
&self,
token: &str,
user_id: &str,
reason: Option<String>,
ttl_secs: u64,
)
pub fn revoke_token( &self, token: &str, user_id: &str, reason: Option<String>, ttl_secs: u64, )
Revokes a specific JWT token.
This method adds a token to the revocation list with associated metadata. The token will be considered invalid for the specified time-to-live duration.
§Automatic Cleanup
After revocation, expired tokens are automatically cleaned up if the revocation list exceeds its maximum capacity.
§Parameters
token: The JWT token string to revokeuser_id: The user ID associated with the tokenreason: Optional reason for revocationttl_secs: Time-to-live in seconds for this revocation record
Sourcepub fn revoke_all_user_tokens(
&self,
user_id: &str,
reason: Option<String>,
) -> usize
pub fn revoke_all_user_tokens( &self, user_id: &str, reason: Option<String>, ) -> usize
Revokes all tokens for a specific user.
This method finds all tokens associated with the given user ID and marks them as revoked. Useful for implementing “logout everywhere” functionality or revoking tokens after a security incident.
§Parameters
user_id: The user ID whose tokens should be revokedreason: Optional reason for the mass revocation
§Returns
The number of tokens that were revoked
Sourcepub fn is_revoked(&self, token: &str) -> bool
pub fn is_revoked(&self, token: &str) -> bool
Checks if a token has been revoked.
This method performs an O(1) lookup to determine if a token exists in the revocation list. If found, it also checks if the revocation record has expired and removes it if so.
§Expiration Handling
If the token is found but its revocation record has expired, the token is automatically removed and treated as not revoked.
§Parameters
token: The JWT token string to check
§Returns
true if the token is revoked and valid, false otherwise
Sourcepub fn get_revocation_info(&self, token: &str) -> Option<DMSCRevokedTokenInfo>
pub fn get_revocation_info(&self, token: &str) -> Option<DMSCRevokedTokenInfo>
Retrieves revocation information for a specific token.
This method returns the metadata associated with a revoked token, including when it was revoked and the reason (if provided).
§Parameters
token: The JWT token string to look up
§Returns
Some(DMSCRevokedTokenInfo) if the token is revoked, None otherwise
Sourcepub fn get_revoked_count(&self) -> usize
pub fn get_revoked_count(&self) -> usize
Returns the current count of revoked tokens.
This method provides the number of tokens currently in the revocation list.
§Returns
The number of revoked tokens stored
Trait Implementations§
Source§impl Default for DMSCJWTRevocationList
impl Default for DMSCJWTRevocationList
Source§impl<'py> IntoPyObject<'py> for DMSCJWTRevocationList
impl<'py> IntoPyObject<'py> for DMSCJWTRevocationList
Source§type Target = DMSCJWTRevocationList
type Target = DMSCJWTRevocationList
Source§type Output = Bound<'py, <DMSCJWTRevocationList as IntoPyObject<'py>>::Target>
type Output = Bound<'py, <DMSCJWTRevocationList as IntoPyObject<'py>>::Target>
Source§fn into_pyobject(
self,
py: Python<'py>,
) -> Result<<Self as IntoPyObject<'_>>::Output, <Self as IntoPyObject<'_>>::Error>
fn into_pyobject( self, py: Python<'py>, ) -> Result<<Self as IntoPyObject<'_>>::Output, <Self as IntoPyObject<'_>>::Error>
Source§impl PyClass for DMSCJWTRevocationList
impl PyClass for DMSCJWTRevocationList
Source§impl PyClassImpl for DMSCJWTRevocationList
impl PyClassImpl for DMSCJWTRevocationList
Source§const IS_BASETYPE: bool = false
const IS_BASETYPE: bool = false
Source§const IS_SUBCLASS: bool = false
const IS_SUBCLASS: bool = false
Source§const IS_MAPPING: bool = false
const IS_MAPPING: bool = false
Source§const IS_SEQUENCE: bool = false
const IS_SEQUENCE: bool = false
Source§const IS_IMMUTABLE_TYPE: bool = false
const IS_IMMUTABLE_TYPE: bool = false
Source§const RAW_DOC: &'static CStr = /// to persist revocations across application restarts.
const RAW_DOC: &'static CStr = /// to persist revocations across application restarts.
Source§const DOC: &'static CStr
const DOC: &'static CStr
text_signature if a constructor is defined. Read moreSource§type ThreadChecker = SendablePyClass<DMSCJWTRevocationList>
type ThreadChecker = SendablePyClass<DMSCJWTRevocationList>
Source§type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild
type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild
Source§type BaseNativeType = PyAny
type BaseNativeType = PyAny
PyAny by default, and when you declare
#[pyclass(extends=PyDict)], it’s PyDict.fn items_iter() -> PyClassItemsIter
fn lazy_type_object() -> &'static LazyTypeObject<Self>
fn dict_offset() -> Option<isize>
fn weaklist_offset() -> Option<isize>
Source§impl PyClassNewTextSignature for DMSCJWTRevocationList
impl PyClassNewTextSignature for DMSCJWTRevocationList
const TEXT_SIGNATURE: &'static str = "()"
Source§impl PyMethods<DMSCJWTRevocationList> for PyClassImplCollector<DMSCJWTRevocationList>
impl PyMethods<DMSCJWTRevocationList> for PyClassImplCollector<DMSCJWTRevocationList>
fn py_methods(self) -> &'static PyClassItems
Source§impl PyTypeInfo for DMSCJWTRevocationList
impl PyTypeInfo for DMSCJWTRevocationList
Source§fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
§fn type_object(py: Python<'_>) -> Bound<'_, PyType>
fn type_object(py: Python<'_>) -> Bound<'_, PyType>
§fn is_type_of(object: &Bound<'_, PyAny>) -> bool
fn is_type_of(object: &Bound<'_, PyAny>) -> bool
object is an instance of this type or a subclass of this type.§fn is_exact_type_of(object: &Bound<'_, PyAny>) -> bool
fn is_exact_type_of(object: &Bound<'_, PyAny>) -> bool
object is an instance of this type.impl DerefToPyAny for DMSCJWTRevocationList
impl ExtractPyClassWithClone for DMSCJWTRevocationList
Auto Trait Implementations§
impl Freeze for DMSCJWTRevocationList
impl !RefUnwindSafe for DMSCJWTRevocationList
impl Send for DMSCJWTRevocationList
impl Sync for DMSCJWTRevocationList
impl Unpin for DMSCJWTRevocationList
impl UnwindSafe for DMSCJWTRevocationList
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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§impl<'py, T> IntoPyObjectExt<'py> for Twhere
T: IntoPyObject<'py>,
impl<'py, T> IntoPyObjectExt<'py> for Twhere
T: IntoPyObject<'py>,
§fn into_bound_py_any(self, py: Python<'py>) -> Result<Bound<'py, PyAny>, PyErr>
fn into_bound_py_any(self, py: Python<'py>) -> Result<Bound<'py, PyAny>, PyErr>
self into an owned Python object, dropping type information.§fn into_py_any(self, py: Python<'py>) -> Result<Py<PyAny>, PyErr>
fn into_py_any(self, py: Python<'py>) -> Result<Py<PyAny>, PyErr>
self into an owned Python object, dropping type information and unbinding it
from the 'py lifetime.§fn into_pyobject_or_pyerr(self, py: Python<'py>) -> Result<Self::Output, PyErr>
fn into_pyobject_or_pyerr(self, py: Python<'py>) -> Result<Self::Output, PyErr>
self into a Python object. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PyErrArguments for T
impl<T> PyErrArguments for T
§impl<T> PyTypeCheck for Twhere
T: PyTypeInfo,
impl<T> PyTypeCheck for Twhere
T: PyTypeInfo,
§const NAME: &'static str = T::NAME
const NAME: &'static str = T::NAME
§fn type_check(object: &Bound<'_, PyAny>) -> bool
fn type_check(object: &Bound<'_, PyAny>) -> bool
§fn classinfo_object(py: Python<'_>) -> Bound<'_, PyAny>
fn classinfo_object(py: Python<'_>) -> Bound<'_, PyAny>
isinstance and issubclass function. Read more