Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion ndc_bin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,3 @@ rustyline.workspace = true
tap.workspace = true
termimad = "0.31.2"


6 changes: 5 additions & 1 deletion ndc_lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ serde_json.workspace = true
tap.workspace = true
thiserror.workspace = true

# Crypto
md5 = { version = "0.7.0", optional = true }
sha1 = { version = "0.10.6", optional = true }

[features]
default = ["ahash"]
default = ["ahash", "crypto"]
ahash = ["dep:ahash"]
crypto = ["dep:md5", "dep:sha1"]
5 changes: 5 additions & 0 deletions ndc_lib/src/stdlib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,14 @@ pub mod serde;
pub mod string;
pub mod value;

#[cfg(feature = "crypto")]
pub mod crypto;

pub fn register(env: &mut Environment) {
aoc::register(env);
cmp::register(env);
#[cfg(feature = "crypto")]
crypto::register(env);
deque::register(env);
file::register(env);
file::register_variadic(env);
Expand Down
20 changes: 20 additions & 0 deletions ndc_lib/src/stdlib/crypto.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use ndc_macros::export_module;

#[export_module]
mod internal {
use sha1::Digest;

/// Computes the md5 hash of an input string and returns it as an hex encoded string
pub fn md5(val: &str) -> String {
let digest = md5::compute(val);
format!("{:x}", digest)
}

/// Computes the sha1 hash of an input string and returns it as an hex encoded string
pub fn sha1(val: &str) -> String {
let mut hasher = sha1::Sha1::new();
hasher.update(val);
let digest = hasher.finalize();
format!("{:x}", digest)
}
}