refactor: use KeyPair::new() in create_keypair()

This commit is contained in:
link2xt
2024-09-16 19:59:03 +00:00
parent f497e4dd12
commit f7a705c6da

View File

@@ -14,9 +14,7 @@ use pgp::composed::{
use pgp::crypto::ecc_curve::ECCCurve;
use pgp::crypto::hash::HashAlgorithm;
use pgp::crypto::sym::SymmetricKeyAlgorithm;
use pgp::types::{
CompressionAlgorithm, KeyTrait, Mpi, PublicKeyTrait, SecretKeyTrait, StringToKey,
};
use pgp::types::{CompressionAlgorithm, KeyTrait, Mpi, PublicKeyTrait, StringToKey};
use rand::{thread_rng, CryptoRng, Rng};
use tokio::runtime::Handle;
@@ -142,7 +140,6 @@ pub struct KeyPair {
pub secret: SignedSecretKey,
}
#[cfg(test)]
impl KeyPair {
/// Creates new keypair from a secret key.
///
@@ -211,18 +208,12 @@ pub(crate) fn create_keypair(addr: EmailAddress, keygen_type: KeyGenType) -> Res
.verify()
.context("invalid secret key generated")?;
let public_key = secret_key
.public_key()
.sign(&secret_key, || "".into())
.context("failed to sign public key")?;
public_key
let key_pair = KeyPair::new(secret_key)?;
key_pair
.public
.verify()
.context("invalid public key generated")?;
Ok(KeyPair {
public: public_key,
secret: secret_key,
})
Ok(key_pair)
}
/// Select public key or subkey to use for encryption.