runar-serializer-macros
Derive and helper procedural macros for runar-serializer.
What it provides
#[derive(Encrypt)]: Generates a companion encrypted struct and helper methods to selectively encrypt/decrypt fields.#[derive(Plain)]: Implements zero-copy conversions between your types andrunar_serializer::ArcValuefor efficient serialization.
Install
[]
= "0.1"
Encrypt derive
Annotate a struct with #[derive(Encrypt)] and mark fields with zones:
#[runar(user)]: encrypted for the user profile key(s)#[runar(system)]: encrypted for the network/system key#[runar(search)]: a search index copy (encrypted) for search contexts#[runar(system_only)]: only available to the system/network context
Example based on real tests:
use Encrypt;
// Generated by the macro:
// - EncryptedProfile: encrypted form
// - Profile::encrypt_with_keystore(&self, ks: &dyn EnvelopeCrypto, res: &dyn LabelResolver)
// - EncryptedProfile::decrypt_with_keystore(&self, ks: &dyn EnvelopeCrypto)
End-to-end usage (abridged)
use Arc;
use ;
use ;
use ;
// Prepare keystores and label resolver
let logger = new;
let mut network_master = new?;
let network_id = network_master.generate_network_data_key?;
let network_pub = network_master.get_network_public_key?;
let mut user_mobile = new?;
user_mobile.initialize_user_root_key?;
let profile_pk = user_mobile.derive_user_profile_key?;
user_mobile.install_network_public_key?;
let mut node = new?;
let token = node.generate_csr?;
let nk_msg = network_master.create_network_key_message?;
node.install_network_key?;
let resolver = new;
// Encrypt/decrypt using the generated helpers
let mobile_ks = new as ;
let node_ks = new as ;
let profile = Profile ;
let encrypted: EncryptedProfile = profile.encrypt_with_keystore?;
let decrypted_for_mobile = encrypted.decrypt_with_keystore?;
let decrypted_for_node = encrypted.decrypt_with_keystore?;
// Integrate with ArcValue and optional encryption during serialization
let ctx = SerializationContext ;
let av = new_struct;
assert_eq!;
let ser = av.serialize?; // encrypted serialization
let de = deserialize?; // decrypt with node keystore
Plain derive
#[derive(Plain)] adds efficient conversions to/from ArcValue without manual glue.
use Plain;
License
MIT. See LICENSE.