-
Notifications
You must be signed in to change notification settings - Fork 0
feat(rust/signed-doc): CBOR encoder using minicbor #351
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
Closed
Closed
Changes from 8 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
9db5fe2
content type fix & encoding/decoding
no30bit 88f75d7
fix docs
no30bit 617a07f
enc/dec for doc ref
no30bit 1192b90
protected header & builder
no30bit 9a5e9d0
adding signatures
no30bit 322fcf6
encode the document
no30bit a4b821b
cspell
no30bit 843299c
merge upstream
no30bit b78ed40
split CoseSign building
no30bit 53cb828
move to mod.rs
no30bit 63208f7
rm dead code
no30bit 57f2e23
upd Cargo.toml
no30bit 52fc974
Merge branch 'feat/minicbor-cose-encoder-components' into feat/minicb…
no30bit fcd6b54
wip
no30bit d397a3a
fmt
no30bit 2eb553b
encode content type, fixes
no30bit e97bd3c
remove accidental change
no30bit 1515bb7
fmt
no30bit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -326,3 +326,4 @@ xprivate | |
XPRV | ||
xpub | ||
yoroi | ||
bytewise |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
use std::collections::BTreeMap; | ||
|
||
use super::EncodeError; | ||
|
||
/// A map of CBOR encoded key-value pairs with **bytewise** lexicographic key ordering. | ||
#[derive(Debug, Default)] | ||
pub struct CborMap(BTreeMap<Vec<u8>, Vec<u8>>); | ||
no30bit marked this conversation as resolved.
Show resolved
Hide resolved
no30bit marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
impl CborMap { | ||
/// Creates an empty map. | ||
#[must_use] | ||
pub fn new() -> Self { | ||
Self::default() | ||
} | ||
|
||
/// A number of entries in a map. | ||
pub fn len(&self) -> usize { | ||
self.0.len() | ||
} | ||
|
||
/// Is there no entries in the map. | ||
pub fn is_empty(&self) -> bool { | ||
self.len() == 0 | ||
} | ||
|
||
/// Encodes a key-value pair to CBOR and then inserts it into the map. | ||
/// | ||
/// If the map did not have this key present, [`None`] is returned. | ||
/// | ||
/// If the map did have this key present, the value is updated, and the old | ||
/// CBOR-encoded value is returned. | ||
pub fn encode_and_insert<C, K: minicbor::Encode<C>, V: minicbor::Encode<C>>( | ||
&mut self, ctx: &mut C, key: K, v: V, | ||
) -> Result<Option<Vec<u8>>, EncodeError> { | ||
let (encoded_key, encoded_v) = ( | ||
minicbor::to_vec_with(key, ctx)?, | ||
minicbor::to_vec_with(v, ctx)?, | ||
); | ||
Ok(self.0.insert(encoded_key, encoded_v)) | ||
} | ||
|
||
/// Iterate over CBOR-encoded key-value pairs. | ||
/// Items are returned in **bytewise** lexicographic key ordering. | ||
pub fn iter(&self) -> impl Iterator<Item = (&[u8], &[u8])> { | ||
self.0 | ||
.iter() | ||
.map(|(key_vec, value_vec)| (key_vec.as_slice(), value_vec.as_slice())) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.