Skip to main content

UploadSource

Trait UploadSource 

Source
pub trait UploadSource: Sync {
    // Required method
    fn read_at(&self, offset: u64, len: usize) -> Result<Cow<'_, [u8]>>;

    // Provided methods
    fn check_unchanged(&self) -> Result<SourceIdentity, SourceChanged> { ... }
    fn verifies_rederived(&self) -> bool { ... }
}
Expand description

The bytes of one blob, read a chunk at a time.

The client asks for exactly the window it is about to send — again after a re-align, a re-send or a resume — so a source never has to hold the blob. A byte slice is one; an original, whose ciphertext is re-derived from its plaintext per window, is the other that matters (capsule_library::lifecycle::OriginalCiphertext).

Required Methods§

Source

fn read_at(&self, offset: u64, len: usize) -> Result<Cow<'_, [u8]>>

The bytes [offset, offset + len). Fewer than len bytes is a source error: the declared size is the blob’s, and a short read means the source changed under the upload. A source that finds what it re-derived differs from what it first sealed returns an error carrying SourceChanged, which ends the transfer typed.

Provided Methods§

Source

fn check_unchanged(&self) -> Result<SourceIdentity, SourceChanged>

The cheap check that the source is still what the bundle was built from (its size, modification time and file id), run before every window is read and when finalization refuses the blob’s hash.

SourceIdentity::Affirmed is a positive claim that every byte the source returns is the byte it returned before; only then is a range this transfer already read sent again (a lost answer, a re-plan, a re-created or resumed session) or a refused hash answered with a re-created session. A source that cannot say — the default — answers SourceIdentity::Unknown, and its transfer ends at the first such re-send: ranges that may now seal to different ciphertexts under the same nonces would hand the server two ciphertexts per nonce. Bytes held in memory cannot change, so they affirm.

§Errors

SourceChanged naming what differs.

Source

fn verifies_rederived(&self) -> bool

Whether every window this source returns is checked against the bytes it first produced, so a window it returns again is byte-identical or refused with SourceChanged: bytes in memory cannot change, and an original re-derives every STREAM chunk a window touches and compares its tag with the one recorded when the bundle was built.

Only such a source is sent with more than one range of a session in flight. A parallel schedule re-sends ranges far more often (a refused overlap, a lost answer, a cut), and a source that only answers check_unchanged can miss a change that keeps its identity, which a re-derived range would then put under nonces the first read spent. A source that cannot say — the default — is sent one range at a time.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl UploadSource for Vec<u8>

Source§

impl UploadSource for [u8]

Source§

impl<T: UploadSource + ?Sized> UploadSource for &T

Source§

impl<const N: usize> UploadSource for [u8; N]

Implementors§