Skip to content

Commit 777cdf5

Browse files
committed
feat: add std.sha512
1 parent 6639b02 commit 777cdf5

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

crates/jrsonnet-stdlib/src/hash.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,14 @@ pub fn builtin_md5(s: IStr) -> String {
55
format!("{:x}", md5::compute(s.as_bytes()))
66
}
77

8-
#[cfg(feature = "exp-more-hashes")]
98
#[builtin]
109
pub fn builtin_sha256(s: IStr) -> String {
1110
use sha2::digest::Digest;
12-
format!("{:?}", sha2::Sha256::digest(s.as_bytes()))
11+
format!("{:x}", sha2::Sha256::digest(s.as_bytes()))
12+
}
13+
14+
#[builtin]
15+
pub fn builtin_sha512(s: IStr) -> String {
16+
use sha2::digest::Digest;
17+
format!("{:x}", sha2::Sha512::digest(s.as_bytes()))
1318
}

crates/jrsonnet-stdlib/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ pub fn stdlib_uncached(settings: Rc<RefCell<Settings>>) -> ObjValue {
115115
// Hash
116116
("md5", builtin_md5::INST),
117117
("sha256", builtin_sha256::INST),
118+
("sha512", builtin_sha512::INST),
118119
// Encoding
119120
("encodeUTF8", builtin_encode_utf8::INST),
120121
("decodeUTF8", builtin_decode_utf8::INST),

0 commit comments

Comments
 (0)