Skip to content

Commit

Permalink
Switch from Secret<String> to SecretString
Browse files Browse the repository at this point in the history
  • Loading branch information
matiaskorhonen committed Dec 6, 2024
1 parent 1486dc3 commit 5817739
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/encryption.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ use std::io::Write;

use age::armor::ArmoredWriter;
use age::armor::Format::AsciiArmor;
use age::secrecy::Secret;
use age::secrecy::SecretString;

/// Encrypt the data from the reader and PEM encode the ciphertext
pub fn encrypt_plaintext(
reader: &mut dyn std::io::BufRead,
passphrase: Secret<String>,
passphrase: SecretString,
) -> Result<(usize, String), Box<dyn std::error::Error>> {
debug!("Encrypting plaintext");

Expand Down Expand Up @@ -39,7 +39,7 @@ mod tests {
#[test]
fn test_armored_output() {
let mut input = b"some secrets" as &[u8];
let passphrase = Secret::new(String::from("snakeoil"));
let passphrase = SecretString::from("snakeoil".to_owned());
let result = encrypt_plaintext(&mut input, passphrase);

assert!(result.is_ok());
Expand Down
8 changes: 4 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::{
path::PathBuf,
};

use age::secrecy::{ExposeSecret, Secret, SecretString};
use age::secrecy::{ExposeSecret, SecretString};
use clap::Parser;
use printpdf::LineDashPattern;
use qrcode::types::QrError;
Expand Down Expand Up @@ -139,8 +139,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
}

/// Read a secret from the user
pub fn read_secret(prompt: &str) -> Result<Secret<String>, io::Error> {
let passphrase = prompt_password(format!("{}: ", prompt)).map(SecretString::new)?;
pub fn read_secret(prompt: &str) -> Result<SecretString, io::Error> {
let passphrase = prompt_password(format!("{}: ", prompt)).map(SecretString::from)?;

Check warning on line 143 in src/main.rs

View check run for this annotation

Codecov / codecov/patch

src/main.rs#L142-L143

Added lines #L142 - L143 were not covered by tests

if passphrase.expose_secret().is_empty() {
return Err(io::Error::new(
Expand All @@ -154,7 +154,7 @@ pub fn read_secret(prompt: &str) -> Result<Secret<String>, io::Error> {

/// Get the passphrase from an interactive prompt or from the PAPERAGE_PASSPHRASE
/// environment variable
fn get_passphrase() -> Result<Secret<String>, io::Error> {
fn get_passphrase() -> Result<SecretString, io::Error> {
let env_passphrase = env::var("PAPERAGE_PASSPHRASE");

if let Ok(value) = env_passphrase {
Expand Down

0 comments on commit 5817739

Please sign in to comment.