pub struct TokenAuthenticator { /* private fields */ }Available on crate feature
auth-token only.Expand description
A production-ready, time-limited signed-token authenticator
(feature = "auth-token").
A token binds a StreamKey to an expiry under an HMAC-SHA-256 signature,
so it cannot be forged without the shared secret nor replayed past its
deadline. The wire form is:
<expiry_unix_seconds>:<hex(hmac_sha256(secret, "app/stream:expiry"))>Mint tokens out-of-band (e.g. in your sign-in / “get publish URL” endpoint)
with sign; the engine verifies them on the publish path —
and, when gate_playback is set, the play path too.
Verification is constant-time and pulls in no crypto dependency (the
HMAC is a small, test-vector-checked in-crate implementation).
use arcly_stream::auth::TokenAuthenticator;
use arcly_stream::StreamKey;
let auth = TokenAuthenticator::new("super-secret");
let key = StreamKey::new("live", "cam-1");
// Mint a token valid until some absolute Unix time:
let token = auth.sign(&key, 9_999_999_999);
assert!(auth.verify(&key, &token).is_ok());
// A token for a different stream is rejected:
assert!(auth.verify(&StreamKey::new("live", "other"), &token).is_err());Implementations§
Source§impl TokenAuthenticator
impl TokenAuthenticator
Sourcepub fn new(secret: impl Into<Vec<u8>>) -> Self
pub fn new(secret: impl Into<Vec<u8>>) -> Self
New authenticator keyed by secret. Gates publish only by default;
call gate_playback to gate play as well.
Sourcepub fn gate_playback(self, gate: bool) -> Self
pub fn gate_playback(self, gate: bool) -> Self
Also require a valid token to play (subscribe), not just publish.
Trait Implementations§
Source§impl StreamAuthenticator for TokenAuthenticator
impl StreamAuthenticator for TokenAuthenticator
Decide whether
creds may subscribe to key.Auto Trait Implementations§
impl Freeze for TokenAuthenticator
impl RefUnwindSafe for TokenAuthenticator
impl Send for TokenAuthenticator
impl Sync for TokenAuthenticator
impl Unpin for TokenAuthenticator
impl UnsafeUnpin for TokenAuthenticator
impl UnwindSafe for TokenAuthenticator
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
Mutably borrows from an owned value. Read more