SignedUrlAuth

Struct SignedUrlAuth 

Source
pub struct SignedUrlAuth { /* private fields */ }
Expand description

Signed URL authenticator using HMAC-SHA256.

This struct provides methods for generating and verifying signed URLs. The signing scheme binds signatures to paths, query params, and expiry times.

Implementations§

Source§

impl SignedUrlAuth

Source

pub fn new(secret_key: impl AsRef<[u8]>) -> Self

Create a new authenticator with the given secret key.

§Arguments
  • secret_key - The secret key used for HMAC computation. Should be at least 32 bytes for security.
Source

pub fn sign(&self, path: &str, ttl: Duration) -> (String, u64)

Sign a path with an expiry duration.

Returns the hex-encoded signature and the expiry timestamp (Unix epoch seconds).

§Arguments
  • path - The URL path to sign (e.g., “/tiles/slides/sample.svs/0/1/2.jpg”)
  • ttl - How long the signature should be valid
§Returns

A tuple of (signature, expiry_timestamp)

Source

pub fn sign_with_params( &self, path: &str, ttl: Duration, params: &[(&str, &str)], ) -> (String, u64)

Sign a path with extra query parameters.

params should exclude exp and sig; those are added automatically.

Source

pub fn sign_with_expiry(&self, path: &str, expiry: u64) -> String

Sign a path with a specific expiry timestamp.

This is useful when you need to generate signatures for a specific time.

§Arguments
  • path - The URL path to sign
  • expiry - Unix timestamp when the signature expires
§Returns

The hex-encoded signature

Source

pub fn sign_with_expiry_and_params( &self, path: &str, expiry: u64, params: &[(&str, &str)], ) -> String

Sign a path with a specific expiry timestamp and extra parameters.

params should exclude exp and sig; those are added automatically.

Source

pub fn verify( &self, path: &str, signature: &str, expiry: u64, params: &[(&str, &str)], ) -> Result<(), AuthError>

Verify a signature for a path and expiry.

§Arguments
  • path - The URL path that was signed
  • signature - The hex-encoded signature to verify
  • expiry - The expiry timestamp from the URL
§Returns

Ok(()) if the signature is valid and not expired, Err(AuthError) otherwise.

Source

pub fn generate_signed_url( &self, base_url: &str, path: &str, ttl: Duration, extra_params: &[(&str, &str)], ) -> String

Generate a complete signed URL.

§Arguments
  • base_url - The base URL (e.g., https://example.com)
  • path - The path to sign (e.g., “/tiles/slides/sample.svs/0/1/2.jpg”)
  • ttl - How long the signature should be valid
  • extra_params - Additional query parameters to include
§Returns

The complete signed URL

Source

pub fn generate_viewer_token( &self, slide_id: &str, ttl: Duration, ) -> (String, u64)

Generate a viewer token for accessing all tiles of a specific slide.

Viewer tokens are special tokens that authorize access to all tiles for a given slide, rather than signing individual tile paths. This is used by the built-in viewer to access tiles when auth is enabled.

§Arguments
  • slide_id - The slide identifier
  • ttl - How long the token should be valid
§Returns

A tuple of (token, expiry_timestamp)

Source

pub fn verify_viewer_token( &self, slide_id: &str, token: &str, expiry: u64, ) -> Result<(), AuthError>

Verify a viewer token for a specific slide.

§Arguments
  • slide_id - The slide identifier the token should authorize
  • token - The hex-encoded viewer token
  • expiry - The expiry timestamp
§Returns

Ok(()) if the token is valid and not expired, Err(AuthError) otherwise.

Trait Implementations§

Source§

impl Clone for SignedUrlAuth

Source§

fn clone(&self) -> SignedUrlAuth

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more