1 unstable release
0.1.9 | Dec 29, 2021 |
---|
#5 in #zero-net
Used in zeronet_sign_derive
17KB
268 lines
Zeronet Sign
Easily make rust structures signable as ZeroNet content files
use serde_derive::{Serialize, Deserialize};
use zeronet_sign::Sign;
use zeronet_sign_derive::*;
use zeronet_cryptography;
pub fn is_default<T: Default + PartialEq>(t: &T) -> bool {
t == &T::default()
}
#[derive(Serialize, Deserialize, Sign, Default)]
struct MyStruct {
data: String,
#[serde(skip_serializing_if = "is_default")]
#[sign(signature)]
sign: String,
#[sign(skip)]
skipped_field: bool,
}
fn main () {
let mut my_struct = MyStruct {
data: "random_data".to_string(),
sign: String::new(),
skipped_field: true,
};
let key = "5KYZdUEo39z3FPrtuX2QbbwGnNP5zTd7yyr2SC1j299sBCnWjss";
let result = my_struct.sign(key);
assert!(result.is_ok());
}
Dependencies
~10MB
~141K SLoC