From ddbde37e21452ebe7997636abdf94e2f4654e5f5 Mon Sep 17 00:00:00 2001 From: Shun Sakai Date: Sun, 4 Aug 2024 11:29:19 +0900 Subject: [PATCH] refactor: Change type of `--passphrase-from-env` Change it to take an UTF-8 string as an environment variable key. --- crates/cli/CHANGELOG.adoc | 7 +++++++ crates/cli/src/cli.rs | 5 ++--- crates/cli/src/passphrase.rs | 3 +-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/crates/cli/CHANGELOG.adoc b/crates/cli/CHANGELOG.adoc index db31257..e3785e5 100644 --- a/crates/cli/CHANGELOG.adoc +++ b/crates/cli/CHANGELOG.adoc @@ -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 diff --git a/crates/cli/src/cli.rs b/crates/cli/src/cli.rs index 7b9fade..bd04b53 100644 --- a/crates/cli/src/cli.rs +++ b/crates/cli/src/cli.rs @@ -3,7 +3,6 @@ // SPDX-License-Identifier: GPL-3.0-or-later use std::{ - ffi::OsString, fmt, io::{self, Write}, ops::Deref, @@ -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, + pub passphrase_from_env: Option, /// Read the passphrase from the file. /// @@ -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, + pub passphrase_from_env: Option, /// Read the passphrase from the file. /// diff --git a/crates/cli/src/passphrase.rs b/crates/cli/src/passphrase.rs index 22f20b9..f9b09be 100644 --- a/crates/cli/src/passphrase.rs +++ b/crates/cli/src/passphrase.rs @@ -4,7 +4,6 @@ use std::{ env, - ffi::OsStr, fs::File, io::{self, BufRead, BufReader}, path::Path, @@ -45,7 +44,7 @@ pub fn read_passphrase_from_tty_once() -> anyhow::Result { } /// Reads the passphrase from the environment variable. -pub fn read_passphrase_from_env(key: &OsStr) -> anyhow::Result { +pub fn read_passphrase_from_env(key: &str) -> anyhow::Result { env::var(key).context("could not read passphrase from environment variable") }