diff --git a/acme_common/Cargo.toml b/acme_common/Cargo.toml index ed9e9e9..6d3c9e3 100644 --- a/acme_common/Cargo.toml +++ b/acme_common/Cargo.toml @@ -13,7 +13,7 @@ name = "acme_common" [features] default = ["openssl"] -standalone = [] +standalone = ["ring"] [dependencies] base64 = "0.10" @@ -23,6 +23,7 @@ handlebars = "2.0.0-beta.2" http_req = "0.5" log = "0.4" openssl = { version = "0.10", optional = true } +ring = { version = "0.14", optional = true } serde_json = "1.0" syslog = "4.0" time = "0.1" diff --git a/acme_common/src/crypto.rs b/acme_common/src/crypto.rs index 441cf6e..e5d4aa8 100644 --- a/acme_common/src/crypto.rs +++ b/acme_common/src/crypto.rs @@ -1,9 +1,19 @@ mod openssl_certificate; + +#[cfg(not(feature = "standalone"))] mod openssl_hash; +#[cfg(feature = "standalone")] +mod standalone_hash; + mod openssl_keys; pub const DEFAULT_ALGO: &str = "rsa2048"; pub use openssl_certificate::{Csr, X509Certificate}; + +#[cfg(not(feature = "standalone"))] pub use openssl_hash::sha256; +#[cfg(feature = "standalone")] +pub use standalone_hash::sha256; + pub use openssl_keys::{gen_keypair, KeyType, PrivateKey, PublicKey}; diff --git a/acme_common/src/crypto/standalone_hash.rs b/acme_common/src/crypto/standalone_hash.rs new file mode 100644 index 0000000..e52252f --- /dev/null +++ b/acme_common/src/crypto/standalone_hash.rs @@ -0,0 +1,5 @@ +use ring::digest::{digest, SHA256}; + +pub fn sha256(data: &[u8]) -> Vec { + digest(&SHA256, data).as_ref().to_vec() +}