Skip to content

Commit

Permalink
Add from_json_bytes method to KeyMeta
Browse files Browse the repository at this point in the history
  • Loading branch information
tgross35 committed Nov 15, 2023
1 parent cd3447d commit d2c23e6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/jose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,12 @@ impl KeyMeta {
serde_json::from_str(val).map_err(Into::into)
}

/// Deserialize this data from a JSON blob (this does the same as [`from_json`] but does not
/// require a UTF-8 `&str`).
pub fn from_json_bytes(val: &[u8]) -> Result<Self> {
serde_json::from_slice(val).map_err(Into::into)
}

/// Create a [`TangClient`] from the URL used to generate this key
pub fn client(&self, timeout: Option<Duration>) -> TangClient {
TangClient::new(&self.clevis.tang.url, timeout)
Expand Down
3 changes: 3 additions & 0 deletions tests/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,7 @@ fn test_roundtrip() {
let newkey = client.recover_secure_key::<10>(&new_meta).unwrap();

assert_eq!(encryption_key.as_bytes(), newkey.as_bytes());

// sanity check the bytes implementation
let new_meta = KeyMeta::from_json_bytes(&meta_str.as_bytes()).unwrap();
}

0 comments on commit d2c23e6

Please sign in to comment.