Provide `sha256` as a primitive in Starlark
shs96c opened this issue · 2 comments
Many uses of Starlark require hashes in order to verify inputs are correct (examples include things like the sha56
attribute of http_archive
in Bazel). It would be very beneficial if Starlark offered a function to allow hashes to be calculated.
The simplest way to do this would be a sha256
primitive, but an alternative design may be to modify hash
to include an optional algorithm
parameter, allowing for a path towards extending the hashing in a stable way (eg. to offer Blake3 or similar support)
buck2 has sha256
builtin. Bazel may have it too, and I think this is actually a feature request for Bazel, not for starlark spec?
This function may be not generic enough to be included in the language specification. For example, in buck2 sha256
returns hex string. But maybe someone else needs digest as bytes? Or someone may want to have stateful sha256 algorithm to update it with chunks. Or someone would want sha1 and sha3? Starlark standard library is very small, and this would be quite large addition.