---
title: Secret
summary: A secret from a secret store.
url: https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/secret_store/struct.Secret/
---

**Kind:** Struct  
**Module:** [secret_store](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/secret_store/)  
**Package:** fastly 0.13.1  
**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/secret_store.rs#72

```rust
pub struct Secret { /* private fields */ }
```

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.

## Methods

### from_bytes

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/secret_store.rs#150

```rust
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
[`Secret`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/secret_store/struct.Secret/)s; instead, we suggest using [`SecretStore::get`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/secret_store/struct.SecretStore/#method-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`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/secret_store/struct.SecretStore/#method-get). They should thus only be used in situations in
which an API requires a [`Secret`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/secret_store/struct.Secret/), but you cannot (for whatever reason) use a
[`SecretStore`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/secret_store/struct.SecretStore/) to store them.

As the early note says, this [`Secret`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/secret_store/struct.Secret/) will be local to the current session, and
will not be shared with other sessions of this service.

**Parameters**

- `secret`: `Vec<u8>`

**Returns**

`Result<Self, fastly_shared::FastlyStatus>`

### plaintext

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/secret_store.rs#107

```rust
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()`](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/secret_store/struct.Secret/#method-try_plaintext) for a fallible equivalent of this method.

#### Examples

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

Check if a [`HeaderValue`](https://docs.rs/http/latest/http/header/value/struct.HeaderValue.html) matches the contents of a secret.

```rust
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!");
}
```

**Parameters**

- `self`: `&Self`

**Returns**

`Bytes`

### try_plaintext

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/secret_store.rs#115

```rust
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.

**Parameters**

- `self`: `&Self`

**Returns**

`Result<Bytes, DecryptError>`

## Auto trait implementations

- `Freeze`
- `RefUnwindSafe`
- `Send`
- `Sync`
- `Unpin`
- `UnsafeUnpin`
- `UnwindSafe`

## Blanket implementations

- `Any`
- `Borrow<T>`
- `BorrowMut<T>`
- `Downcast`
- `ErasedDestructor`
- `From<T>`
- `Into<U>`
- `IntoEither`
- `Same`
- `TryFrom<U>`
- `TryInto<U>`
