Skip to content

Commit

Permalink
refactor: rename min_verified into verified
Browse files Browse the repository at this point in the history
  • Loading branch information
link2xt committed Nov 30, 2023
1 parent 5d08b2c commit 1c9662a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
6 changes: 3 additions & 3 deletions src/e2ee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl EncryptHelper {
pub async fn encrypt(
self,
context: &Context,
min_verified: bool,
verified: bool,
mail_to_encrypt: lettre_email::PartBuilder,
peerstates: Vec<(Option<Peerstate>, &str)>,
) -> Result<String> {
Expand All @@ -107,7 +107,7 @@ impl EncryptHelper {
.filter_map(|(state, addr)| state.clone().map(|s| (s, addr)))
{
let key = peerstate
.take_key(min_verified)
.take_key(verified)
.with_context(|| format!("proper enc-key for {addr} missing, cannot encrypt"))?;
keyring.push(key);
verifier_addresses.push(addr);
Expand All @@ -118,7 +118,7 @@ impl EncryptHelper {

// Encrypt to secondary verified keys
// if we also encrypt to the introducer ("verifier") of the key.
if min_verified {
if verified {
for (peerstate, _addr) in peerstates {
if let Some(peerstate) = peerstate {
if let (Some(key), Some(verifier)) = (
Expand Down
8 changes: 4 additions & 4 deletions src/mimefactory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ impl<'a> MimeFactory<'a> {
}
}

fn min_verified(&self) -> bool {
fn verified(&self) -> bool {
match &self.loaded {
Loaded::Message { chat } => {
if chat.is_protected() {
Expand Down Expand Up @@ -627,7 +627,7 @@ impl<'a> MimeFactory<'a> {
));
}

let min_verified = self.min_verified();
let verified = self.verified();
let grpimage = self.grpimage();
let force_plaintext = self.should_force_plaintext();
let skip_autocrypt = self.should_skip_autocrypt();
Expand Down Expand Up @@ -723,7 +723,7 @@ impl<'a> MimeFactory<'a> {
&& self.should_do_gossip(context).await?
{
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));
is_gossiped = true;
}
Expand Down Expand Up @@ -756,7 +756,7 @@ impl<'a> MimeFactory<'a> {
}

let encrypted = encrypt_helper
.encrypt(context, min_verified, message, peerstates)
.encrypt(context, verified, message, peerstates)
.await?;

outer_message
Expand Down
18 changes: 9 additions & 9 deletions src/peerstate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,8 @@ impl Peerstate {
}

/// Returns the contents of the `Autocrypt-Gossip` header for outgoing messages.
pub fn render_gossip_header(&self, min_verified: bool) -> Option<String> {
if let Some(key) = self.peek_key(min_verified) {
pub fn render_gossip_header(&self, verified: bool) -> Option<String> {
if let Some(key) = self.peek_key(verified) {
let header = Aheader::new(
self.addr.clone(),
key.clone(), // TODO: avoid cloning
Expand All @@ -386,8 +386,8 @@ impl Peerstate {
/// Converts the peerstate into the contact public 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> {
if min_verified {
pub fn take_key(mut self, verified: bool) -> Option<SignedPublicKey> {
if verified {
self.verified_key.take()
} else {
self.public_key.take().or_else(|| self.gossip_key.take())
Expand All @@ -396,15 +396,15 @@ impl Peerstate {

/// 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,
/// otherwise returns the Autocrypt key.
///
/// Returned key is suitable for sending in `Autocrypt-Gossip` header.
///
/// Returns `None` if there is no suitable public key.
pub fn peek_key(&self, min_verified: bool) -> Option<&SignedPublicKey> {
if min_verified {
pub fn peek_key(&self, verified: bool) -> Option<&SignedPublicKey> {
if verified {
self.verified_key.as_ref()
} else {
self.public_key.as_ref().or(self.gossip_key.as_ref())
Expand All @@ -414,8 +414,8 @@ impl Peerstate {
/// Returns a reference to the contact's public key fingerprint.
///
/// Similar to [`Self::peek_key`], but returns the fingerprint instead of the key.
fn peek_key_fingerprint(&self, min_verified: bool) -> Option<&Fingerprint> {
if min_verified {
fn peek_key_fingerprint(&self, verified: bool) -> Option<&Fingerprint> {
if verified {
self.verified_key_fingerprint.as_ref()
} else {
self.public_key_fingerprint
Expand Down

0 comments on commit 1c9662a

Please sign in to comment.