Struct Doc

Source
pub struct Doc { /* private fields */ }
Expand description

Doc is a valid identity document.

To ensure that only valid documents are used, this type is restricted to be read-only. For mutating the document use Doc::edit.

A valid Doc can be constructed in four ways:

  1. Doc::initial: a safe way to construct the initial document for an identity.
  2. RawDoc::verified: validates a RawDoc’s fields and converts it into a Doc
  3. Deserialize: will deserialize a Doc by first deserializing a RawDoc and use RawDoc::verified to construct the Doc.
  4. Doc::from_blob: construct a Doc from a Git blob by deserializing its contents.

Implementations§

Source§

impl Doc

Source

pub fn initial(project: Project, delegate: Did, visibility: Visibility) -> Doc

Construct the initial Doc for an identity.

It will begin with the provided project in the Doc::payload, the delegate as the sole delegate, a threshold of 1, and the given visibility.

Source

pub fn from_blob(blob: &Blob<'_>) -> Result<Doc, DocError>

Construct a Doc contained in the provided Git blob.

Source

pub fn edit(self) -> RawDoc

Convert the Doc into a RawDoc for changing the field values and re-verifying.

Source

pub fn with_edits<F>(self, f: F) -> Result<Doc, DocError>
where F: FnOnce(&mut RawDoc),

Using the current state of the Doc, perform any edits on the RawDoc form and verify the changes.

Source

pub fn version(&self) -> &Version

Get the version of the document.

Source

pub fn payload(&self) -> &BTreeMap<PayloadId, Payload>

Return the associated payloads for this Doc.

Source

pub fn project(&self) -> Result<Project, PayloadError>

Get the project payload, if it exists and is valid, out of this document.

Source

pub fn default_branch_rule( &self, ) -> Result<(Pattern, Rule<ResolvedDelegates, Threshold>), DefaultBranchRuleError>

Source

pub fn visibility(&self) -> &Visibility

Return the associated Visibility of this document.

Source

pub fn is_public(&self) -> bool

Check whether the visibility of the document is public.

Source

pub fn is_private(&self) -> bool

Check whether the visibility of the document is private.

Source

pub fn threshold(&self) -> usize

Return the associated threshold of this document.

Source

pub fn threshold_nonzero(&self) -> &NonZero<usize>

Return the associated threshold of this document in its non-zero format.

Source

pub fn delegates(&self) -> &Delegates

Return the associated delegates of this document.

Source

pub fn is_delegate(&self, did: &Did) -> bool

Check if the did is part of the Doc::delegates set.

Source

pub fn is_visible_to(&self, did: &Did) -> bool

Check whether this document and the associated repository is visible to the given peer.

Source

pub fn verify_signature( &self, key: &PublicKey, signature: &Signature, blob: Oid, ) -> Result<(), PublicKey>

Validate signature using this document’s delegates, against a given document blob.

Source

pub fn is_majority(&self, votes: usize) -> bool

Check the provided votes passes the Doc::majority.

Source

pub fn majority(&self) -> usize

Return the majority number based on the size of the delegates set.

Source

pub fn encode(&self) -> Result<(Oid, Vec<u8>), DocError>

Encode the Doc as canonical JSON, returning the set of bytes and its corresponding Git Oid.

Source

pub fn sign<G>(&self, signer: &G) -> Result<(Oid, Vec<u8>, Signature), DocError>
where G: Signer<Signature>,

Doc::encode and sign the Doc, returning the set of bytes, its corresponding Git Oid and the Signature over the Oid.

Source

pub fn signature_of<G>(&self, signer: &G) -> Result<Signature, DocError>
where G: Signer<Signature>,

Similar to Doc::sign, but only returning the Signature.

Source

pub fn load_at<R>(commit: Oid, repo: &R) -> Result<DocAt, DocError>
where R: ReadRepository,

Load the DocAt found at the given commit. The DocAt will contain the corresponding Doc.

Source

pub fn init<G>( &self, repo: &Repository, signer: &Device<G>, ) -> Result<Oid, RepositoryError>
where G: Signer<Signature>,

Initialize an identity::Identity with this Doc as the associated document.

Trait Implementations§

Source§

impl AsRef<Doc> for DocAt

Source§

fn as_ref(&self) -> &Doc

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Clone for Doc

Source§

fn clone(&self) -> Doc

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 Debug for Doc

Source§

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

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

impl<'de> Deserialize<'de> for Doc

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<Doc, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<DocAt> for Doc

Source§

fn from(value: DocAt) -> Doc

Converts to this type from the input type.
Source§

impl GetCanonicalRefs for Doc

Source§

type Error = CanonicalRefsError

Source§

fn canonical_refs( &self, ) -> Result<Option<CanonicalRefs>, <Doc as GetCanonicalRefs>::Error>

Retrieve the CanonicalRefs, returning Some if they are not present, and None if they are missing. Read more
Source§

fn raw_canonical_refs( &self, ) -> Result<Option<RawCanonicalRefs>, <Doc as GetCanonicalRefs>::Error>

Retrieve the RawCanonicalRefs, returning Some if they are not present, and None if they are missing. Read more
Source§

fn canonical_refs_or_default<D, E>( &self, default: D, ) -> Result<CanonicalRefs, E>
where D: Fn() -> Result<CanonicalRefs, E>, E: From<Self::Error>,

Retrieve the CanonicalRefs, and in the case of None, then use the default function to return a default set of CanonicalRefs.
Source§

impl PartialEq for Doc

Source§

fn eq(&self, other: &Doc) -> 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 Serialize for Doc

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl TryFrom<RawDoc> for Doc

Source§

type Error = DocError

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

fn try_from(doc: RawDoc) -> Result<Doc, <Doc as TryFrom<RawDoc>>::Error>

Performs the conversion.
Source§

impl Eq for Doc

Source§

impl StructuralPartialEq for Doc

Auto Trait Implementations§

§

impl Freeze for Doc

§

impl RefUnwindSafe for Doc

§

impl Send for Doc

§

impl Sync for Doc

§

impl Unpin for Doc

§

impl UnwindSafe for Doc

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> 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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. 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> IntoInit<ZeroInit> for T

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Serialize for T
where T: Serialize + ?Sized,

Source§

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>

Source§

fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> ErasedDestructor for T
where T: 'static,