#[cfg(feature = "dev")]
use arbitrary::Arbitrary;
use crate::prelude::*;
#[derive(Debug, PartialEq, Eq, Clone)]
#[cfg_attr(feature = "dev", derive(Arbitrary))]
pub struct PossiblyAuthorisedEntry {
pub entry: Entry,
pub authorisation_token: AuthorisationToken,
}
impl PossiblyAuthorisedEntry {
pub fn new(entry: Entry, authorisation_token: AuthorisationToken) -> Self {
Self {
entry,
authorisation_token,
}
}
#[allow(clippy::result_large_err)]
pub fn into_authorised_entry(self) -> Result<AuthorisedEntry, Self> {
if self.authorisation_token.does_authorise(&self.entry) {
Ok(AuthorisedEntry {
entry: self.entry,
authorisation_token: self.authorisation_token,
})
} else {
Err(self)
}
}
pub unsafe fn into_authorised_entry_unchecked(self) -> AuthorisedEntry {
AuthorisedEntry {
entry: self.entry,
authorisation_token: self.authorisation_token,
}
}
}
impl Keylike for PossiblyAuthorisedEntry {
fn subspace_id(&self) -> &SubspaceId {
self.entry.subspace_id()
}
fn path(&self) -> &Path {
self.entry.path()
}
}
impl Coordinatelike for PossiblyAuthorisedEntry {
fn timestamp(&self) -> Timestamp {
self.entry.timestamp()
}
}
impl Namespaced for PossiblyAuthorisedEntry {
fn namespace_id(&self) -> &NamespaceId {
self.entry.namespace_id()
}
}
impl Entrylike for PossiblyAuthorisedEntry {
fn payload_length(&self) -> u64 {
self.entry.payload_length()
}
fn payload_digest(&self) -> &PayloadDigest {
self.entry.payload_digest()
}
}
#[derive(Debug, PartialEq, Eq, Clone)]
#[cfg_attr(feature = "dev", derive(Arbitrary))]
pub struct AuthorisedEntry {
entry: Entry,
authorisation_token: AuthorisationToken,
}
impl AuthorisedEntry {
pub fn into_parts(self) -> (Entry, AuthorisationToken) {
(self.entry, self.authorisation_token)
}
pub fn entry(&self) -> &Entry {
&self.entry
}
pub fn authorisation_token(&self) -> &AuthorisationToken {
&self.authorisation_token
}
}
impl Keylike for AuthorisedEntry {
fn subspace_id(&self) -> &SubspaceId {
self.entry.subspace_id()
}
fn path(&self) -> &Path {
self.entry.path()
}
}
impl Coordinatelike for AuthorisedEntry {
fn timestamp(&self) -> Timestamp {
self.entry.timestamp()
}
}
impl Namespaced for AuthorisedEntry {
fn namespace_id(&self) -> &NamespaceId {
self.entry.namespace_id()
}
}
impl Entrylike for AuthorisedEntry {
fn payload_length(&self) -> u64 {
self.entry.payload_length()
}
fn payload_digest(&self) -> &PayloadDigest {
self.entry.payload_digest()
}
}