Skip to main content

pep_json

Macro pep_json 

Source
macro_rules! pep_json {
    ({ $($tt:tt)* }) => { ... };
    (@object $builder:ident, ) => { ... };
    (@object $builder:ident, $key:literal : pseudonym($value:expr)) => { ... };
    (@object $builder:ident, $key:literal : pseudonym($value:expr), $($rest:tt)*) => { ... };
    (@object $builder:ident, $key:literal : { $($inner:tt)* }) => { ... };
    (@object $builder:ident, $key:literal : { $($inner:tt)* }, $($rest:tt)*) => { ... };
    (@object $builder:ident, $key:literal : [ $($inner:tt)* ]) => { ... };
    (@object $builder:ident, $key:literal : [ $($inner:tt)* ], $($rest:tt)*) => { ... };
    (@object $builder:ident, $key:literal : $value:expr) => { ... };
    (@object $builder:ident, $key:literal : $value:expr, $($rest:tt)*) => { ... };
}
Expand description

Macro for creating PEPJSONValue objects with a JSON-like syntax.

Supports marking fields as pseudonyms using pseudonym("value") syntax. Creates an unencrypted PEPJSONValue which can then be encrypted.

§Example

use libpep::pep_json;
use serde_json::json;

let pep_value = pep_json!({
    "id": pseudonym("user1@example.com"),
    "age": 16,
    "verified": true,
    "scores": [88, 91, 85]
});

// Then encrypt it
let encrypted = encrypt(&pep_value, &keys, &mut rng);
let decrypted = decrypt(&encrypted, &keys)?;
assert_eq!(decrypted, json!({
    "id": "user1@example.com",
    "age": 16,
    "verified": true,
    "scores": [88, 91, 85]
}));