Struct EncKeys

Source
pub struct EncKeys {
    pub enc_key_active: String,
    pub enc_keys: Vec<(String, Vec<u8>)>,
}
Expand description

Encryption keys used for all operations

These can be either used statically initialized for ease of use, or given dynamically each time. You just need to use the appropriate functions for the EncValue.

Fields§

§enc_key_active: String§enc_keys: Vec<(String, Vec<u8>)>

Implementations§

Source§

impl EncKeys

Source

pub fn re_key_id() -> &'static Regex

Source

pub fn try_parse( enc_key_active: String, enc_keys_unparsed: Vec<String>, ) -> Result<Self, CryptrError>

Source

pub fn append_new_random(&mut self) -> Result<(), CryptrError>

Generates and appends a new random encryption key

Source

pub fn append_new_random_with_id( &mut self, id: String, ) -> Result<(), CryptrError>

Generates and appends a new random encryption key with a specific ID

Source

pub async fn config_path() -> Result<String, CryptrError>

Returns the default config path.

Available with feature cli only

Source

pub fn delete(&mut self, enc_key_id: &str) -> Result<(), CryptrError>

Mutate the keys and deletes the key with the given ID, if it exists

Source

pub fn fmt_enc_keys_str_for_config(enc_keys: &str) -> (String, String)

Formats a converted ENC_KEYS string in the correct format for config / K8s secret

This is useful for generating keys somewhere else to paste them into K8s / Docker definitions later on.

§Returns 2 values:
  1. ENC_KEYS= value for a config or environment variable
  2. ENC_KEYS: with an additional base64 encoding which can be used inside a K8s secret directly
Source

pub async fn read_from_config() -> Result<Self, CryptrError>

Reads the keys from the default config

Available with feature cli only

Source

pub fn read_from_file(path: &str) -> Result<Self, CryptrError>

Reads the keys from a given file location on disk

Source

pub fn from_env() -> Result<Self, CryptrError>

Builds the keys from environment variables

Expects 2 values:

  1. ENC_KEY_ACTIVE which indicates the active, default key
  2. ENC_KEYS with the available keys in the korrect format, for instance:
ENC_KEYS="
z8ycdOXnOv7E/nxOhIuLo1oiQBpcg6lYz2Jkc3TgAYoD7h4+orRdlYAk=
test1337/HQyncjvJUNLTv2YvoTWeVmMKQLBe7+xVSHMXUVES8qE=
"
Source

pub fn keys_as_b64(&self) -> Result<String, CryptrError>

All keys merged into a single String for usage via ENV vars

Source

pub fn keys_as_b64_vec(&self) -> Vec<String>

All keys converted to b64 inside a Vec<_>.

Source

pub async fn save_to_file(&self, file: &str) -> Result<(), CryptrError>

Source

pub async fn save_to_file_with_path( &self, path: &str, file_name: &str, ) -> Result<(), CryptrError>

Source

pub fn get_key(&self, enc_key_id: &str) -> Result<&[u8], CryptrError>

Returns a reference to specified EncKey

Source

pub fn get_static<'a>() -> &'a Self

Returns a reference to the initialized EncKeys.

init() must have been called at application startup for this to succeed.

§Panics

If the EncKeys have not been set up at startup with init()

Source

pub fn get_static_key<'a>(enc_key_id: &str) -> Result<&'a [u8], CryptrError>

Returns a reference to specified EncKey

init() must have been called at application startup for this to succeed.

Source

pub fn get_key_active<'a>() -> Result<&'a [u8], CryptrError>

Returns a reference to currently active EncKey

init() must have been called at application startup for this to succeed.

Source

pub fn init(self) -> Result<(), CryptrError>

Initialize the encryption keys statically for ease of use.

This function must be called before accessing EncKeys::get(), or basically with any function that uses the static keys.

Throws an error if called more than once.

Source

pub fn generate() -> Result<Self, CryptrError>

Generates a new random encryption key

Source

pub fn generate_multiple(number_of_keys: u16) -> Result<Self, CryptrError>

Generates a new random set of encryption keys

Source

pub fn generate_with_id(id: String) -> Result<Self, CryptrError>

Generates a new random encryption key with a specific ID

Source

pub fn try_convert_legacy_keys(keys: &str) -> Result<String, CryptrError>

Used for compatibility with the older system

This will convert the old encryption key format into the new one

Trait Implementations§

Source§

impl<'__de, __Context> BorrowDecode<'__de, __Context> for EncKeys

Source§

fn borrow_decode<__D: BorrowDecoder<'__de, Context = __Context>>( decoder: &mut __D, ) -> Result<Self, DecodeError>

Attempt to decode this type with the given BorrowDecode.
Source§

impl Debug for EncKeys

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<__Context> Decode<__Context> for EncKeys

Source§

fn decode<__D: Decoder<Context = __Context>>( decoder: &mut __D, ) -> Result<Self, DecodeError>

Attempt to decode this type with the given Decode.
Source§

impl Default for EncKeys

Source§

fn default() -> EncKeys

Returns the “default value” for a type. Read more
Source§

impl Encode for EncKeys

Source§

fn encode<__E: Encoder>(&self, encoder: &mut __E) -> Result<(), EncodeError>

Encode a given type.
Source§

impl From<KdfValue> for EncKeys

Source§

fn from(kdf: KdfValue) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for EncKeys

Source§

fn eq(&self, other: &EncKeys) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl TryFrom<&[u8]> for EncKeys

Source§

type Error = CryptrError

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

fn try_from(value: &[u8]) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl StructuralPartialEq for EncKeys

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

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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 = 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>,

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,