Skip to content

Commit

Permalink
data visibility (#127)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasoncolburne authored Mar 10, 2023
1 parent c95a38e commit 3cf0a18
Show file tree
Hide file tree
Showing 11 changed files with 292 additions and 311 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cesride"
version = "0.2.2"
version = "0.3.0"
edition = "2021"
description = "Cryptographic primitives for use with Composable Event Streaming Representation (CESR)"
license = "Apache-2.0"
Expand Down
28 changes: 13 additions & 15 deletions src/core/common.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::data::{data, Data, Value};
use crate::data::{dat, Value};
use crate::error::{err, Error, Result};

use lazy_static::lazy_static;
Expand Down Expand Up @@ -209,7 +209,7 @@ pub(crate) fn sizeify(ked: &Value, kind: Option<&str>) -> Result<SizeifyResult>
}

let mut ked = ked.clone();
ked["v"] = data!(&vs);
ked["v"] = dat!(&vs);

Ok(SizeifyResult { raw, ident: result.ident, kind, ked, version: result.version })
}
Expand Down Expand Up @@ -314,48 +314,46 @@ pub(crate) fn sniff(raw: &[u8]) -> Result<SniffResult> {
#[cfg(test)]
mod test {
use crate::core::common;
use crate::data::{data, Data};
use crate::data::dat;
use rstest::rstest;

#[test]
fn loads() {
let raw = &data!({}).to_json().unwrap().as_bytes().to_vec();
let raw = &dat!({}).to_json().unwrap().as_bytes().to_vec();
assert!(common::loads(raw, None, None).is_ok());
}

#[test]
fn sniff_unhappy_paths() {
assert!(common::sniff(&[]).is_err()); // minimum 29 octets
assert!(common::sniff(
&data!({"v":"version string must be valid!"}).to_json().unwrap().as_bytes()
&dat!({"v":"version string must be valid!"}).to_json().unwrap().as_bytes()
)
.is_err());
assert!(common::sniff(
&data!({"i":"needs to start within 12 characters!","v":"KERI10JSON000000_"})
&dat!({"i":"needs to start within 12 characters!","v":"KERI10JSON000000_"})
.to_json()
.unwrap()
.as_bytes()
)
.is_err());
assert!(common::sniff(&data!({"v":"KERI10ABCD000000_","confusing but necessary filler":"hmm...maybe a 12 octet magic prefix?"}).to_json().unwrap().as_bytes()).is_err());
assert!(common::sniff(&dat!({"v":"KERI10ABCD000000_","confusing but necessary filler":"hmm...maybe a 12 octet magic prefix?"}).to_json().unwrap().as_bytes()).is_err());
// needs to have a valid serialization kind
}

#[test]
fn loads_unhappy_paths() {
let raw = &data!({}).to_json().unwrap().as_bytes().to_vec();
let raw = &dat!({}).to_json().unwrap().as_bytes().to_vec();
assert!(common::loads(raw, None, Some("CESR")).is_err());
assert!(common::loads(raw, Some(1024), Some("CESR")).is_err());
}

#[test]
fn sizeify_unhappy_paths() {
assert!(common::sizeify(&data!({}), None).is_err());
assert!(common::sizeify(&data!({"v":"KERIffJSON000000_"}), None).is_err());
assert!(common::sizeify(&data!({"v":"KERI10JSON000000_"}), Some("CESR")).is_err());
assert!(
common::sizeify(&data!({"i":"filler entry","v":"KERI10JSON000000_"}), None).is_err()
);
assert!(common::sizeify(&dat!({}), None).is_err());
assert!(common::sizeify(&dat!({"v":"KERIffJSON000000_"}), None).is_err());
assert!(common::sizeify(&dat!({"v":"KERI10JSON000000_"}), Some("CESR")).is_err());
assert!(common::sizeify(&dat!({"i":"filler entry","v":"KERI10JSON000000_"}), None).is_err());
}

#[test]
Expand All @@ -373,6 +371,6 @@ mod test {

#[test]
fn dumps_unhappy_paths() {
assert!(common::dumps(&data!({}), Some("CESR")).is_err());
assert!(common::dumps(&dat!({}), Some("CESR")).is_err());
}
}
Loading

0 comments on commit 3cf0a18

Please sign in to comment.