Skip to content

Commit

Permalink
build(deps): ⬆️ update to rpgp v0.14.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Jisu-Woniu committed Oct 8, 2024
1 parent 311421b commit 75f815f
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 28 deletions.
105 changes: 97 additions & 8 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src-tauri/crypto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ async-trait = "0.1.83"
chrono = "0.4.38"
futures = "0.3.31"
hex = "0.4.3"
pgp = "0.13.2"
pgp = "0.14.0"
rand = "0.8.5"
serde = { version = "1.0.210", features = ["derive"] }
smallvec = "1.13.2"
thiserror = "1.0.64"
Expand Down
9 changes: 5 additions & 4 deletions src-tauri/crypto/src/key_pair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use pgp::{
types::{CompressionAlgorithm, SecretKeyTrait as _},
KeyType, SecretKeyParamsBuilder, SignedPublicKey, SignedSecretKey,
};
use rand::thread_rng;
use smallvec::smallvec;

use crate::Result;
Expand All @@ -24,7 +25,7 @@ impl KeyPair {
) -> Result<Self> {
let secret_key = SecretKeyParamsBuilder::default()
// Set keygen params.
.key_type(KeyType::EdDSA)
.key_type(KeyType::Ed25519)
.primary_user_id(format!("{} <{}>", name, email))
.preferred_symmetric_algorithms(smallvec![
SymmetricKeyAlgorithm::AES256,
Expand All @@ -47,10 +48,10 @@ impl KeyPair {
.can_sign(true)
.build()
.expect("msg")
.generate()?;
let signed_secret_key = secret_key.sign(passwd_fn.clone())?;
.generate(thread_rng())?;
let signed_secret_key = secret_key.sign(thread_rng(), passwd_fn.clone())?;
let public_key = signed_secret_key.public_key();
let signed_public_key = public_key.sign(&signed_secret_key, passwd_fn)?;
let signed_public_key = public_key.sign(thread_rng(), &signed_secret_key, passwd_fn)?;

Ok(KeyPair::from_keys(signed_secret_key, signed_public_key))
}
Expand Down
4 changes: 2 additions & 2 deletions src-tauri/crypto/src/keygen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use std::path::{Path, PathBuf};

use futures::future::try_join;
use pgp::{types::KeyTrait, ArmorOptions};
use pgp::{types::PublicKeyTrait as _, ArmorOptions};
use serde::Serialize;
use tokio::fs::{write, DirBuilder};
use zeroize::Zeroizing;
Expand Down Expand Up @@ -71,7 +71,7 @@ where
#[cfg(test)]
mod tests {

use pgp::{types::KeyTrait, ArmorOptions, SignedSecretKey};
use pgp::{types::PublicKeyTrait as _, ArmorOptions, SignedSecretKey};

use crate::{from_file::FromFile, key_pair::KeyPair, Result};

Expand Down
26 changes: 13 additions & 13 deletions src-tauri/crypto/src/signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{

use chrono::Utc;
use pgp::{
packet::{self, SignatureConfigBuilder, SignatureType, Subpacket, SubpacketData},
packet::{self, SignatureConfig, SignatureType, Subpacket, SubpacketData},
types::SecretKeyTrait,
Signature, SignedPublicKey, SignedSecretKey,
};
Expand All @@ -22,18 +22,18 @@ fn sign(
passwd_fn: impl FnOnce() -> String + Clone,
) -> Result<Signature> {
let now = Utc::now();
let sig_conf = SignatureConfigBuilder::default()
.pub_alg(secret_key.algorithm())
.hash_alg(secret_key.hash_alg())
.typ(SignatureType::Binary)
.issuer(Some(secret_key.key_id()))
.created(Some(now))
.hashed_subpackets(vec![
Subpacket::regular(SubpacketData::SignatureCreationTime(now)),
Subpacket::regular(SubpacketData::Issuer(secret_key.key_id())),
])
.unhashed_subpackets(vec![])
.build()?;

let mut sig_conf = SignatureConfig::v4(
SignatureType::Binary,
secret_key.algorithm(),
secret_key.hash_alg(),
);

sig_conf.hashed_subpackets = vec![
Subpacket::regular(SubpacketData::SignatureCreationTime(now)),
Subpacket::regular(SubpacketData::Issuer(secret_key.key_id())),
];

Ok(sig_conf.sign(secret_key, passwd_fn, data)?)
}

Expand Down

0 comments on commit 75f815f

Please sign in to comment.