0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-03-03 09:31:22 -05:00

refactor(cli/checksum): use map to generate hex string (#6382)

This commit is contained in:
Fallenhh 2020-06-19 23:03:33 +08:00 committed by GitHub
parent 5c8ce06c92
commit 1c5ab8bf1a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,15 +1,13 @@
use std::fmt::Write;
pub fn gen(v: Vec<&[u8]>) -> String {
let mut ctx = ring::digest::Context::new(&ring::digest::SHA256);
for src in v.iter() {
ctx.update(src);
}
let digest = ctx.finish();
let mut out = String::new();
// TODO There must be a better way to do this...
for byte in digest.as_ref() {
write!(&mut out, "{:02x}", byte).unwrap();
}
out
let out: Vec<String> = digest
.as_ref()
.iter()
.map(|byte| format!("{:02x}", byte))
.collect();
out.join("")
}