Skip to main content

LocalFileKms

Struct LocalFileKms 

Source
pub struct LocalFileKms { /* private fields */ }
Expand description

A KEK read from a file. See the module docs for why it refuses production.

Implementations§

Source§

impl LocalFileKms

Source

pub fn open(path: impl AsRef<Path>, env: &str) -> Result<Self, KmsError>

Reads the master key from path.

env is the deployment environment, as cratefield_core::VentureEnv spells it: anything equal to "production" (case-insensitively) is refused. The environment is a parameter rather than read from the process here, so the refusal cannot be sidestepped by unsetting a variable, and so the caller passes the same value it validated everything else with.

The file holds 32 raw bytes, or their hex or base64 encoding on one line; a trailing newline is ignored, because the difference between printf and echo should not be a cryptographic event.

§Errors

KmsError::Refused in production, KmsError::Unavailable when the file cannot be read, KmsError::Invalid when its contents are not a 32-byte key.

Source

pub fn from_key( kek: Dek, key_ref: impl Into<String>, env: &str, ) -> Result<Self, KmsError>

A KEK the caller already holds, for tests that do not want a file. Refuses production for the same reason.

§Errors

KmsError::Refused in production.

Source

pub fn create(path: impl AsRef<Path>) -> Result<(), KmsError>

Writes a fresh master key to path for a development environment. Refuses to overwrite: losing a KEK means losing every secret wrapped under it, so the destructive version of this is a human deleting the file on purpose.

§Errors

KmsError::Refused when the file exists, KmsError::Unavailable when it cannot be written.

Trait Implementations§

Source§

impl Debug for LocalFileKms

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Names the key file, never its contents. Written by hand rather than derived so it cannot start printing key material because a field was added.

Source§

impl Kms for LocalFileKms

Source§

fn provider(&self) -> &'static str

Stored with every wrapped key: "local-file", "worker-secret", "aws-kms", "gcp-kms".
Source§

fn key_ref(&self) -> &str

The master key this instance wraps under, as the vendor names it. Stored with every wrapped key so a re-wrap knows what it is moving from.
Source§

fn wrap<'life0, 'life1, 'async_trait>( &'life0 self, dek: &'life1 Dek, ) -> Pin<Box<dyn Future<Output = Result<Vec<u8>, KmsError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Wraps a data key. The result is opaque to the caller and is what goes in the database (docs/SECRETS-DESIGN.md §3). Read more
Source§

fn unwrap<'life0, 'life1, 'async_trait>( &'life0 self, wrapped: &'life1 [u8], ) -> Pin<Box<dyn Future<Output = Result<Dek, KmsError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Unwraps what Kms::wrap produced. Read more

Auto Trait Implementations§

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

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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.