refactor: rename min_verified into verified

This commit is contained in:
link2xt
2023-11-29 17:06:54 +00:00
parent 5d08b2ce33
commit 1c9662a8f2
3 changed files with 16 additions and 16 deletions

View File

@@ -94,7 +94,7 @@ impl EncryptHelper {
pub async fn encrypt( pub async fn encrypt(
self, self,
context: &Context, context: &Context,
min_verified: bool, verified: bool,
mail_to_encrypt: lettre_email::PartBuilder, mail_to_encrypt: lettre_email::PartBuilder,
peerstates: Vec<(Option<Peerstate>, &str)>, peerstates: Vec<(Option<Peerstate>, &str)>,
) -> Result<String> { ) -> Result<String> {
@@ -107,7 +107,7 @@ impl EncryptHelper {
.filter_map(|(state, addr)| state.clone().map(|s| (s, addr))) .filter_map(|(state, addr)| state.clone().map(|s| (s, addr)))
{ {
let key = peerstate let key = peerstate
.take_key(min_verified) .take_key(verified)
.with_context(|| format!("proper enc-key for {addr} missing, cannot encrypt"))?; .with_context(|| format!("proper enc-key for {addr} missing, cannot encrypt"))?;
keyring.push(key); keyring.push(key);
verifier_addresses.push(addr); verifier_addresses.push(addr);
@@ -118,7 +118,7 @@ impl EncryptHelper {
// Encrypt to secondary verified keys // Encrypt to secondary verified keys
// if we also encrypt to the introducer ("verifier") of the key. // if we also encrypt to the introducer ("verifier") of the key.
if min_verified { if verified {
for (peerstate, _addr) in peerstates { for (peerstate, _addr) in peerstates {
if let Some(peerstate) = peerstate { if let Some(peerstate) = peerstate {
if let (Some(key), Some(verifier)) = ( if let (Some(key), Some(verifier)) = (

View File

@@ -312,7 +312,7 @@ impl<'a> MimeFactory<'a> {
} }
} }
fn min_verified(&self) -> bool { fn verified(&self) -> bool {
match &self.loaded { match &self.loaded {
Loaded::Message { chat } => { Loaded::Message { chat } => {
if chat.is_protected() { if chat.is_protected() {
@@ -627,7 +627,7 @@ impl<'a> MimeFactory<'a> {
)); ));
} }
let min_verified = self.min_verified(); let verified = self.verified();
let grpimage = self.grpimage(); let grpimage = self.grpimage();
let force_plaintext = self.should_force_plaintext(); let force_plaintext = self.should_force_plaintext();
let skip_autocrypt = self.should_skip_autocrypt(); let skip_autocrypt = self.should_skip_autocrypt();
@@ -723,7 +723,7 @@ impl<'a> MimeFactory<'a> {
&& self.should_do_gossip(context).await? && self.should_do_gossip(context).await?
{ {
for peerstate in peerstates.iter().filter_map(|(state, _)| state.as_ref()) { for peerstate in peerstates.iter().filter_map(|(state, _)| state.as_ref()) {
if let Some(header) = peerstate.render_gossip_header(min_verified) { if let Some(header) = peerstate.render_gossip_header(verified) {
message = message.header(Header::new("Autocrypt-Gossip".into(), header)); message = message.header(Header::new("Autocrypt-Gossip".into(), header));
is_gossiped = true; is_gossiped = true;
} }
@@ -756,7 +756,7 @@ impl<'a> MimeFactory<'a> {
} }
let encrypted = encrypt_helper let encrypted = encrypt_helper
.encrypt(context, min_verified, message, peerstates) .encrypt(context, verified, message, peerstates)
.await?; .await?;
outer_message outer_message

View File

@@ -362,8 +362,8 @@ impl Peerstate {
} }
/// Returns the contents of the `Autocrypt-Gossip` header for outgoing messages. /// Returns the contents of the `Autocrypt-Gossip` header for outgoing messages.
pub fn render_gossip_header(&self, min_verified: bool) -> Option<String> { pub fn render_gossip_header(&self, verified: bool) -> Option<String> {
if let Some(key) = self.peek_key(min_verified) { if let Some(key) = self.peek_key(verified) {
let header = Aheader::new( let header = Aheader::new(
self.addr.clone(), self.addr.clone(),
key.clone(), // TODO: avoid cloning key.clone(), // TODO: avoid cloning
@@ -386,8 +386,8 @@ impl Peerstate {
/// Converts the peerstate into the contact public key. /// Converts the peerstate into the contact public key.
/// ///
/// Similar to [`Self::peek_key`], but consumes the peerstate and returns owned key. /// Similar to [`Self::peek_key`], but consumes the peerstate and returns owned key.
pub fn take_key(mut self, min_verified: bool) -> Option<SignedPublicKey> { pub fn take_key(mut self, verified: bool) -> Option<SignedPublicKey> {
if min_verified { if verified {
self.verified_key.take() self.verified_key.take()
} else { } else {
self.public_key.take().or_else(|| self.gossip_key.take()) self.public_key.take().or_else(|| self.gossip_key.take())
@@ -396,15 +396,15 @@ impl Peerstate {
/// Returns a reference to the contact public key. /// Returns a reference to the contact public key.
/// ///
/// `min_verified` determines the minimum required verification status of the key. /// `verified` determines the required verification status of the key.
/// If verified key is requested, returns the verified key, /// If verified key is requested, returns the verified key,
/// otherwise returns the Autocrypt key. /// otherwise returns the Autocrypt key.
/// ///
/// Returned key is suitable for sending in `Autocrypt-Gossip` header. /// Returned key is suitable for sending in `Autocrypt-Gossip` header.
/// ///
/// Returns `None` if there is no suitable public key. /// Returns `None` if there is no suitable public key.
pub fn peek_key(&self, min_verified: bool) -> Option<&SignedPublicKey> { pub fn peek_key(&self, verified: bool) -> Option<&SignedPublicKey> {
if min_verified { if verified {
self.verified_key.as_ref() self.verified_key.as_ref()
} else { } else {
self.public_key.as_ref().or(self.gossip_key.as_ref()) self.public_key.as_ref().or(self.gossip_key.as_ref())
@@ -414,8 +414,8 @@ impl Peerstate {
/// Returns a reference to the contact's public key fingerprint. /// Returns a reference to the contact's public key fingerprint.
/// ///
/// Similar to [`Self::peek_key`], but returns the fingerprint instead of the key. /// Similar to [`Self::peek_key`], but returns the fingerprint instead of the key.
fn peek_key_fingerprint(&self, min_verified: bool) -> Option<&Fingerprint> { fn peek_key_fingerprint(&self, verified: bool) -> Option<&Fingerprint> {
if min_verified { if verified {
self.verified_key_fingerprint.as_ref() self.verified_key_fingerprint.as_ref()
} else { } else {
self.public_key_fingerprint self.public_key_fingerprint