Struct fastly::secret_store::Secret

source ·
pub struct Secret { /* private fields */ }
Expand description

A secret from a secret store.

A secret name has a maximum length of 255 bytes and must contain only letters, numbers, dashes (-), underscores (_), and periods (.).

A secret value has a maximum length of 64 KiB.

Implementations§

source§

impl Secret

source

pub fn plaintext(&self) -> Bytes

Read the plaintext contents of a secret into memory as a byte buffer.

Once a secret is read into memory, a secret’s contents can be repeatedly accessed cheaply.

See [try_plaintext()Secret::try_plaintext() for a fallible equivalent of this method.

§Examples
let secret = secret_store.get("example").unwrap();
assert_eq!(secret.plaintext(), "hello world!")

Check if a HeaderValue matches the contents of a secret.

let secret = secret_store.get("example").unwrap();
let header = request.get_header("example").unwrap();
if secret.plaintext() == header.as_bytes() {
    println!("you have guessed correctly!");
}
source

pub fn try_plaintext(&self) -> Result<Bytes, DecryptError>

Try to read the plaintext contents of a secret into memory as a byte buffer.

Once a secret is read into memory, a secret’s contents can be repeatedly accessed cheaply.

source

pub fn from_bytes(secret: Vec<u8>) -> Result<Self, FastlyStatus>

Create a new “secret” from the given memory. This is not the suggested way to create Secrets; instead, we suggest using SecretStore::get. This secret will NOT be shared with other sessions.

This method can be used for data that should be secret, but is being obtained by some other means than the secret store. New “secrets” created this way use plaintext only, and live in the session’s memory unencrypted for much longer than secrets generated by SecretStore::get. They should thus only be used in situations in which an API requires a Secret, but you cannot (for whatever reason) use a SecretStore to store them.

As the early note says, this Secret will be local to the current session, and will not be shared with other sessions of this service.

Auto Trait Implementations§

§

impl !Freeze for Secret

§

impl !RefUnwindSafe for Secret

§

impl Send for Secret

§

impl !Sync for Secret

§

impl Unpin for Secret

§

impl UnwindSafe for Secret

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> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Same for T

§

type Output = T

Should always be Self
source§

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

§

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>,

§

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.