Skip to content

Commit

Permalink
signature: add Keypair trait
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tarcieri committed Aug 13, 2022
1 parent 6af5706 commit a246755
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
17 changes: 17 additions & 0 deletions signature/src/keypair.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//! Signing keypairs.

use crate::{Signature, Signer, Verifier};

/// Signing keypair with an associated verifying key.
///
/// This represents a type which holds both a signing key and a verifying key.
pub trait Keypair<S: Signature>: AsRef<Self::VerifyingKey> + Signer<S> {
/// Verifying key type for this keypair.
type VerifyingKey: Verifier<S>;

/// Get the verifying key which can verify signatures produced by the
/// signing key portion of this keypair.
fn verifying_key(&self) -> &Self::VerifyingKey {
self.as_ref()
}
}
3 changes: 2 additions & 1 deletion signature/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,9 @@ pub use digest;
pub use rand_core;

mod error;
mod keypair;
mod signature;
mod signer;
mod verifier;

pub use crate::{error::*, signature::*, signer::*, verifier::*};
pub use crate::{error::*, keypair::*, signature::*, signer::*, verifier::*};

0 comments on commit a246755

Please sign in to comment.