added RSA generate

tokio-1.0
Avril 4 years ago
parent fd37756272
commit 3cff2e90f1
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -1,6 +1,6 @@
[package]
name = "cryptohelpers"
version = "0.1.0"
version = "0.1.1"
license= "MIT"
description = "Collection of helpers and simplifying functions for cryptography things"
authors = ["Avril <flanchan@cumallover.me>"]
@ -36,6 +36,3 @@ password = ["sha256", "pbkdf2", "hex-literal", "hmac", "getrandom"]
aes = ["openssl", "getrandom"]
checksum = ["crc"]
rsa = ["openssl", "password"]
[build-dependencies]
rustc_version = "0.2"

@ -1,24 +0,0 @@
extern crate rustc_version;
use rustc_version::{version, version_meta, Channel};
fn main() {
// Assert we haven't travelled back in time
assert!(version().unwrap().major >= 1);
// Set cfg flags depending on release channel
match version_meta().unwrap().channel {
Channel::Stable => {
println!("cargo:rustc-cfg=stable");
}
Channel::Beta => {
println!("cargo:rustc-cfg=beta");
}
Channel::Nightly => {
println!("cargo:rustc-cfg=nightly");
}
Channel::Dev => {
println!("cargo:rustc-cfg=dev");
}
}
}

@ -38,8 +38,8 @@ pub struct AesKey {
impl AesKey
{
/// Generate a new random AES key and IV.
pub fn random() -> Result<Self, Error>
/// Generate a new AES key and IV.
pub fn generate() -> Result<Self, Error>
{
let mut this = Self::default();
@ -48,6 +48,14 @@ impl AesKey
Ok(this)
}
/// Generate a new random AES key and IV.
///
/// # Deprecated
/// Use `AesKey::generate()` instead.
#[deprecated] #[inline] pub fn random() -> Result<Self, Error>
{
Self::generate()
}
/// Create a new instance from a key and IV
pub const fn new(key: [u8; KEYSIZE], iv: [u8; IVSIZE]) -> Self

@ -60,6 +60,12 @@ pub struct RsaPrivateKey
impl RsaPrivateKey
{
/// Generate a new RSA private key
pub fn generate() -> Result<Self, Error>
{
Ok(Rsa::generate(RSA_KEY_BITS)?.into())
}
/// Create a new private key from its components
pub fn new(
n: impl Borrow<BigNumRef>,

@ -56,6 +56,11 @@ pub struct RsaPublicKey
impl RsaPublicKey
{
/// Generate a new RSA public key (kinda useless, use `RsaPrivateKey::generate()`).
pub fn generate() -> Result<Self, Error>
{
Ok(Rsa::generate(RSA_KEY_BITS)?.into())
}
/// Create a new RSAPublicKey from components
pub fn new(
n: impl Borrow<BigNumRef>,

Loading…
Cancel
Save