-
Notifications
You must be signed in to change notification settings - Fork 5
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
refactor: changes done while porting iroh-willow #45
Changes from all commits
d89cbf6
75369f3
254c153
65bfc1f
ebb9efd
100b4c0
04eb287
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,11 +16,20 @@ pub struct AreaOfInterest<const MCL: usize, const MCC: usize, const MPL: usize, | |
impl<const MCL: usize, const MCC: usize, const MPL: usize, S: SubspaceId> | ||
AreaOfInterest<MCL, MCC, MPL, S> | ||
{ | ||
/// Creates a new [`AreaOfInterest`]. | ||
pub fn new(area: Area<MCL, MCC, MPL, S>, max_count: u64, max_size: u64) -> Self { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's just easier to type than initializing with |
||
Self { | ||
area, | ||
max_count, | ||
max_size, | ||
} | ||
} | ||
|
||
/// Return the intersection of this [`AreaOfInterest`] with another. | ||
/// [Definition](https://willowprotocol.org/specs/grouping-entries/index.html#aoi_intersection). | ||
pub fn intersection( | ||
&self, | ||
other: AreaOfInterest<MCL, MCC, MPL, S>, | ||
other: &AreaOfInterest<MCL, MCC, MPL, S>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't consume |
||
) -> Option<AreaOfInterest<MCL, MCC, MPL, S>> { | ||
match self.area.intersection(&other.area) { | ||
None => None, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ use arbitrary::{Arbitrary, Error as ArbitraryError}; | |
|
||
use crate::path::Path; | ||
|
||
#[derive(Debug, Hash, PartialEq, Eq)] | ||
#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Those can easily be copy |
||
/// Determines whether a [`Range`] is _closed_ or _open_. | ||
pub enum RangeEnd<T: Ord> { | ||
/// A [closed range](https://willowprotocol.org/specs/grouping-entries/index.html#closed_range) consists of a [start value](https://willowprotocol.org/specs/grouping-entries/index.html#start_value) and an [end_value](https://willowprotocol.org/specs/grouping-entries/index.html#end_value). | ||
|
@@ -119,18 +119,6 @@ impl<const MCL: usize, const MCC: usize, const MPL: usize> PartialOrd<RangeEnd<P | |
} | ||
} | ||
|
||
impl<T> Clone for RangeEnd<T> | ||
where | ||
T: Ord + Clone, | ||
{ | ||
fn clone(&self) -> Self { | ||
match self { | ||
RangeEnd::Closed(val) => RangeEnd::Closed(val.clone()), | ||
RangeEnd::Open => RangeEnd::Open, | ||
} | ||
} | ||
} | ||
|
||
#[cfg(feature = "dev")] | ||
impl<'a, T> Arbitrary<'a> for RangeEnd<T> | ||
where | ||
|
@@ -152,7 +140,7 @@ where | |
/// One-dimensional grouping over a type of value. | ||
/// | ||
/// [Definition](https://willowprotocol.org/specs/grouping-entries/index.html#range) | ||
#[derive(Debug, Hash, PartialEq, Eq)] | ||
#[derive(Debug, Hash, PartialEq, Eq, Clone, Copy)] | ||
pub struct Range<T: Ord> { | ||
/// A range [includes](https://willowprotocol.org/specs/grouping-entries/index.html#range_include) all values greater than or equal to its [start value](https://willowprotocol.org/specs/grouping-entries/index.html#start_value) **and** less than its [end_value](https://willowprotocol.org/specs/grouping-entries/index.html#end_value) | ||
pub start: T, | ||
|
@@ -164,6 +152,11 @@ impl<T> Range<T> | |
where | ||
T: Ord + Clone, | ||
{ | ||
/// Construct a range. | ||
pub fn new(start: T, end: RangeEnd<T>) -> Self { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, a constructor for when you have a |
||
Self { start, end } | ||
} | ||
|
||
/// Construct a new [open range](https://willowprotocol.org/specs/grouping-entries/index.html#open_range) from a [start value](https://willowprotocol.org/specs/grouping-entries/index.html#start_value). | ||
pub fn new_open(start: T) -> Self { | ||
Self { | ||
|
@@ -248,18 +241,6 @@ impl<T: Ord> PartialOrd for Range<T> { | |
} | ||
} | ||
|
||
impl<T> Clone for Range<T> | ||
where | ||
T: Ord + Clone, | ||
{ | ||
fn clone(&self) -> Self { | ||
Self { | ||
start: self.start.clone(), | ||
end: self.end.clone(), | ||
} | ||
} | ||
} | ||
|
||
#[cfg(feature = "dev")] | ||
impl<'a, T> Arbitrary<'a> for Range<T> | ||
where | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,7 @@ impl<NamespacePublicKey: std::fmt::Debug> std::error::Error | |
/// A capability that implements [communal namespaces](https://willowprotocol.org/specs/meadowcap/index.html#communal_namespace). | ||
/// | ||
/// [Definition](https://willowprotocol.org/specs/meadowcap/index.html#communal_capabilities). | ||
#[derive(Clone, Debug, PartialEq, Eq)] | ||
#[derive(Clone, Debug, PartialEq, Eq, Hash)] | ||
pub struct CommunalCapability< | ||
const MCL: usize, | ||
const MCC: usize, | ||
|
@@ -157,8 +157,8 @@ where | |
/// The kind of access this capability grants. | ||
/// | ||
/// [Definition](https://willowprotocol.org/specs/meadowcap/index.html#communal_cap_mode) | ||
pub fn access_mode(&self) -> &AccessMode { | ||
&self.access_mode | ||
pub fn access_mode(&self) -> AccessMode { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Copy types should be returned by value |
||
self.access_mode | ||
} | ||
|
||
/// The user to whom this capability grants access. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,7 @@ impl std::error::Error for NotAWriteCapabilityError {} | |
/// A Meadowcap capability. | ||
/// | ||
/// [Definition](https://willowprotocol.org/specs/meadowcap/index.html#Capability) | ||
#[derive(Clone, Debug, PartialEq, Eq)] | ||
#[derive(Clone, Debug, PartialEq, Eq, Hash)] | ||
#[cfg_attr(feature = "dev", derive(Arbitrary))] | ||
pub enum McCapability< | ||
const MCL: usize, | ||
|
@@ -96,9 +96,9 @@ where | |
} | ||
|
||
/// Create a new owned capability granting access to the [full area](https://willowprotocol.org/specs/grouping-entries/index.html#full_area) of the [namespace](https://willowprotocol.org/specs/data-model/index.html#namespace) to the given `UserPublicKey`. | ||
pub async fn new_owned<NamespaceSecret>( | ||
pub fn new_owned<NamespaceSecret>( | ||
namespace_key: NamespacePublicKey, | ||
namespace_secret: NamespaceSecret, | ||
namespace_secret: &NamespaceSecret, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
user_key: UserPublicKey, | ||
access_mode: AccessMode, | ||
) -> Result<Self, OwnedCapabilityCreationError<NamespacePublicKey>> | ||
|
@@ -111,7 +111,7 @@ where | |
} | ||
|
||
/// The kind of access this capability grants. | ||
pub fn access_mode(&self) -> &AccessMode { | ||
pub fn access_mode(&self) -> AccessMode { | ||
match self { | ||
Self::Communal(cap) => cap.access_mode(), | ||
Self::Owned(cap) => cap.access_mode(), | ||
|
@@ -251,7 +251,7 @@ where | |
/// Return a new [`McAuthorisationToken`], or an error if the resulting signature was not for the capability's receiver. | ||
pub fn authorisation_token<UserSecret, PD>( | ||
&self, | ||
entry: Entry<MCL, MCC, MPL, NamespacePublicKey, UserPublicKey, PD>, | ||
entry: &Entry<MCL, MCC, MPL, NamespacePublicKey, UserPublicKey, PD>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Entry isn't consumed so take ref to avoid clone at call site |
||
secret: UserSecret, | ||
) -> Result< | ||
McAuthorisationToken< | ||
|
@@ -354,12 +354,12 @@ pub(super) mod encoding { | |
|
||
match self { | ||
McCapability::Communal(_) => { | ||
if self.access_mode() == &AccessMode::Write { | ||
if self.access_mode() == AccessMode::Write { | ||
header |= 0b0100_0000; | ||
} | ||
} | ||
McCapability::Owned(_) => { | ||
if self.access_mode() == &AccessMode::Read { | ||
if self.access_mode() == AccessMode::Read { | ||
header |= 0b1000_0000; | ||
} else { | ||
header |= 0b1100_0000; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the fields should not be pub: If this type is intended to symbolize an entry+token pair where the authorisation was checked (which the
new
function indicates, and which is also how the term is used in the willow spec) then I think the fields should be private, otherwiseAuthorisedEntry(some_entry, some_token)
is a too-easy-to-get-wrong constructor for an unchecked AuthorisedEntry.