pub struct Key(/* private fields */);Expand description
Cryptographically-secure key used for signing URLs.
Implementationsยง
Sourceยงimpl Key
impl Key
Sourcepub fn from(key: &[u8]) -> Key
pub fn from(key: &[u8]) -> Key
Creates a new Key from a 512-bit cryptographically random string.
The supplied key must be at least 512-bits (64 bytes). For security, the master key must be cryptographically random.
ยงPanics
Panics if key is less than 64 bytes in length.
For a non-panicking version, use Key::try_from() or generate a key
with Key::generate() or Key::try_generate().
ยงExample
use tower_image_xform::Key;
let key = { /* a cryptographically random key >= 64 bytes */ };
let key = Key::from(key);Sourcepub fn generate() -> Key
pub fn generate() -> Key
Generates signing/encryption keys from a secure, random source. Keys are generated nondeterministically.
ยงPanics
Panics if randomness cannot be retrieved from the operating system. See
Key::try_generate() for a non-panicking version.
ยงExample
use tower_image_xform::Key;
let key = Key::generate();Sourcepub fn try_generate() -> Option<Key>
pub fn try_generate() -> Option<Key>
Attempts to generate signing/encryption keys from a secure, random
source. Keys are generated nondeterministically. If randomness cannot be
retrieved from the underlying operating system, returns None.
ยงExample
use tower_image_xform::Key;
let key = Key::try_generate();Trait Implementationsยง
Sourceยงimpl TryFrom<&[u8]> for Key
impl TryFrom<&[u8]> for Key
Sourceยงfn try_from(key: &[u8]) -> Result<Self, Self::Error>
fn try_from(key: &[u8]) -> Result<Self, Self::Error>
A fallible version of Key::from().
Succeeds when Key::from() succeds and returns an error where
Key::from() panics, namely, if key is too short.
ยงExample
use tower_image_xform::Key;
let key = { /* a cryptographically random key >= 64 bytes */ };
assert!(Key::try_from(key).is_ok());
// A key that's far too short to use.
let key = &[1, 2, 3, 4][..];
assert!(Key::try_from(key).is_err());Auto Trait Implementationsยง
impl Freeze for Key
impl RefUnwindSafe for Key
impl Send for Key
impl Sync for Key
impl Unpin for Key
impl UnwindSafe for Key
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
Sourceยงimpl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Sourceยงimpl<T> Instrument for T
impl<T> Instrument for T
Sourceยงfn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Sourceยงfn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Sourceยงimpl<T> IntoEither for T
impl<T> IntoEither for T
Sourceยงfn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSourceยงfn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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