Secret
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
View sourceCreate 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.
Parameters
- secret: Vec<u8>
Returns
plaintext
View sourcefn plaintext(&self) -> BytesRead 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() 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!");}Parameters
- self: &Self
Returns
try_plaintext
View sourceTry 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