Crates.io | zeronet_sign |
lib.rs | zeronet_sign |
version | 0.1.9 |
source | src |
created_at | 2021-12-29 00:31:30.93652 |
updated_at | 2021-12-29 00:31:30.93652 |
description | ZeroNet content signing |
homepage | http://www.github.com/Anshorei/zeronet_cryptography |
repository | http://www.github.com/Anshorei/zeronet_cryptography |
max_upload_size | |
id | 504531 |
size | 5,128 |
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());
}