Skip to content

Commit f26efc5

Browse files
authored
Merge pull request #35 from Foundation-Devices/keycard-shard-improve
`backup-shard`: add `encode()` and `decode()` method for `Shard`
2 parents ee5db69 + c0f3448 commit f26efc5

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

backup-shard/src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,14 @@ impl Shard {
3939
hash_input.extend_from_slice(self.data().as_slice());
4040
hash_input
4141
}
42+
43+
/// Returns the encoded shard (official encoding is minicbor)
44+
pub fn encode(&self) -> Vec<u8> {
45+
minicbor::to_vec(self).unwrap()
46+
}
47+
48+
/// Returns the decoded shard (official encoding is minicbor)
49+
pub fn decode(data: &[u8]) -> Result<Shard, minicbor::decode::Error> {
50+
minicbor::decode(data)
51+
}
4252
}

0 commit comments

Comments
 (0)