-
Notifications
You must be signed in to change notification settings - Fork 0
feat(rust/signed-doc): Catalyst signed document encoding using minicbor #353
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
fe64ad9
dcc6355
cbf9fd9
767f754
4d6ec46
7e38804
fe74f8c
4bf7a43
577736c
d7a0d24
518944c
5239ac8
7867c32
8cb772d
0fc4b3a
5f6a855
7f4f979
1007bc9
b2de830
1d37c6f
5b209bb
49c860c
7f7847d
e00afc7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,33 +55,34 @@ impl<'de> Deserialize<'de> for ContentType { | |
} | ||
} | ||
|
||
impl From<ContentType> for CoapContentFormat { | ||
fn from(value: ContentType) -> Self { | ||
match value { | ||
ContentType::Cbor => Self::Cbor, | ||
ContentType::Json => Self::Json, | ||
} | ||
} | ||
} | ||
|
||
impl TryFrom<&coset::ContentType> for ContentType { | ||
type Error = anyhow::Error; | ||
|
||
fn try_from(value: &coset::ContentType) -> Result<Self, Self::Error> { | ||
let content_type = match value { | ||
coset::ContentType::Assigned(CoapContentFormat::Json) => ContentType::Json, | ||
coset::ContentType::Assigned(CoapContentFormat::Cbor) => ContentType::Cbor, | ||
_ => { | ||
match value { | ||
coset::ContentType::Assigned(CoapContentFormat::Json) => Ok(ContentType::Json), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The aim is to remove coset, is it not? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inside this PR, I've just removing coset for encoding functionality. Decoding would be done under the different PR |
||
coset::ContentType::Assigned(CoapContentFormat::Cbor) => Ok(ContentType::Cbor), | ||
coset::ContentType::Text(str) => str.parse(), | ||
coset::RegisteredLabel::Assigned(_) => { | ||
anyhow::bail!( | ||
"Unsupported Content Type {value:?}, Supported only: {:?}", | ||
"Unsupported Content Type: {value:?}, Supported only: {:?}", | ||
ContentType::VARIANTS | ||
.iter() | ||
.map(ToString::to_string) | ||
.collect::<Vec<_>>() | ||
) | ||
}, | ||
}; | ||
Ok(content_type) | ||
} | ||
} | ||
} | ||
|
||
impl minicbor::Encode<()> for ContentType { | ||
fn encode<W: minicbor::encode::Write>( | ||
&self, e: &mut minicbor::Encoder<W>, _ctx: &mut (), | ||
) -> Result<(), minicbor::encode::Error<W::Error>> { | ||
// encode as media types, not in CoAP Content-Formats | ||
e.str(self.to_string().as_str())?; | ||
Ok(()) | ||
} | ||
} | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.