Don't show hint if a recipient is listed in encrypt.for-self.
- Fixes #471.
This commit is contained in:
parent
dfc36e38d8
commit
04615bc768
@ -320,7 +320,9 @@ pub fn encrypt<'a, 'b: 'a>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ! have_one_secret && passwords.is_empty() {
|
if ! have_one_secret && passwords.is_empty() && ! recipients.iter()
|
||||||
|
.any(|c| sq.config.encrypt_for_self().contains(&c.fingerprint()))
|
||||||
|
{
|
||||||
sq.hint(format_args!(
|
sq.hint(format_args!(
|
||||||
"It looks like you won't be able to decrypt the message. \
|
"It looks like you won't be able to decrypt the message. \
|
||||||
Consider adding yourself as recipient, for example by \
|
Consider adding yourself as recipient, for example by \
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
//! Configuration model and file parsing.
|
//! Configuration model and file parsing.
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
collections::HashSet,
|
collections::{BTreeSet, HashSet},
|
||||||
fs,
|
fs,
|
||||||
io,
|
io,
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
@ -39,7 +39,7 @@ use crate::{
|
|||||||
/// It is available as `Sq::config`, with suitable accessors that
|
/// It is available as `Sq::config`, with suitable accessors that
|
||||||
/// handle the precedence of the various sources.
|
/// handle the precedence of the various sources.
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
encrypt_for_self: Vec<Fingerprint>,
|
encrypt_for_self: BTreeSet<Fingerprint>,
|
||||||
policy_path: Option<PathBuf>,
|
policy_path: Option<PathBuf>,
|
||||||
policy_inline: Option<Vec<u8>>,
|
policy_inline: Option<Vec<u8>>,
|
||||||
cipher_suite: Option<sequoia_openpgp::cert::CipherSuite>,
|
cipher_suite: Option<sequoia_openpgp::cert::CipherSuite>,
|
||||||
@ -49,7 +49,7 @@ pub struct Config {
|
|||||||
impl Default for Config {
|
impl Default for Config {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Config {
|
Config {
|
||||||
encrypt_for_self: vec![],
|
encrypt_for_self: Default::default(),
|
||||||
policy_path: None,
|
policy_path: None,
|
||||||
policy_inline: None,
|
policy_inline: None,
|
||||||
cipher_suite: None,
|
cipher_suite: None,
|
||||||
@ -61,7 +61,7 @@ impl Default for Config {
|
|||||||
impl Config {
|
impl Config {
|
||||||
/// Returns the certificates that should be added to the list of
|
/// Returns the certificates that should be added to the list of
|
||||||
/// recipients if `encrypt --for-self` is given.
|
/// recipients if `encrypt --for-self` is given.
|
||||||
pub fn encrypt_for_self(&self) -> &[Fingerprint] {
|
pub fn encrypt_for_self(&self) -> &BTreeSet<Fingerprint> {
|
||||||
&self.encrypt_for_self
|
&self.encrypt_for_self
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -571,14 +571,14 @@ fn apply_encrypt_for_self(config: &mut Option<&mut Config>,
|
|||||||
.ok_or_else(|| Error::bad_item_type(path, item, "array"))?;
|
.ok_or_else(|| Error::bad_item_type(path, item, "array"))?;
|
||||||
|
|
||||||
let mut strs = Vec::new();
|
let mut strs = Vec::new();
|
||||||
let mut values = Vec::new();
|
let mut values = BTreeSet::default();
|
||||||
for (i, server) in list.iter().enumerate() {
|
for (i, server) in list.iter().enumerate() {
|
||||||
let s = server.as_str()
|
let s = server.as_str()
|
||||||
.ok_or_else(|| Error::bad_value_type(&format!("{}.{}", path, i),
|
.ok_or_else(|| Error::bad_value_type(&format!("{}.{}", path, i),
|
||||||
server, "string"))?;
|
server, "string"))?;
|
||||||
|
|
||||||
strs.push(s);
|
strs.push(s);
|
||||||
values.push(s.parse::<Fingerprint>()?);
|
values.insert(s.parse::<Fingerprint>()?);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(cli) = cli {
|
if let Some(cli) = cli {
|
||||||
|
Loading…
Reference in New Issue
Block a user