Skip to content

Commit

Permalink
dsa: derive serde
Browse files Browse the repository at this point in the history
  • Loading branch information
sivizius committed Oct 12, 2024
1 parent c0ab70c commit e98d4d7
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 0 deletions.
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.

6 changes: 6 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,9 @@ rand_chacha = "0.3"
sha1 = "=0.11.0-pre.4"

[features]
serde = [
"dep:serde",
"num-bigint/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")]
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", 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

0 comments on commit e98d4d7

Please sign in to comment.