diff --git a/Cargo.toml b/Cargo.toml index 53bc8b4..9e2c5d4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 "] @@ -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" diff --git a/build.rs b/build.rs deleted file mode 100644 index 6399463..0000000 --- a/build.rs +++ /dev/null @@ -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"); - } - } -} diff --git a/src/aes.rs b/src/aes.rs index b492d88..b006dea 100644 --- a/src/aes.rs +++ b/src/aes.rs @@ -38,8 +38,8 @@ pub struct AesKey { impl AesKey { - /// Generate a new random AES key and IV. - pub fn random() -> Result + /// Generate a new AES key and IV. + pub fn generate() -> Result { 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::generate() + } /// Create a new instance from a key and IV pub const fn new(key: [u8; KEYSIZE], iv: [u8; IVSIZE]) -> Self diff --git a/src/rsa/private.rs b/src/rsa/private.rs index 9c7f0e3..c3b0aea 100644 --- a/src/rsa/private.rs +++ b/src/rsa/private.rs @@ -60,6 +60,12 @@ pub struct RsaPrivateKey impl RsaPrivateKey { + /// Generate a new RSA private key + pub fn generate() -> Result + { + Ok(Rsa::generate(RSA_KEY_BITS)?.into()) + } + /// Create a new private key from its components pub fn new( n: impl Borrow, diff --git a/src/rsa/public.rs b/src/rsa/public.rs index da2073a..59084b9 100644 --- a/src/rsa/public.rs +++ b/src/rsa/public.rs @@ -56,6 +56,11 @@ pub struct RsaPublicKey impl RsaPublicKey { + /// Generate a new RSA public key (kinda useless, use `RsaPrivateKey::generate()`). + pub fn generate() -> Result + { + Ok(Rsa::generate(RSA_KEY_BITS)?.into()) + } /// Create a new RSAPublicKey from components pub fn new( n: impl Borrow,