MCPcopy Create free account
hub / github.com/chatmail/core / try_decrypt_with_auth_token

Function try_decrypt_with_auth_token

src/decrypt.rs:202–219  ·  view source on GitHub ↗
(
    esk: &SymKeyEncryptedSessionKey,
    conn: &mut rusqlite::Connection,
    self_fingerprint: &str,
)

Source from the content-addressed store, hash-verified

200}
201
202fn try_decrypt_with_auth_token(
203 esk: &SymKeyEncryptedSessionKey,
204 conn: &mut rusqlite::Connection,
205 self_fingerprint: &str,
206) -> Result<Option<PlainSessionKey>> {
207 // ORDER BY id DESC to query the most-recently saved tokens are returned first.
208 // This improves performance when Bob scans a QR code that was just created.
209 let mut stmt = conn.prepare("SELECT token FROM tokens WHERE namespc=? ORDER BY id DESC")?;
210 let mut rows = stmt.query((Namespace::Auth,))?;
211 while let Some(row) = rows.next()? {
212 let token: String = row.get(0)?;
213 let shared_secret = format!("securejoin/{self_fingerprint}/{token}");
214 if let Ok(psk) = decrypt_session_key_with_password(esk, &Password::from(shared_secret)) {
215 return Ok(Some(psk));
216 }
217 }
218 Ok(None)
219}
220
221/// Returns Ok(()) if we want to try symmetrically decrypting the message,
222/// and Err with a reason if symmetric decryption should not be tried.

Callers 1

Calls 3

prepareMethod · 0.45
nextMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected