Skip to content

Commit

Permalink
refactor: Change type of --passphrase-from-env
Browse files Browse the repository at this point in the history
Change it to take an UTF-8 string as an environment variable key.
  • Loading branch information
sorairolake committed Aug 4, 2024
1 parent 7f319db commit ddbde37
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
7 changes: 7 additions & 0 deletions crates/cli/CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ All notable changes to this project will be documented in this file.
The format is based on https://keepachangelog.com/[Keep a Changelog], and this
project adheres to https://semver.org/[Semantic Versioning].

== {compare-url}/scryptenc-cli-v0.7.12\...HEAD[Unreleased]

=== Changed

* Change `--passphrase-from-env` to take an UTF-8 string as an environment
variable key ({pull-request-url}/407[#407])

== {compare-url}/scryptenc-cli-v0.7.11\...scryptenc-cli-v0.7.12[0.7.12] - 2024-04-17

=== Changed
Expand Down
5 changes: 2 additions & 3 deletions crates/cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// SPDX-License-Identifier: GPL-3.0-or-later

use std::{
ffi::OsString,
fmt,
io::{self, Write},
ops::Deref,
Expand Down Expand Up @@ -179,7 +178,7 @@ pub struct Encrypt {
/// Note that storing a passphrase in an environment variable can be a
/// security risk.
#[arg(long, value_name("VAR"), group("passphrase"))]
pub passphrase_from_env: Option<OsString>,
pub passphrase_from_env: Option<String>,

/// Read the passphrase from the file.
///
Expand Down Expand Up @@ -263,7 +262,7 @@ pub struct Decrypt {
/// Note that storing a passphrase in an environment variable can be a
/// security risk.
#[arg(long, value_name("VAR"), group("passphrase"))]
pub passphrase_from_env: Option<OsString>,
pub passphrase_from_env: Option<String>,

/// Read the passphrase from the file.
///
Expand Down
3 changes: 1 addition & 2 deletions crates/cli/src/passphrase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use std::{
env,
ffi::OsStr,
fs::File,
io::{self, BufRead, BufReader},
path::Path,
Expand Down Expand Up @@ -45,7 +44,7 @@ pub fn read_passphrase_from_tty_once() -> anyhow::Result<String> {
}

/// Reads the passphrase from the environment variable.
pub fn read_passphrase_from_env(key: &OsStr) -> anyhow::Result<String> {
pub fn read_passphrase_from_env(key: &str) -> anyhow::Result<String> {
env::var(key).context("could not read passphrase from environment variable")
}

Expand Down

0 comments on commit ddbde37

Please sign in to comment.