mirror of
https://github.com/chatmail/core.git
synced 2026-05-22 16:26:31 +03:00
refactor: use KeyPair::new() in create_keypair()
This commit is contained in:
19
src/pgp.rs
19
src/pgp.rs
@@ -14,9 +14,7 @@ use pgp::composed::{
|
|||||||
use pgp::crypto::ecc_curve::ECCCurve;
|
use pgp::crypto::ecc_curve::ECCCurve;
|
||||||
use pgp::crypto::hash::HashAlgorithm;
|
use pgp::crypto::hash::HashAlgorithm;
|
||||||
use pgp::crypto::sym::SymmetricKeyAlgorithm;
|
use pgp::crypto::sym::SymmetricKeyAlgorithm;
|
||||||
use pgp::types::{
|
use pgp::types::{CompressionAlgorithm, KeyTrait, Mpi, PublicKeyTrait, StringToKey};
|
||||||
CompressionAlgorithm, KeyTrait, Mpi, PublicKeyTrait, SecretKeyTrait, StringToKey,
|
|
||||||
};
|
|
||||||
use rand::{thread_rng, CryptoRng, Rng};
|
use rand::{thread_rng, CryptoRng, Rng};
|
||||||
use tokio::runtime::Handle;
|
use tokio::runtime::Handle;
|
||||||
|
|
||||||
@@ -142,7 +140,6 @@ pub struct KeyPair {
|
|||||||
pub secret: SignedSecretKey,
|
pub secret: SignedSecretKey,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
impl KeyPair {
|
impl KeyPair {
|
||||||
/// Creates new keypair from a secret key.
|
/// Creates new keypair from a secret key.
|
||||||
///
|
///
|
||||||
@@ -211,18 +208,12 @@ pub(crate) fn create_keypair(addr: EmailAddress, keygen_type: KeyGenType) -> Res
|
|||||||
.verify()
|
.verify()
|
||||||
.context("invalid secret key generated")?;
|
.context("invalid secret key generated")?;
|
||||||
|
|
||||||
let public_key = secret_key
|
let key_pair = KeyPair::new(secret_key)?;
|
||||||
.public_key()
|
key_pair
|
||||||
.sign(&secret_key, || "".into())
|
.public
|
||||||
.context("failed to sign public key")?;
|
|
||||||
public_key
|
|
||||||
.verify()
|
.verify()
|
||||||
.context("invalid public key generated")?;
|
.context("invalid public key generated")?;
|
||||||
|
Ok(key_pair)
|
||||||
Ok(KeyPair {
|
|
||||||
public: public_key,
|
|
||||||
secret: secret_key,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Select public key or subkey to use for encryption.
|
/// Select public key or subkey to use for encryption.
|
||||||
|
|||||||
Reference in New Issue
Block a user