SubspaceId

Struct SubspaceId 

Source
pub struct SubspaceId(/* private fields */);
Expand description

The type of SubspaceIds used by Willow’25.

Subspaces group Willow data within the same namespace into independent collections — entries with nonequal subspace ids cannot overwrite each other. Subspaces further play a role in access control for Willow: subspace ids are public keys of a digital signature system, and knowledge of the corresponding secret key allow you to issue write entries to a subspace, and to delegate access to other users — see the meadowcap module for more details.

That all said, you can also simply think of subspace ids as glorified [u8; 32] arrays. That perspective should be sufficient as long as you do not need to care about cryptographic details.

You will typically obtain a subspace id either by randomly generating a key pair, by cloning an existing subspace id, or by creating it from raw bytes via SubspaceId::from_bytes. See the Willow25 specification if you want to work with raw bytes — while every [u8; 32] can be converted into a SubspaceId, some of these do not correspond to canonic public key encodings and thus always fail signature verification.

use rand::rngs::OsRng;
use willow25::prelude::*;

let mut csprng = OsRng; // cryptographically secure pseudo-random number generator
let (_subspace_id, _secret) = randomly_generate_subspace(&mut csprng);

let subspace_id2 = SubspaceId::from_bytes(&[17; SUBSPACE_ID_WIDTH]);
assert_eq!(subspace_id2.as_bytes(), &[17; 32]);

Implementations§

Source§

impl SubspaceId

Source

pub fn from_bytes(bytes: &[u8; 32]) -> Self

Returns a new SubspaceId corresponding to the supplied bytes.

use willow25::prelude::*;

let subspace_id = SubspaceId::from_bytes(&[17; SUBSPACE_ID_WIDTH]);
assert_eq!(subspace_id.as_bytes(), &[17; SUBSPACE_ID_WIDTH]);
Source

pub fn as_bytes(&self) -> &[u8; 32]

Returns a reference to the raw bytes that make up this subspace id.

use willow25::prelude::*;

let subspace_id = SubspaceId::from_bytes(&[17; SUBSPACE_ID_WIDTH]);
assert_eq!(subspace_id.as_bytes(), &[17; SUBSPACE_ID_WIDTH]);
Source

pub fn to_bytes(&self) -> [u8; 32]

Returns the raw bytes that make up this subspace id.

use willow25::prelude::*;

let subspace_id = SubspaceId::from_bytes(&[17; SUBSPACE_ID_WIDTH]);
assert_eq!(subspace_id.to_bytes(), [17; SUBSPACE_ID_WIDTH]);
Source

pub fn from_ed25519_verifying_key(verifying_key: VerifyingKey) -> Self

Creates a subspace id from an ed25519 verifying key.

use willow25::prelude::*;

let from_key = SubspaceId::from_ed25519_verifying_key(
    ed25519_dalek::VerifyingKey::from_bytes(&[17; 32]).unwrap(),
);
let from_bytes = SubspaceId::from_bytes(&[17; SUBSPACE_ID_WIDTH]);

assert_eq!(from_key, from_bytes);

Trait Implementations§

Source§

impl AuthorisationToken<MCL, MCC, MPL, NamespaceId, SubspaceId, PayloadDigest> for AuthorisationToken

You only need this trait impl if you work with fully generic code from the willow_data_model crate.

Source§

type Ingredients = McIngredients

The type of the information you need in order to authorise an entry. For example, in Meadowcap, this would be a pair of a capability and a secret key.
Source§

type CreationError = DoesNotAuthorise

Everything that can go wrong when trying to create a new authorisation token from some Ingredients for some entry.
Source§

fn new_for_entry<E>( entry: &E, ingredients: &Self::Ingredients, ) -> Result<Self, Self::CreationError>
where E: EntrylikeExt<MCL, MCC, MPL, NamespaceId, SubspaceId, PayloadDigest> + ?Sized,

Creates an authorisation token for the given entry, if possible.
Source§

fn does_authorise<E>(&self, entry: &E) -> bool
where E: EntrylikeExt<MCL, MCC, MPL, NamespaceId, SubspaceId, PayloadDigest> + ?Sized,

Determines whether self authorises the given entry.
Source§

impl Clone for SubspaceId

Source§

fn clone(&self) -> SubspaceId

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Coordinatelike<MCL, MCC, MPL, SubspaceId> for (Path, SubspaceId, Timestamp)

Source§

fn wdm_timestamp(&self) -> Timestamp

Returns the timestamp of self.
Source§

impl Coordinatelike<MCL, MCC, MPL, SubspaceId> for (Path, Timestamp, SubspaceId)

Source§

fn wdm_timestamp(&self) -> Timestamp

Returns the timestamp of self.
Source§

impl Coordinatelike<MCL, MCC, MPL, SubspaceId> for (SubspaceId, Path, Timestamp)

Source§

fn wdm_timestamp(&self) -> Timestamp

Returns the timestamp of self.
Source§

impl Coordinatelike<MCL, MCC, MPL, SubspaceId> for (SubspaceId, Timestamp, Path)

Source§

fn wdm_timestamp(&self) -> Timestamp

Returns the timestamp of self.
Source§

impl Coordinatelike<MCL, MCC, MPL, SubspaceId> for (Timestamp, Path, SubspaceId)

Source§

fn wdm_timestamp(&self) -> Timestamp

Returns the timestamp of self.
Source§

impl Coordinatelike<MCL, MCC, MPL, SubspaceId> for (Timestamp, SubspaceId, Path)

Source§

fn wdm_timestamp(&self) -> Timestamp

Returns the timestamp of self.
Source§

impl Coordinatelike<MCL, MCC, MPL, SubspaceId> for AuthorisedEntry

Source§

fn wdm_timestamp(&self) -> Timestamp

Returns the timestamp of self.
Source§

impl Coordinatelike<MCL, MCC, MPL, SubspaceId> for Entry

Source§

fn wdm_timestamp(&self) -> Timestamp

Returns the timestamp of self.
Source§

impl Coordinatelike<MCL, MCC, MPL, SubspaceId> for PossiblyAuthorisedEntry

Source§

fn wdm_timestamp(&self) -> Timestamp

Returns the timestamp of self.
Source§

impl Debug for SubspaceId

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Decodable for SubspaceId

Source§

type ErrorReason = Infallible

Reason why decoding can fail (beyond an unexpected end of input or a producer error).
Source§

async fn decode<P>( producer: &mut P, ) -> Result<Self, DecodeError<P::Final, P::Error, Self::ErrorReason>>
where P: BulkProducer<Item = u8> + ?Sized, Self: Sized,

Decodes the symbols produced by the given bulk producer into a Self, or yields an error if the producer does not produce a valid encoding. Read more
Source§

impl DecodableCanonic for SubspaceId

Source§

type ErrorCanonic = Infallible

The type for reporting that the sequence of symbols to decode was not a valid canonic encoding of any value of type Self. Read more
Source§

async fn decode_canonic<P>( producer: &mut P, ) -> Result<Self, DecodeError<P::Final, P::Error, Self::ErrorCanonic>>
where P: BulkProducer<Item = u8> + ?Sized, Self: Sized,

Decodes the symbols produced by the given bulk producer into a Self, and errors if the input encoding is not the canonical one.
Source§

impl Encodable for SubspaceId

Source§

async fn encode<C>(&self, consumer: &mut C) -> Result<(), C::Error>
where C: BulkConsumer<Item = u8> + ?Sized,

Writes an encoding of &self into the given bulk consumer. Read more
Source§

impl EncodableKnownLength for SubspaceId

Source§

fn len_of_encoding(&self) -> usize

Computes the number of symbols of the encoding of self. A successful call to encode must feed exactly that many symbols into the bulk consumer.
Source§

impl Entrylike<MCL, MCC, MPL, NamespaceId, SubspaceId, PayloadDigest> for AuthorisedEntry

Source§

fn wdm_payload_length(&self) -> u64

Returns the payload_length of self.
Source§

fn wdm_payload_digest(&self) -> &PayloadDigest

Returns the payload_digest of self.
Source§

impl Entrylike<MCL, MCC, MPL, NamespaceId, SubspaceId, PayloadDigest> for Entry

Source§

fn wdm_payload_length(&self) -> u64

Returns the payload_length of self.
Source§

fn wdm_payload_digest(&self) -> &PayloadDigest

Returns the payload_digest of self.
Source§

impl Entrylike<MCL, MCC, MPL, NamespaceId, SubspaceId, PayloadDigest> for PossiblyAuthorisedEntry

Source§

fn wdm_payload_length(&self) -> u64

Returns the payload_length of self.
Source§

fn wdm_payload_digest(&self) -> &PayloadDigest

Returns the payload_digest of self.
Source§

impl From<[u8; 32]> for SubspaceId

Source§

fn from(value: [u8; 32]) -> Self

Converts to this type from the input type.
Source§

impl GreatestElement for SubspaceId

Source§

fn greatest() -> Self

Returns the unique greatest element. Read more
Source§

fn is_greatest(&self) -> bool

Returns true if and only if self is the greatest element.
Source§

impl Hash for SubspaceId

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Keylike<MCL, MCC, MPL, SubspaceId> for (Path, SubspaceId)

Source§

fn wdm_subspace_id(&self) -> &SubspaceId

Returns the subspace_id of self.
Source§

fn wdm_path(&self) -> &Path<MCL, MCC, MPL>

Returns the path of self.
Source§

impl Keylike<MCL, MCC, MPL, SubspaceId> for (Path, SubspaceId, Timestamp)

Source§

fn wdm_subspace_id(&self) -> &SubspaceId

Returns the subspace_id of self.
Source§

fn wdm_path(&self) -> &Path<MCL, MCC, MPL>

Returns the path of self.
Source§

impl Keylike<MCL, MCC, MPL, SubspaceId> for (Path, Timestamp, SubspaceId)

Source§

fn wdm_subspace_id(&self) -> &SubspaceId

Returns the subspace_id of self.
Source§

fn wdm_path(&self) -> &Path<MCL, MCC, MPL>

Returns the path of self.
Source§

impl Keylike<MCL, MCC, MPL, SubspaceId> for (SubspaceId, Path)

Source§

fn wdm_subspace_id(&self) -> &SubspaceId

Returns the subspace_id of self.
Source§

fn wdm_path(&self) -> &Path<MCL, MCC, MPL>

Returns the path of self.
Source§

impl Keylike<MCL, MCC, MPL, SubspaceId> for (SubspaceId, Path, Timestamp)

Source§

fn wdm_subspace_id(&self) -> &SubspaceId

Returns the subspace_id of self.
Source§

fn wdm_path(&self) -> &Path<MCL, MCC, MPL>

Returns the path of self.
Source§

impl Keylike<MCL, MCC, MPL, SubspaceId> for (SubspaceId, Timestamp, Path)

Source§

fn wdm_subspace_id(&self) -> &SubspaceId

Returns the subspace_id of self.
Source§

fn wdm_path(&self) -> &Path<MCL, MCC, MPL>

Returns the path of self.
Source§

impl Keylike<MCL, MCC, MPL, SubspaceId> for (Timestamp, Path, SubspaceId)

Source§

fn wdm_subspace_id(&self) -> &SubspaceId

Returns the subspace_id of self.
Source§

fn wdm_path(&self) -> &Path<MCL, MCC, MPL>

Returns the path of self.
Source§

impl Keylike<MCL, MCC, MPL, SubspaceId> for (Timestamp, SubspaceId, Path)

Source§

fn wdm_subspace_id(&self) -> &SubspaceId

Returns the subspace_id of self.
Source§

fn wdm_path(&self) -> &Path<MCL, MCC, MPL>

Returns the path of self.
Source§

impl Keylike<MCL, MCC, MPL, SubspaceId> for AuthorisedEntry

Source§

fn wdm_subspace_id(&self) -> &SubspaceId

Returns the subspace_id of self.
Source§

fn wdm_path(&self) -> &Path<MCL, MCC, MPL>

Returns the path of self.
Source§

impl Keylike<MCL, MCC, MPL, SubspaceId> for Entry

Source§

fn wdm_subspace_id(&self) -> &SubspaceId

Returns the subspace_id of self.
Source§

fn wdm_path(&self) -> &Path<MCL, MCC, MPL>

Returns the path of self.
Source§

impl Keylike<MCL, MCC, MPL, SubspaceId> for PossiblyAuthorisedEntry

Source§

fn wdm_subspace_id(&self) -> &SubspaceId

Returns the subspace_id of self.
Source§

fn wdm_path(&self) -> &Path<MCL, MCC, MPL>

Returns the path of self.
Source§

impl LeastElement for SubspaceId

Source§

fn least() -> Self

Returns the unique least element. Read more
Source§

fn is_least(&self) -> bool

Returns true if and only if self is the least element.
Source§

impl LowerSemilattice for SubspaceId

Source§

fn greatest_lower_bound(&self, other: &Self) -> Self

Returns the greatest lower bound of self and other, i.e., the unique greatest element in the type which is less than or equal to both self and other.
Source§

impl Ord for SubspaceId

Implemented lexicographically on the compressed Edwards y coordinate encoding.

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for SubspaceId

Source§

fn eq(&self, other: &SubspaceId) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for SubspaceId

Implemented lexicographically on the compressed Edwards y coordinate encoding.

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl RangeBounds<SubspaceId> for Area

Source§

fn start_bound(&self) -> Bound<&SubspaceId>

Start index bound. Read more
Source§

fn end_bound(&self) -> Bound<&SubspaceId>

End index bound. Read more
1.35.0 · Source§

fn contains<U>(&self, item: &U) -> bool
where T: PartialOrd<U>, U: PartialOrd<T> + ?Sized,

Returns true if item is contained in the range. Read more
Source§

fn is_empty(&self) -> bool
where T: PartialOrd,

🔬This is a nightly-only experimental API. (range_bounds_is_empty)
Returns true if the range contains no items. One-sided ranges (RangeFrom, etc) always return false. Read more
Source§

impl RangeBounds<SubspaceId> for Range3d

Source§

fn start_bound(&self) -> Bound<&SubspaceId>

Start index bound. Read more
Source§

fn end_bound(&self) -> Bound<&SubspaceId>

End index bound. Read more
1.35.0 · Source§

fn contains<U>(&self, item: &U) -> bool
where T: PartialOrd<U>, U: PartialOrd<T> + ?Sized,

Returns true if item is contained in the range. Read more
Source§

fn is_empty(&self) -> bool
where T: PartialOrd,

🔬This is a nightly-only experimental API. (range_bounds_is_empty)
Returns true if the range contains no items. One-sided ranges (RangeFrom, etc) always return false. Read more
Source§

impl TryPredecessor for SubspaceId

Source§

fn try_predecessor(&self) -> Option<Self>

If self has a predecessor, i.e., a unique greatest value which is strictly less than self, returns it. If there is no unique predecessor, returns None.
Source§

fn is_predecessor_of(&self, other: &Self) -> bool

Returns true iff self is the predecessor of other.
Source§

fn is_not_predecessor_of(&self, other: &Self) -> bool

Returns true iff self is not the predecessor of other.
Source§

impl TrySuccessor for SubspaceId

Source§

fn try_successor(&self) -> Option<Self>

If self has a successor, i.e., a unique least value which is strictly greater than self, returns it. If there is no unique successor, returns None.
Source§

fn is_successor_of(&self, other: &Self) -> bool

Returns true iff self is the successor of other.
Source§

fn is_not_successor_of(&self, other: &Self) -> bool

Returns true iff self is not the successor of other.
Source§

impl UpperSemilattice for SubspaceId

Source§

fn least_upper_bound(&self, other: &Self) -> Self

Returns the least upper bound of self and other, i.e., the unique least element in the type which is greater than or equal to both self and other.
Source§

impl Verifier<SubspaceSignature> for SubspaceId

Source§

fn verify(&self, msg: &[u8], signature: &SubspaceSignature) -> Result<(), Error>

Use Self to verify that the provided signature for a given message bytestring is authentic. Read more
Source§

impl Eq for SubspaceId

Source§

impl PredecessorExceptForLeast for SubspaceId

Source§

impl StructuralPartialEq for SubspaceId

Source§

impl SuccessorExceptForGreatest for SubspaceId

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> BoundedLowerSemilattice for T

Source§

fn greatest_lower_bound_slice(values: &[Self]) -> Self

Computes the greatest lower bound of all values in the slice. For the empty slice, this is the least element.
Source§

impl<T> BoundedUpperSemilattice for T

Source§

fn least_upper_bound_slice(values: &[Self]) -> Self

Computes the least upper bound of all values in the slice. For the empty slice, this is the greatest element.
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T, S> EncodableExt<S> for T
where T: Encodable<S>,

Source§

async fn new_vec_storing_encoding(&self) -> Vec<Symbol>
where Symbol: Default,

Returns a Vec storing the encoding of self. Read more
Source§

impl<T, S> EncodableKnownLengthExt<S> for T

Source§

async fn new_boxed_slice_storing_encoding(&self) -> Box<[Symbol]>
where Symbol: Default,

Returns a Box<[Symbol]> storing the encoding of self. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> BoundedLattice for T

Source§

impl<T> Lattice for T