safe_nd/messaging/
blob.rs1use super::{AuthorisationKind, CmdError, DataAuthKind, QueryResponse};
11use crate::{Blob, BlobAddress, Error, XorName};
12use serde::{Deserialize, Serialize};
13use std::fmt;
14
15#[derive(Hash, Eq, PartialEq, PartialOrd, Clone, Serialize, Deserialize)]
17pub enum BlobRead {
18 Get(BlobAddress),
20}
21
22#[allow(clippy::large_enum_variant)]
24#[derive(Hash, Eq, PartialEq, PartialOrd, Clone, Serialize, Deserialize)]
25pub enum BlobWrite {
26 New(Blob),
28 DeletePrivate(BlobAddress),
30}
31
32impl BlobRead {
33 pub fn error(&self, error: Error) -> QueryResponse {
45 QueryResponse::GetBlob(Err(error))
46 }
47
48 pub fn authorisation_kind(&self) -> AuthorisationKind {
50 use BlobRead::*;
51 match self {
52 Get(BlobAddress::Public(_)) => AuthorisationKind::Data(DataAuthKind::PublicRead),
53 Get(BlobAddress::Private(_)) => AuthorisationKind::Data(DataAuthKind::PrivateRead),
54 }
55 }
56
57 pub fn dst_address(&self) -> XorName {
59 use BlobRead::*;
60 match self {
61 Get(ref address) => *address.name(),
62 }
63 }
64}
65
66impl BlobWrite {
67 pub fn error(&self, error: Error) -> CmdError {
70 CmdError::Data(error)
71 }
72
73 pub fn authorisation_kind(&self) -> AuthorisationKind {
75 AuthorisationKind::Data(DataAuthKind::Write)
76 }
77
78 pub fn dst_address(&self) -> XorName {
80 use BlobWrite::*;
81 match self {
82 New(ref data) => *data.name(),
83 DeletePrivate(ref address) => *address.name(),
84 }
85 }
86}
87
88impl fmt::Debug for BlobRead {
89 fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
90 use BlobRead::*;
91 match self {
92 Get(req) => write!(formatter, "{:?}", req),
93 }
94 }
95}
96
97impl fmt::Debug for BlobWrite {
98 fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
99 use BlobWrite::*;
100 match self {
101 New(req) => write!(formatter, "{:?}", req),
102 DeletePrivate(req) => write!(formatter, "{:?}", req),
103 }
104 }
105}