You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Right now we define
pub type Sha256HashValue = [u8; 32];
pub type Sha512HashValue = [u8; 64];
which is simple enough but also painful: we can implement our own traits
for these types (and indeed, we do it for FsVerityHashValue) but we
can't implement things like fmt::Debug because there's a default impl
(which rather unhelpfully prints the hashes out as an array of bytes).
Turn these into proper types using a trivial struct wrapper:
pub struct Sha256HashValue([u8; 32]);
pub struct Sha512HashValue([u8; 64]);
which gives us a lot more control. We can start by implementing
meaningful fmt::Debug traits.
Doing this means that we implicitly lose our implementation of
AsRef<[u8]> and AsMut<[u8]> which we've been mostly using in order to do
various ad-hoc encoding to/from various forms of hex values all over the
codebase. Move all of those ad-hoc forms of encoding into proper
methods on the trait itself by adding functions like ::to_hex() and
::from_hex() which we can use instead. We also drop our last instances
of using parse_sha256() for fs-verity digests.
There are a couple of other places where we need the actual bytes,
though: when reading/writing hash values to splitstreams and when
reading/writing the metacopy xattr in erofs images. Deal with those by
deriving the usual zerocopy FromBytes/IntoBytes traits for our new hash
types and moving the code in the splitstream and erofs modules to
directly include the data inside of the relevant structure types, mark
those types as FromBytes/IntoBytes, and use the zerocopy APIs directly.
In the case of the metacopy attr in the erofs code this provides an
opportunity for a substantial cleanup in an otherwise scary part of the
code.
Signed-off-by: Allison Karlitskaya <[email protected]>
0 commit comments