mirror of
https://github.com/chatmail/core.git
synced 2026-05-01 20:36:31 +03:00
feat: do not load more than one own key
This commit is contained in:
24
src/key.rs
24
src/key.rs
@@ -156,24 +156,14 @@ pub(crate) async fn load_self_public_key(context: &Context) -> Result<SignedPubl
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns our own public keyring.
|
/// Returns our own public keyring.
|
||||||
|
///
|
||||||
|
/// No keys are generated and at most one key is returned.
|
||||||
pub(crate) async fn load_self_public_keyring(context: &Context) -> Result<Vec<SignedPublicKey>> {
|
pub(crate) async fn load_self_public_keyring(context: &Context) -> Result<Vec<SignedPublicKey>> {
|
||||||
let keys = context
|
if let Some(public_key) = load_self_public_key_opt(context).await? {
|
||||||
.sql
|
Ok(vec![public_key])
|
||||||
.query_map_vec(
|
} else {
|
||||||
r#"SELECT public_key
|
Ok(vec![])
|
||||||
FROM keypairs
|
}
|
||||||
ORDER BY id=(SELECT value FROM config WHERE keyname='key_id') DESC"#,
|
|
||||||
(),
|
|
||||||
|row| {
|
|
||||||
let public_key_bytes: Vec<u8> = row.get(0)?;
|
|
||||||
Ok(public_key_bytes)
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.await?
|
|
||||||
.into_iter()
|
|
||||||
.filter_map(|bytes| SignedPublicKey::from_slice(&bytes).log_err(context).ok())
|
|
||||||
.collect();
|
|
||||||
Ok(keys)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns own public key fingerprint in (not human-readable) hex representation.
|
/// Returns own public key fingerprint in (not human-readable) hex representation.
|
||||||
|
|||||||
Reference in New Issue
Block a user