#[cfg(feature = "key-load")]
#[macro_use]
extern crate log;
mod error;
#[cfg(feature = "hash")]
#[cfg_attr(docsrs, doc(cfg(feature = "hash")))]
pub mod hash;
mod hex;
#[cfg(feature = "jwt")]
#[cfg_attr(docsrs, doc(cfg(feature = "jwt")))]
pub mod jwt;
mod key;
pub mod secp256k1;
mod signature;
#[cfg(feature = "key-load")]
pub use error::KeyLoadError;
pub use error::{ContextError, SignatureParseError, SigningError, VerificationError};
#[cfg(feature = "key-load")]
pub use key::load::current_user_key_name;
#[cfg(feature = "key-load")]
pub use key::load::current_user_search_path;
#[cfg(feature = "key-load")]
pub use key::load::load_key;
#[cfg(feature = "key-load")]
pub use key::load::load_key_from_path;
pub use key::{KeyParseError, PrivateKey, PublicKey};
pub use signature::Signature;
pub trait Signer: Send {
fn algorithm_name(&self) -> &str;
fn sign(&self, message: &[u8]) -> Result<Signature, SigningError>;
fn public_key(&self) -> Result<PublicKey, SigningError>;
fn clone_box(&self) -> Box<dyn Signer>;
}
impl Clone for Box<dyn Signer> {
fn clone(&self) -> Self {
self.clone_box()
}
}
pub trait Verifier: Send {
fn algorithm_name(&self) -> &str;
fn verify(
&self,
message: &[u8],
signature: &Signature,
public_key: &PublicKey,
) -> Result<bool, VerificationError>;
}
pub trait VerifierFactory: Send {
fn new_verifier(&self) -> Box<dyn Verifier>;
}
pub trait Context: Send {
fn algorithm_name(&self) -> &str;
fn new_signer(&self, key: PrivateKey) -> Box<dyn Signer>;
fn new_verifier(&self) -> Box<dyn Verifier>;
fn new_random_private_key(&self) -> PrivateKey;
fn get_public_key(&self, private_key: &PrivateKey) -> Result<PublicKey, ContextError>;
}
impl<T: Context> VerifierFactory for T {
fn new_verifier(&self) -> Box<dyn Verifier> {
Context::new_verifier(self)
}
}