summaryrefslogtreecommitdiff
path: root/cli/util/checksum.rs
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2022-11-28 17:28:54 -0500
committerGitHub <noreply@github.com>2022-11-28 17:28:54 -0500
commit2d4c46c975eb916dc622cc729a1a8d397582a76f (patch)
tree445e819117acd2f94ffc9d7da7ed8e3e604435d0 /cli/util/checksum.rs
parentf526513d74d34ac254aa40ef9b73238cb21c395b (diff)
refactor: create util folder, move nap_sym to napi/sym, move http_cache to cache folder (#16857)
Diffstat (limited to 'cli/util/checksum.rs')
-rw-r--r--cli/util/checksum.rs32
1 files changed, 32 insertions, 0 deletions
diff --git a/cli/util/checksum.rs b/cli/util/checksum.rs
new file mode 100644
index 000000000..c0e41356d
--- /dev/null
+++ b/cli/util/checksum.rs
@@ -0,0 +1,32 @@
+// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
+
+use ring::digest::Context;
+use ring::digest::SHA256;
+
+pub fn gen(v: &[impl AsRef<[u8]>]) -> String {
+ let mut ctx = Context::new(&SHA256);
+ for src in v {
+ ctx.update(src.as_ref());
+ }
+ let digest = ctx.finish();
+ let out: Vec<String> = digest
+ .as_ref()
+ .iter()
+ .map(|byte| format!("{:02x}", byte))
+ .collect();
+ out.join("")
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn test_gen() {
+ let actual = gen(&[b"hello world"]);
+ assert_eq!(
+ actual,
+ "b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9"
+ );
+ }
+}