Skip to main content

Crate uselesskey_rustcrypto

Crate uselesskey_rustcrypto 

Source
Expand description

Integration between uselesskey test fixtures and the RustCrypto ecosystem.

This crate provides extension traits that convert uselesskey fixtures into native RustCrypto types, making it easy to use test fixtures with code that depends on the RustCrypto crates directly.

§Features

Enable the key types you need:

  • rsa - RSA keypairs -> rsa::RsaPrivateKey / rsa::RsaPublicKey
  • ecdsa - ECDSA keypairs -> p256::ecdsa::SigningKey / p384::ecdsa::SigningKey
  • ed25519 - Ed25519 keypairs -> ed25519_dalek::SigningKey / VerifyingKey
  • hmac - HMAC secrets -> hmac::Hmac<Sha256> / Sha384 / Sha512
  • all - All of the above

§Example: RSA sign and verify

use uselesskey_core::Factory;
use uselesskey_rsa::{RsaFactoryExt, RsaSpec};
use uselesskey_rustcrypto::RustCryptoRsaExt;
use rsa::pkcs1v15::SigningKey;
use rsa::signature::{Signer, Verifier};
use rsa::sha2::Sha256;

let fx = Factory::random();
let keypair = fx.rsa("test", RsaSpec::rs256());

let private_key = keypair.rsa_private_key();
let signing_key = SigningKey::<Sha256>::new_unprefixed(private_key);
let signature = signing_key.sign(b"hello world");

let public_key = keypair.rsa_public_key();
let verifying_key = rsa::pkcs1v15::VerifyingKey::<Sha256>::new_unprefixed(public_key);
verifying_key.verify(b"hello world", &signature).unwrap();

Traits§

RustCryptoEcdsaExt
Extension trait to convert uselesskey ECDSA fixtures into RustCrypto p256/p384 types.
RustCryptoEd25519Ext
Extension trait to convert uselesskey Ed25519 fixtures into ed25519-dalek types.
RustCryptoHmacExt
Extension trait to convert uselesskey HMAC fixtures into hmac::Hmac types.
RustCryptoRsaExt
Extension trait to convert uselesskey RSA fixtures into RustCrypto rsa types.