pub struct UrlSigner { /* private fields */ }Expand description
Signs and verifies URLs.
Implementations§
Source§impl UrlSigner
impl UrlSigner
Sourcepub fn new(keys: KeyRing) -> Self
pub fn new(keys: KeyRing) -> Self
A signer over keys.
The same ring the rest of the application encrypts with, so rotating a key retires the links it signed — which is the correct behaviour and worth knowing before rotating one: every outstanding verification email stops working.
Sourcepub fn sign(&self, url: &str) -> Result<String>
pub fn sign(&self, url: &str) -> Result<String>
Sign url, which may be a path or an absolute URL.
Returns it with signature appended.
Sourcepub fn sign_until(&self, url: &str, expires_at: i64) -> Result<String>
pub fn sign_until(&self, url: &str, expires_at: i64) -> Result<String>
Sign url so that it stops verifying after expires_at.
expires_at is seconds since the epoch. It goes into the query — and
is therefore signed, so it cannot be moved without invalidating the
link.
Sourcepub fn verify(&self, url: &str) -> Result<()>
pub fn verify(&self, url: &str) -> Result<()>
Whether url carries a signature this application produced, and has
not expired.
§Errors
Distinguishes the two cases a caller wants to tell apart: a link that was never valid, and one that was and is not any more. Somebody with an expired verification email should be offered a new one; somebody with a forged link should not.
Sourcepub fn signature_for(&self, url: &str) -> Result<String>
pub fn signature_for(&self, url: &str) -> Result<String>
The signature for a URL, without attaching it.
For a caller building the link some other way — a redirect, a template — that still wants the same tag.