From 95f1272e11361d83067025b532cda61e5b5023d3 Mon Sep 17 00:00:00 2001 From: realaravinth Date: Fri, 12 Mar 2021 13:52:49 +0530 Subject: [PATCH] serialize and deserialize impls --- CHANGELOG.md | 1 + Cargo.lock | 2 +- src/cache/mod.rs | 3 ++- src/defense.rs | 5 +++-- src/pow.rs | 6 +++--- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0717770..d3ce2bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,2 +1,3 @@ # 0.1.1 - typo fix: `MCaptcha::decrement_visiotr()` became `MCaptcha::decrement_visitor()` +- `serde::{Serialize, Deserialize}` impls (shouldn't break anything) diff --git a/Cargo.lock b/Cargo.lock index c4dc2c8..e46cc2d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -570,7 +570,7 @@ dependencies = [ [[package]] name = "m_captcha" -version = "0.1.0" +version = "0.1.1" dependencies = [ "actix", "actix-rt", diff --git a/src/cache/mod.rs b/src/cache/mod.rs index f3c0ff8..f43370d 100644 --- a/src/cache/mod.rs +++ b/src/cache/mod.rs @@ -31,13 +31,14 @@ pub mod messages { //! Messages that can be sent to cache data structures implementing [Save][super::Save] use actix::dev::*; use derive_builder::Builder; + use serde::{Deserialize, Serialize}; use crate::errors::*; use crate::mcaptcha::VisitorResult; use crate::pow::PoWConfig; /// Message to cache PoW difficulty factor and string - #[derive(Message, Builder)] + #[derive(Message, Serialize, Deserialize, Builder)] #[rtype(result = "CaptchaResult<()>")] pub struct Cache { pub string: String, diff --git a/src/defense.rs b/src/defense.rs index ae79b22..a985ea9 100644 --- a/src/defense.rs +++ b/src/defense.rs @@ -43,9 +43,10 @@ //! ``` use crate::errors::*; +use serde::{Deserialize, Serialize}; /// Level struct that describes threshold-difficulty factor mapping -#[derive(Debug, Copy, Clone, PartialEq)] +#[derive(Debug, Deserialize, Serialize, Copy, Clone, PartialEq)] pub struct Level { visitor_threshold: u32, difficulty_factor: u32, @@ -106,7 +107,7 @@ impl LevelBuilder { } /// struct describes all the different [Level]s at which an mCaptcha system operates -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)] pub struct Defense { levels: Vec, // index of current visitor threshold diff --git a/src/pow.rs b/src/pow.rs index a3e3b83..abcc428 100644 --- a/src/pow.rs +++ b/src/pow.rs @@ -18,12 +18,12 @@ //! PoW datatypes used in client-server interaction use pow_sha256::PoW; -use serde::Serialize; +use serde::{Deserialize, Serialize}; pub use pow_sha256::ConfigBuilder; /// PoW requirement datatype that is be sent to clients for generating PoW -#[derive(Clone, Serialize, Debug)] +#[derive(Clone, Serialize, Deserialize, Debug)] pub struct PoWConfig { pub string: String, pub difficulty_factor: u32, @@ -41,7 +41,7 @@ impl PoWConfig { } /// PoW datatype that clients send to server -#[derive(Clone, Serialize, Debug)] +#[derive(Clone, Serialize, Deserialize, Debug)] pub struct Work { pub string: String, pub result: String,