bazelbuild / starlark

Starlark Language
Apache License 2.0
2.44k stars 163 forks source link

Provide `sha256` as a primitive in Starlark #275

Open shs96c opened 5 months ago

shs96c commented 5 months ago

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)

stepancheg commented 5 months ago

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.