Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split SafeReader into separate types #276

Merged
merged 1 commit into from Feb 5, 2020

Conversation

wellsie1116
Copy link

Since the Repository traits can be implemented outside this crate, it is
not safe to assume that those implementations will verify the maximum
length or hash of metadata/targets before succeeding a fetch request.

In preparation to move the length check and hash verification into the
tuf client, this change splits the SafeReader into 2 types:

  • EnforceMinimumBitrate enforces a minimum transfer rate, currently
    utilized by only the http repository implementation
  • SafeReader, which retains the logic to enforce a maximum file size
    and hash value.
    This change also defines an extension trait on AsyncRead to easily wrap
    an AsyncRead in these types.

A future change will move hash and length enforcement out of the
Repository implementations.

Since the Repository traits can be implemented outside this crate, it is
not safe to assume that those implementations will verify the maximum
length or hash of metadata/targets before succeeding a fetch request.

In preparation to move the length check and hash verification into the
tuf client, this change splits the SafeReader into 2 types:
 * EnforceMinimumBitrate enforces a minimum transfer rate, currently
   utilized by only the http repository implementation
 * SafeReader, which retains the logic to enforce a maximum file size
   and hash value.
This change also defines an extension trait on AsyncRead to easily wrap
an AsyncRead in these types.

A future change will move hash and length enforcement out of the
Repository implementations.
src/util.rs Show resolved Hide resolved

use crate::crypto::{HashAlgorithm, HashValue};
use crate::Result;

pub(crate) trait SafeAsyncRead: Sized {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably fine that this is pub(crate) for now, but I can imagine custom Repository implementations might want to use this functionality.

@erickt erickt merged commit 7dd5753 into theupdateframework:develop Feb 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants