Skip to main content

save_encrypted_config

Function save_encrypted_config 

Source
pub fn save_encrypted_config(
    config: &SerializableConfig,
    passphrase: &str,
) -> Result<(), String>
Expand description

Saves the given configuration to an encrypted file using the provided passphrase.

Encrypts the config and writes it to both the primary file (secrets.enc) and a backup (backups/secrets.enc.backup). The backup directory is created automatically if it doesn’t exist. The backup is written first to ensure a valid copy exists even if the primary write fails.

§Arguments

  • config - The configuration to save.
  • passphrase - The passphrase used to encrypt the configuration.

§Returns

A Result indicating success or failure, with an error message as a String on failure.

§Errors

Returns an error if:

  • Serialization of the config fails
  • Encryption fails
  • The backups directory cannot be created
  • Either the backup or primary file cannot be written

§Example

let config = SerializableConfig { ... };
save_encrypted_config(&config, "my_secure_passphrase").expect("Failed to save encrypted config");