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
 
impl EncKeys
sourcepub fn append_new_random(&mut self) -> Result<(), CryptrError>
 
pub fn append_new_random(&mut self) -> Result<(), CryptrError>
Generates and appends a new random encryption key
sourcepub fn append_new_random_with_id(
    &mut self,
    id: String
) -> Result<(), CryptrError>
 
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
sourcepub fn config_path() -> Result<String, CryptrError>
 
pub fn config_path() -> Result<String, CryptrError>
Returns the default config path.
Available with feature cli only
sourcepub fn delete(&mut self, enc_key_id: &str) -> Result<(), CryptrError>
 
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
sourcepub fn fmt_enc_keys_str_for_config(enc_keys: &str) -> (String, String)
 
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:
ENC_KEYS=value for a config or environment variableENC_KEYS:with an additional base64 encoding which can be used inside a K8s secret directly
sourcepub fn read_from_config() -> Result<Self, CryptrError>
 
pub fn read_from_config() -> Result<Self, CryptrError>
Reads the keys from the default config
Available with feature cli only
sourcepub fn read_from_file(path: &str) -> Result<Self, CryptrError>
 
pub fn read_from_file(path: &str) -> Result<Self, CryptrError>
Reads the keys from a given file location on disk
sourcepub fn from_env() -> Result<Self, CryptrError>
 
pub fn from_env() -> Result<Self, CryptrError>
Builds the keys from environment variables
Expects 2 values:
ENC_KEY_ACTIVEwhich indicates the active, default keyENC_KEYSwith the available keys in the korrect format, for instance:
ENC_KEYS="
z8ycdOXnOv7E/nxOhIuLo1oiQBpcg6lYz2Jkc3TgAYoD7h4+orRdlYAk=
test1337/HQyncjvJUNLTv2YvoTWeVmMKQLBe7+xVSHMXUVES8qE=
"
pub fn keys_as_b64(&self) -> Result<String, CryptrError>
pub async fn save_to_file(&self, file: &str) -> Result<(), CryptrError>
pub async fn save_to_file_with_path( &self, path: &str, file_name: &str ) -> Result<(), CryptrError>
sourcepub fn get_key(&self, enc_key_id: &str) -> Result<&[u8], CryptrError>
 
pub fn get_key(&self, enc_key_id: &str) -> Result<&[u8], CryptrError>
Returns a reference to specified EncKey
sourcepub fn get_static<'a>() -> &'a Self
 
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()
sourcepub fn get_static_key<'a>(enc_key_id: &str) -> Result<&'a [u8], CryptrError>
 
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.
sourcepub fn get_key_active<'a>() -> Result<&'a [u8], CryptrError>
 
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.
sourcepub fn init(self) -> Result<(), CryptrError>
 
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.
sourcepub fn generate() -> Result<Self, CryptrError>
 
pub fn generate() -> Result<Self, CryptrError>
Generates a new random encryption key
sourcepub fn generate_multiple(number_of_keys: u16) -> Result<Self, CryptrError>
 
pub fn generate_multiple(number_of_keys: u16) -> Result<Self, CryptrError>
Generates a new random set of encryption keys
sourcepub fn generate_with_id(id: String) -> Result<Self, CryptrError>
 
pub fn generate_with_id(id: String) -> Result<Self, CryptrError>
Generates a new random encryption key with a specific ID
sourcepub fn try_convert_legacy_keys(keys: &str) -> Result<String, CryptrError>
 
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