Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Digest and SHA256Digest #202

Merged
merged 1 commit into from
Aug 30, 2024
Merged

Conversation

cgwalters
Copy link
Contributor

@cgwalters cgwalters commented Aug 27, 2024

This addresses #201
add starts parsing digests in a stricter way. We now reject
malformed digests (notably including ones with / which is my
biggest concern) making them always safe to use as a file name.

For example in some cases (e.g. ocidir-rs) I want to write a descriptor
to the filesystem, and I don't want any possibility of path traversal
attacks from someone including a / in a descriptor.

We also add accessors to retrieve strictly validated SHA-256
as that's really the only important case (while still supporting
other generic digests).

Signed-off-by: Colin Walters [email protected]

Comment on lines 22 to 84
/// A parsed pair of algorithm:digest as defined
/// by <https://github.com/opencontainers/image-spec/blob/main/descriptor.md#digests>
pub struct Digest<'a> {
/// The algorithm name (e.g. sha256, sha512)
pub algorithm: &'a str,
/// The algorithm component (lowercase hexadecimal)
pub value: &'a str,
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to use derive in the same way as for other structures within this crate? Like the getters?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it makes total sense to only expose a getter to disallow (accidental) mutation of the values to become invalid states (though, IMO, you'd rather have to work to make that accident happen; I don't know what a programmer would be thinking to end up with &mut Digest).

I battled the getset crate for a bit and I couldn't figure out how to convince it not to add an extra & reference on the getter, so I ended up just doing getters manually. (And dropped the pub from the values).

@cgwalters cgwalters force-pushed the add-digest-type branch 2 times, most recently from 28a5807 to 90c017a Compare August 29, 2024 19:57
This addresses youki-dev#201
add starts parsing digests in a stricter way. We now reject
malformed digests (notably including ones with `/` which is my
biggest concern) making them always safe to use as a file name.

For example in some cases (e.g. ocidir-rs) I want to write a descriptor
to the filesystem, and I don't want any possibility of path traversal
attacks from someone including a `/` in a descriptor.

We also add accessors to retrieve strictly validated SHA-256
as that's really the only important case (while still supporting
other generic digests).

Signed-off-by: Colin Walters <[email protected]>
@cgwalters cgwalters merged commit d3ddc0b into youki-dev:main Aug 30, 2024
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants