Skip to main content

Module signed_url

Module signed_url 

Source
Expand description

Signed URL helpers — HMAC-SHA256 with optional expiry. See signed_url::sign / signed_url::verify. Signed URL helpers — tamper-evident URLs with optional expiry.

Common uses:

  • Magic-link login (one-time URL emailed to the user)
  • Password reset confirmation links
  • Time-limited file download URLs
  • “Click here to verify your email” links

§Quick start

use rustango::signed_url::{sign, verify};
use std::time::Duration;

let secret = b"my-app-secret";

// Issue a one-hour magic-link
let url = sign("https://app.example.com/auth/login?email=alice@x.com",
               secret,
               Some(Duration::from_secs(3600)));

// On the callback handler:
match verify(&incoming_url, secret) {
    Ok(()) => { /* identity confirmed */ }
    Err(e) => { /* expired or tampered */ }
}

§How it works

Appends ?signature=<base64>&expires=<unix_secs> to the URL. The signature is HMAC-SHA256 over <scheme>://<host>/<path>?<sorted-query-without-signature>. Sorting the query parameters before signing makes the URL canonical so query ordering can’t be used to forge mismatches.

Enums§

SignedUrlError

Functions§

sign
Sign url with secret, optionally with an expiry from “now”.
sign_at
Sign url at a specific unix-seconds expiry — useful for tests.
verify
Verify the signature on url against secret. Returns Ok(()) when the URL is valid and (if it has an expires param) not yet expired.
verify_at
Verify at a specific unix-seconds wall-clock time — useful for tests.