Skip to content

Commit ba2eaba

Browse files
committed
feat: initial chain
1 parent b1136bb commit ba2eaba

File tree

4 files changed

+27
-9
lines changed

4 files changed

+27
-9
lines changed

rust/signed_doc/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ use cbork_utils::{array::Array, decode_context::DecodeCtx, with_cbor_bytes::With
2424
pub use content::Content;
2525
use decode_context::{CompatibilityPolicy, DecodeContext};
2626
pub use metadata::{
27-
ContentEncoding, ContentType, DocLocator, DocType, DocumentRef, DocumentRefs, Metadata, Section,
27+
Chain, ContentEncoding, ContentType, DocLocator, DocType, DocumentRef, DocumentRefs, Metadata,
28+
Section,
2829
};
2930
use minicbor::{decode, encode, Decode, Decoder, Encode};
3031
pub use signature::{CatalystId, Signatures};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//! Document Payload Chain.
2+
3+
use std::hash::Hash;
4+
5+
/// Document type - `Chain`.
6+
#[derive(Clone, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
7+
pub struct Chain;

rust/signed_doc/src/metadata/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::{
44
fmt::{Display, Formatter},
55
};
66

7+
mod chain;
78
mod collaborators;
89
mod content_encoding;
910
mod content_type;
@@ -13,6 +14,7 @@ mod section;
1314
mod supported_field;
1415

1516
use catalyst_types::{catalyst_id::CatalystId, problem_report::ProblemReport, uuid::UuidV7};
17+
pub use chain::Chain;
1618
pub use content_encoding::ContentEncoding;
1719
pub use content_type::ContentType;
1820
pub use doc_type::DocType;

rust/signed_doc/src/metadata/supported_field.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use serde::Deserialize;
77
use strum::{EnumDiscriminants, EnumTryAs, IntoDiscriminant as _};
88

99
use crate::{
10-
metadata::collaborators::Collaborators, ContentEncoding, ContentType, DocType, DocumentRefs,
11-
Section,
10+
metadata::collaborators::Collaborators, Chain, ContentEncoding, ContentType, DocType,
11+
DocumentRefs, Section,
1212
};
1313

1414
/// COSE label. May be either a signed integer or a string.
@@ -100,18 +100,20 @@ pub(crate) enum SupportedField {
100100
Ver(UuidV7) = 3,
101101
/// `type` field.
102102
Type(DocType) = 4,
103+
/// `chain` field.
104+
Chain(Chain) = 5,
103105
/// `reply` field.
104-
Reply(DocumentRefs) = 5,
106+
Reply(DocumentRefs) = 6,
105107
/// `section` field.
106-
Section(Section) = 6,
108+
Section(Section) = 7,
107109
/// `template` field.
108-
Template(DocumentRefs) = 7,
110+
Template(DocumentRefs) = 8,
109111
/// `parameters` field.
110-
Parameters(DocumentRefs) = 8,
112+
Parameters(DocumentRefs) = 9,
111113
/// `collaborators` field.
112-
Collaborators(Collaborators) = 9,
114+
Collaborators(Collaborators) = 10,
113115
/// `Content-Encoding` field.
114-
ContentEncoding(ContentEncoding) = 10,
116+
ContentEncoding(ContentEncoding) = 11,
115117
}
116118

117119
impl SupportedLabel {
@@ -124,6 +126,7 @@ impl SupportedLabel {
124126
Label::Str("ref") => Some(Self::Ref),
125127
Label::Str("ver") => Some(Self::Ver),
126128
Label::Str("type") => Some(Self::Type),
129+
Label::Str("chain") => Some(Self::Chain),
127130
Label::Str("reply") => Some(Self::Reply),
128131
Label::Str("collaborators") => Some(Self::Collaborators),
129132
Label::Str("section") => Some(Self::Section),
@@ -146,6 +149,7 @@ impl SupportedLabel {
146149
Self::Ref => Label::Str("ref"),
147150
Self::Ver => Label::Str("ver"),
148151
Self::Type => Label::Str("type"),
152+
Self::Chain => Label::Str("chain"),
149153
Self::Reply => Label::Str("reply"),
150154
Self::Collaborators => Label::Str("collaborators"),
151155
Self::Section => Label::Str("section"),
@@ -179,6 +183,7 @@ impl serde::ser::Serialize for SupportedField {
179183
match self {
180184
Self::Id(v) | Self::Ver(v) => v.serialize(serializer),
181185
Self::Type(v) => v.serialize(serializer),
186+
Self::Chain(v) => v.serialize(serializer),
182187
Self::ContentType(v) => v.serialize(serializer),
183188
Self::ContentEncoding(v) => v.serialize(serializer),
184189
Self::Ref(v) | Self::Reply(v) | Self::Template(v) | Self::Parameters(v) => {
@@ -205,6 +210,7 @@ impl<'de> serde::de::DeserializeSeed<'de> for SupportedLabel {
205210
SupportedLabel::Ref => Deserialize::deserialize(d).map(SupportedField::Ref),
206211
SupportedLabel::Ver => Deserialize::deserialize(d).map(SupportedField::Ver),
207212
SupportedLabel::Type => Deserialize::deserialize(d).map(SupportedField::Type),
213+
SupportedLabel::Chain => Deserialize::deserialize(d).map(SupportedField::Chain),
208214
SupportedLabel::Reply => Deserialize::deserialize(d).map(SupportedField::Reply),
209215
SupportedLabel::Collaborators => {
210216
Deserialize::deserialize(d).map(SupportedField::Collaborators)
@@ -253,6 +259,7 @@ impl minicbor::Decode<'_, crate::decode_context::DecodeContext> for Option<Suppo
253259
.map(SupportedField::Ver)
254260
},
255261
SupportedLabel::Type => d.decode().map(SupportedField::Type),
262+
SupportedLabel::Chain => d.decode().map(SupportedField::Chain),
256263
SupportedLabel::Reply => {
257264
d.decode_with(&mut ctx.policy().clone())
258265
.map(SupportedField::Reply)
@@ -314,6 +321,7 @@ impl minicbor::Encode<()> for SupportedField {
314321
| SupportedField::Template(document_ref)
315322
| SupportedField::Parameters(document_ref) => document_ref.encode(e, ctx),
316323
SupportedField::Type(doc_type) => doc_type.encode(e, ctx),
324+
SupportedField::Chain(chain) => chain.encode(e, ctx),
317325
SupportedField::Collaborators(collaborators) => collaborators.encode(e, ctx),
318326
SupportedField::Section(section) => section.encode(e, ctx),
319327
SupportedField::ContentEncoding(content_encoding) => content_encoding.encode(e, ctx),

0 commit comments

Comments
 (0)