Browse Source

Add the standalone hash implementation

pull/5/head
Rodolphe Breard 6 years ago
parent
commit
147370caa2
  1. 3
      acme_common/Cargo.toml
  2. 10
      acme_common/src/crypto.rs
  3. 5
      acme_common/src/crypto/standalone_hash.rs

3
acme_common/Cargo.toml

@ -13,7 +13,7 @@ name = "acme_common"
[features] [features]
default = ["openssl"] default = ["openssl"]
standalone = []
standalone = ["ring"]
[dependencies] [dependencies]
base64 = "0.10" base64 = "0.10"
@ -23,6 +23,7 @@ handlebars = "2.0.0-beta.2"
http_req = "0.5" http_req = "0.5"
log = "0.4" log = "0.4"
openssl = { version = "0.10", optional = true } openssl = { version = "0.10", optional = true }
ring = { version = "0.14", optional = true }
serde_json = "1.0" serde_json = "1.0"
syslog = "4.0" syslog = "4.0"
time = "0.1" time = "0.1"

10
acme_common/src/crypto.rs

@ -1,9 +1,19 @@
mod openssl_certificate; mod openssl_certificate;
#[cfg(not(feature = "standalone"))]
mod openssl_hash; mod openssl_hash;
#[cfg(feature = "standalone")]
mod standalone_hash;
mod openssl_keys; mod openssl_keys;
pub const DEFAULT_ALGO: &str = "rsa2048"; pub const DEFAULT_ALGO: &str = "rsa2048";
pub use openssl_certificate::{Csr, X509Certificate}; pub use openssl_certificate::{Csr, X509Certificate};
#[cfg(not(feature = "standalone"))]
pub use openssl_hash::sha256; pub use openssl_hash::sha256;
#[cfg(feature = "standalone")]
pub use standalone_hash::sha256;
pub use openssl_keys::{gen_keypair, KeyType, PrivateKey, PublicKey}; pub use openssl_keys::{gen_keypair, KeyType, PrivateKey, PublicKey};

5
acme_common/src/crypto/standalone_hash.rs

@ -0,0 +1,5 @@
use ring::digest::{digest, SHA256};
pub fn sha256(data: &[u8]) -> Vec<u8> {
digest(&SHA256, data).as_ref().to_vec()
}
Loading…
Cancel
Save