pub struct Container<'a> { /* private fields */ }Expand description
A parsed container, borrowing the bytes it was parsed from.
Parsing does not copy the payload and does not read it. A container of a hundred gigabytes parses in the time it takes to hash a footer, and the sections are read when somebody asks for them.
Implementations§
Source§impl<'a> Container<'a>
impl<'a> Container<'a>
Sourcepub fn parse(bytes: &'a [u8]) -> Result<Self>
pub fn parse(bytes: &'a [u8]) -> Result<Self>
Parses a container and checks that the footer is the footer that was written.
The root digest covers the header and the footer, so a container that parses has metadata
nobody has edited since it was written. Section contents are not read here. Call
Container::verify for that, which is the expensive one and is a separate decision.
§Errors
Returns Error describing the first thing that was wrong. It never panics, whatever the
input is, and there is a fuzz target that exists to keep that true.
Sourcepub fn parse_without_root_digest(bytes: &'a [u8]) -> Result<Self>
pub fn parse_without_root_digest(bytes: &'a [u8]) -> Result<Self>
Parses a container without checking the root digest.
This exists for the fuzzer. Checking the digest first would mean essentially every generated input is rejected in the trailer, and the parser behind it would never be reached, which is the part that needs the fuzzing. It is public because the fuzz target lives outside this crate, and it is named at length so that nobody reaches for it by accident.
§Errors
The same as Container::parse, minus the digest mismatch.
Sourcepub const fn header(&self) -> FileHeader
pub const fn header(&self) -> FileHeader
The format version this container was written at.
Sourcepub const fn root_digest(&self) -> Digest
pub const fn root_digest(&self) -> Digest
The digest that covers the header and the footer.
Sourcepub const fn decoder(&self) -> Option<&DecoderRef<'a>>
pub const fn decoder(&self) -> Option<&DecoderRef<'a>>
The decoder reference, if there is one.
Sourcepub fn section_bytes(&self, section: &Section) -> &'a [u8] ⓘ
pub fn section_bytes(&self, section: &Section) -> &'a [u8] ⓘ
The bytes of a section.
The bounds were checked during parsing, so this cannot be out of range for a section that
came from this container. It takes a &Section rather than an id so that the only way to
call it is with one that did.
Sourcepub fn decoder_bytes(&self) -> Option<&'a [u8]>
pub fn decoder_bytes(&self) -> Option<&'a [u8]>
The bytes of the embedded decoder module, if the decoder is embedded and the section it names exists.
Sourcepub fn verify(&self) -> Result<()>
pub fn verify(&self) -> Result<()>
Hashes every section and checks it against the footer.
This reads the whole file, so it is a decision rather than something that happens on every open. The honest place for it is once when a dataset arrives and then never again.
§Errors
Returns Error::DigestMismatch naming the first section whose bytes do not hash to what
the footer says they should.