Turbopack: add Rope.content_hash and SHA hashing (#90235)
We want `FileContent.content_hash()` to only hash the content bytes. This is also needed to produce the correct hashes [for SRI](https://developer.mozilla.org/en-US/docs/Web/Security/Defenses/Subresource_Integrity) However, the default `DeterministicHash` and `Hash` impls are ill-suited for that because they're a generic hashing infrastructure. Hashing only the content bytes isn't what you want actually, otherwise `hash(("a", "b", "c"))` would be the same as `hash("abc")` https://doc.rust-lang.org/std/hash/trait.Hasher.html#method.write_str describes this problem as well This is exactly what we want for Rope though, so this adds a `Rope.content_hash() -> impl DeterministicHash`. Additionally, this changes `content_hash` to accept a HashAlgorithm to prepare for sha SRI hashes. This required changing the return type to `RcStr`, because of the variable hash lengths. But the return value was always `encode_hex`d everywhere anyway.
Showing
File moved
File moved
File moved
File moved
File moved
File moved
File moved
Please
register
or
sign in
to comment