-
Notifications
You must be signed in to change notification settings - Fork 51
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
Conversation
2a8036b
to
764c0eb
Compare
src/image/digest.rs
Outdated
/// 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, | ||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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).
28a5807
to
90c017a
Compare
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]>
90c017a
to
5601907
Compare
This addresses #201
add starts parsing digests in a stricter way. We now reject
malformed digests (notably including ones with
/
which is mybiggest 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]