pub struct Checksum(/* private fields */);Expand description
A 32-byte SHA-256 checksum that names an object.
§Forms
A checksum has these forms:
- 64 lowercase hex characters, in refs, loose paths, and object names. See
to_hexandfrom_hex. - The raw 32-byte
ay, inside commit and dirtree objects. Seeas_bytesandfrom_ay. - Modified base64, in static-delta directory names. See
to_base64_modifiedandfrom_base64_modified. - Standard padded base64. See
to_base64andfrom_base64.
§Order
Checksum values compare byte-wise. The byte order equals the order of
the lowercase hex strings. A sort of Checksum values gives the ASCII
checksum order of the on-disk format, for example the order of the
ostree.sizes entries.
Implementations§
Source§impl Checksum
impl Checksum
Sourcepub fn from_bytes(b: [u8; 32]) -> Checksum
pub fn from_bytes(b: [u8; 32]) -> Checksum
Creates a checksum from the raw digest bytes.
Sourcepub fn sha256(data: &[u8]) -> Checksum
pub fn sha256(data: &[u8]) -> Checksum
Returns the SHA-256 digest of data.
This digest is the checksum of a metadata object, where data is the
serialized GVariant form of the object.
Sourcepub fn from_hex_lower(s: &str) -> Result<Checksum>
pub fn from_hex_lower(s: &str) -> Result<Checksum>
Parses 64 lowercase hex characters.
This is the form that to_hex writes. The rule
applies to a revision: a name of 64 characters is a checksum only if
it is lowercase hex. An uppercase or mixed-case name of that length is
a ref name.
For a checksum from stored bytes, from_hex is
the parser. It accepts both cases.
§Errors
The function returns Error::InvalidChecksum with one of these
messages:
hex checksum is not lowercaseifsholds an uppercase character. This check comes first.hex checksum is not 64 charactersifsis not 64 bytes long.hex checksum has a non-hex characterif a character is not in0-9ora-f.
Sourcepub fn from_hex(s: &str) -> Result<Checksum>
pub fn from_hex(s: &str) -> Result<Checksum>
Parses 64 hex characters in uppercase, lowercase, or mixed case.
to_hex writes the result in lowercase.
§Errors
The function returns Error::InvalidChecksum with one of these
messages:
hex checksum is not 64 charactersifsis not 64 bytes long.hex checksum has a non-hex characterif a character is not in0-9,a-f, orA-F.
Sourcepub fn from_ay(b: &[u8]) -> Result<Checksum>
pub fn from_ay(b: &[u8]) -> Result<Checksum>
Creates a checksum from the payload of a GVariant ay value.
§Errors
The function returns Error::InvalidChecksum with the message
ay checksum is not 32 bytes if b is not exactly 32 bytes long.
Sourcepub fn to_base64(&self) -> String
pub fn to_base64(&self) -> String
Returns the checksum as standard padded base64 of 44 characters.
The string holds 43 data characters and one = pad.
Sourcepub fn from_base64(s: &str) -> Result<Checksum>
pub fn from_base64(s: &str) -> Result<Checksum>
Parses standard padded base64 of exactly 44 characters.
The string must hold 43 data characters and one = pad. Each checksum
has exactly one accepted spelling.
§Errors
The function returns Error::InvalidChecksum with one of these
messages:
base64 checksum has the wrong lengthifsis not 44 bytes long.base64 checksum is missing its padif the last character is not=.base64 has an invalid characterif a data character is not in the standard alphabet. The modified character_is not in this alphabet.base64 checksum has nonzero trailing bitsif the two unused low bits of the last data character are not zero.
Sourcepub fn to_base64_modified(&self) -> String
pub fn to_base64_modified(&self) -> String
Returns the checksum as modified base64 of 43 characters.
Modified base64 is standard base64 with _ in the place of / and
with no trailing =.
Sourcepub fn from_base64_modified(s: &str) -> Result<Checksum>
pub fn from_base64_modified(s: &str) -> Result<Checksum>
Parses modified base64 of exactly 43 characters with no pad.
Each checksum has exactly one accepted spelling.
§Errors
The function returns Error::InvalidChecksum with one of these
messages:
base64 checksum has the wrong lengthifsis not 43 bytes long. A stray trailing=makes the string 44 bytes long.base64 has an invalid characterif a character is not in the modified alphabet. The standard character/and the pad=are not in this alphabet.base64 checksum has nonzero trailing bitsif the two unused low bits of the last character are not zero.
Trait Implementations§
impl Copy for Checksum
impl Eq for Checksum
Source§impl GvEncode for Checksum
Encodes the checksum as its raw 32 bytes, the GVariant ay form.
impl GvEncode for Checksum
Encodes the checksum as its raw 32 bytes, the GVariant ay form.
Checksum::from_ay decodes this form.