Skip to content

Commit f51d495

Browse files
committed
signature: add Keypair trait
Adds a trait for types which represent a combination of both a signing key and verifying key as is common in many digital signature systems. The `Keypair` name follows Rust standard capitalization rules for the closed compound word "keypair" as commonly used in cryptography.
1 parent 54d32dc commit f51d495

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

signature/src/keypair.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//! Signing keypairs.
2+
3+
use crate::{Signature, Signer, Verifier};
4+
5+
/// Signing keypair with an associated verifying key.
6+
///
7+
/// This represents a type which holds both a signing key and a verifying key.
8+
pub trait Keypair<S: Signature>: AsRef<Self::VerifyingKey> + Signer<S> {
9+
/// Verifying key type for this keypair.
10+
type VerifyingKey: Verifier<S>;
11+
12+
/// Get the verifying key which can verify signatures produced by the
13+
/// signing key portion of this keypair.
14+
fn verifying_key(&self) -> &Self::VerifyingKey {
15+
self.as_ref()
16+
}
17+
}

signature/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,9 @@ pub use digest;
176176
pub use rand_core;
177177

178178
mod error;
179+
mod keypair;
179180
mod signature;
180181
mod signer;
181182
mod verifier;
182183

183-
pub use crate::{error::*, signature::*, signer::*, verifier::*};
184+
pub use crate::{error::*, keypair::*, signature::*, signer::*, verifier::*};

0 commit comments

Comments
 (0)