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, Error>
pub fn from_hex_lower(s: &str) -> Result<Checksum, Error>
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, Error>
pub fn from_hex(s: &str) -> Result<Checksum, Error>
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, Error>
pub fn from_ay(b: &[u8]) -> Result<Checksum, Error>
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, Error>
pub fn from_base64(s: &str) -> Result<Checksum, Error>
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, Error>
pub fn from_base64_modified(s: &str) -> Result<Checksum, Error>
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.
Source§impl Ord for Checksum
impl Ord for Checksum
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for Checksum
impl PartialOrd for Checksum
impl StructuralPartialEq for Checksum
Auto Trait Implementations§
impl Forget for Checksum
impl Freeze for Checksum
impl Move for Checksum
impl RefUnwindSafe for Checksum
impl Send for Checksum
impl Sync for Checksum
impl Unpin for Checksum
impl UnsafeUnpin for Checksum
impl UnwindSafe for Checksum
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.