Skip to content

Typed Digest, er, type - #3816

Open
itowlson wants to merge 2 commits into
spinframework:mainfrom
itowlson:digest-digest-digest-the-word-has-lost-all-meaning-digest-digest-digest
Open

itowlson wants to merge 2 commits into
spinframework:mainfrom
itowlson:digest-digest-digest-the-word-has-lost-all-meaning-digest-digest-digest

Conversation

@itowlson

@itowlson itowlson commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

This PR proposes a strong-typed (well, less weakly typed) Digest type, specifically for use at cache boundaries although this has knock-on effects in a bunch of places. The idea is that Digest values can be trusted to be, well, if not yer actual digests, at least predictable in their format. It also provides some type-level documentation to make it harder to mix digests up with strings representing descriptions, component IDs, etc.

(Why yes, yes I would like types for those other things too.)

I am not sure if this particular approach is right (in various ways e.g. naming, strictness, code location) but anyway putting it up to see how folks feel about such things.

Behaviourally this is almost a pure refactoring, except that some ill-formed digests will now raise errors.

Signed-off-by: itowlson <ivan.towlson@fermyon.com>
Signed-off-by: itowlson <ivan.towlson@fermyon.com>
@itowlson
itowlson force-pushed the digest-digest-digest-the-word-has-lost-all-meaning-digest-digest-digest branch from 3ed38ac to f64f4b6 Compare December 2, 2026 02:37
@itowlson

itowlson commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

While running unit tests, I found the spin-common Cargo.toml was missing some tokio features (which other crates helpfully supplied normally, but broke when tested in isolation). Bunged it into this PR but as a separate commit.

Comment on lines +7 to +8
/// A digest value in text form. The text may be a hex string
/// or may be prefixed with a scheme (e.g. `sha256:...`).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would strongly encourage storing only the prefixed form and using explicit methods to convert to/from unprefixed. I think most of the advantage of having a wrapper type like this comes from getting the same behavior out of it no matter where it was constructed.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants