Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dsa: introduce serde #870

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Cargo.lock

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

9 changes: 9 additions & 0 deletions dsa/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ num-bigint = { package = "num-bigint-dig", version = "0.8", default-features = f
num-traits = { version = "0.2", default-features = false }
pkcs8 = { version = "=0.11.0-rc.1", default-features = false, features = ["alloc"] }
rfc6979 = { version = "=0.5.0-pre.4", path = "../rfc6979" }
serde = { version = "1.0", default-features = false, features = ["derive"], optional = true }
sha2 = { version = "=0.11.0-pre.4", default-features = false }
signature = { version = "=2.3.0-pre.4", default-features = false, features = ["alloc", "digest", "rand_core"] }
zeroize = { version = "1", default-features = false }
Expand All @@ -32,4 +33,12 @@ rand_chacha = "0.3"
sha1 = "=0.11.0-pre.4"

[features]
serde = [
"dep:serde",
"num-bigint/serde",
]
serde_secrets = [
"serde",
"zeroize/serde",
]
std = []
4 changes: 4 additions & 0 deletions dsa/src/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ use pkcs8::der::{
};
use signature::rand_core::CryptoRngCore;

#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

/// The common components of an DSA keypair
///
/// (the prime p, quotient q and generator g)
#[derive(Clone, Debug, PartialEq, PartialOrd)]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
#[must_use]
pub struct Components {
/// Prime p
Expand Down
4 changes: 4 additions & 0 deletions dsa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,12 @@ use pkcs8::der::{
};
use signature::SignatureEncoding;

#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

/// Container of the DSA signature
#[derive(Clone, Debug)]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
#[must_use]
pub struct Signature {
/// Signature part r
Expand Down
4 changes: 4 additions & 0 deletions dsa/src/signing_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,15 @@ use signature::{
};
use zeroize::{Zeroize, Zeroizing};

#[cfg(feature = "serde_secrets")]
use serde::{Deserialize, Serialize};

/// DSA private key.
///
/// The [`(try_)sign_digest_with_rng`](::signature::RandomizedDigestSigner) API uses regular non-deterministic signatures,
/// while the [`(try_)sign_digest`](::signature::DigestSigner) API uses deterministic signatures as described in RFC 6979
#[derive(Clone, PartialEq)]
#[cfg_attr(feature = "serde_secrets", derive(Deserialize, Serialize))]
#[must_use]
pub struct SigningKey {
/// Public key
Expand Down
4 changes: 4 additions & 0 deletions dsa/src/verifying_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ use pkcs8::{
};
use signature::{hazmat::PrehashVerifier, DigestVerifier, Verifier};

#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

/// DSA public key.
#[derive(Clone, Debug, PartialEq, PartialOrd)]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
#[must_use]
pub struct VerifyingKey {
/// common components
Expand Down
Loading