Skip to main content

save_encrypted

Function save_encrypted 

Source
pub fn save_encrypted<T: Serialize>(
    value: &T,
    path: impl AsRef<Path>,
    format: Format,
    key: &str,
    encryptor: &dyn Encryptor,
) -> Result<(), Error>
Available on crate feature decrypt only.
Expand description

As save, encrypting the document before it reaches the disk.

The counterpart to reading a secrets.json.age. The encryptor is passed here rather than installed process-wide, because who may read this file is a decision about this write.

use dynamic_config::age::Recipients;

let recipients = Recipients::from_public_keys(["age1ql3z7..."])?;

dynamic_config::save_encrypted(
    &config,
    "secrets.json.age",
    dynamic_config::Format::Json,
    "db",
    &recipients,
)?;

§Errors

If value cannot be serialized, the format’s feature is off, encryption fails, or the file cannot be written.