Struct Verify
pub struct Verify<V, F = Closed> { /* private fields */ }Expand description
A policy that decides with a TokenVerifier when the peer presents a token.
With a token, the verifier decides. A token it rejects is a rejection,
and never falls through to the fallback, so a peer cannot get the
fallback’s rights with a forged token. Without a token, the fallback
policy decides. The default fallback, Closed, makes the token
required.
One case falls through: when a node decides again about a live session
and the verifier rejects its token with moq_net::Error::Expired, the
fallback decides. A session whose token expires thus narrows to the
fallback’s rights, or closes under Closed. A new session with an
expired token is rejected.
A node that dials a peer decides with no token, so the fallback decides
every dial, and under Closed the node can dial nobody.
The token is the one SessionRequest::token
returns.
§Examples
Admit peers with a valid token, and let others subscribe:
use moq_ext_access::{
Grant,
policy::{self, Decision, PeerRequest, Rejection, TokenVerifier, Verify},
};
#[derive(Debug)]
struct Password;
impl TokenVerifier<String> for Password {
fn verify(&self, token: &str, _request: &PeerRequest<String>) -> Decision {
match token {
"secret" => Ok(Grant::everything().into()),
_ => Err(Rejection::new("wrong password")),
}
}
}
let policy = Verify::new(Password).with_fallback(policy::Open(Grant::subscribe_only()));Implementations§
§impl<V, F> Verify<V, F>
impl<V, F> Verify<V, F>
pub fn with_fallback<G>(self, fallback: G) -> Verify<V, G>
pub fn with_fallback<G>(self, fallback: G) -> Verify<V, G>
Returns this policy with fallback deciding the requests without a token.
Trait Implementations§
Auto Trait Implementations§
impl<V, F> Freeze for Verify<V, F>
impl<V, F> RefUnwindSafe for Verify<V, F>where
V: RefUnwindSafe,
F: RefUnwindSafe,
impl<V, F> Send for Verify<V, F>
impl<V, F> Sync for Verify<V, F>
impl<V, F> Unpin for Verify<V, F>
impl<V, F> UnsafeUnpin for Verify<V, F>where
V: UnsafeUnpin,
F: UnsafeUnpin,
impl<V, F> UnwindSafe for Verify<V, F>where
V: UnwindSafe,
F: UnwindSafe,
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<P, T> DynPolicy<P> for Twhere
P: PeerId,
T: Policy<P>,
impl<P, T> DynPolicy<P> for Twhere
P: PeerId,
T: Policy<P>,
§fn decide<'a>(
&'a self,
request: &'a PeerRequest<P>,
) -> Pin<Box<dyn Future<Output = Result<Authorization, Rejection>> + Send + 'a>>
fn decide<'a>( &'a self, request: &'a PeerRequest<P>, ) -> Pin<Box<dyn Future<Output = Result<Authorization, Rejection>> + Send + 'a>>
Policy::decide does, with a boxed future.