Implemented serialize and clone fot both TOTP and Algorithm. Only Algorithm is copy
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
diff --git a/Cargo.toml b/Cargo.toml
index f8fad4d..580c458 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "totp-rs"
-version = "0.2.2"
+version = "0.2.3"
authors = ["Cleo Rebert <cleo.rebert@gmail.com>"]
edition = "2018"
readme = "README.md"
@@ -12,6 +12,7 @@ keywords = ["authentification", "2fa", "totp", "hmac"]
categories = ["authentication", "web-programming"]
[dependencies]
+serde = { version = "1.0", features = ["derive"] }
ring = "0.16.12"
byteorder = "1.3.4"
otpauth = "0.4.1"
diff --git a/src/lib.rs b/src/lib.rs
index 039ee93..71413a6 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -15,6 +15,8 @@
//! println!("{}", token);
//! ```
+use serde::{Serialize, Deserialize};
+
use base32;
use byteorder::{BigEndian, ReadBytesExt};
use ring::hmac;
@@ -25,7 +27,7 @@ use image::Luma;
use qrcode::QrCode;
/// Algorithm enum holds the three standards algorithms for TOTP as per the [reference implementation](https://tools.ietf.org/html/rfc6238#appendix-A)
-#[derive(Debug)]
+#[derive(Debug, Serialize, Deserialize, Copy, Clone)]
pub enum Algorithm {
SHA1,
SHA256,
@@ -33,7 +35,7 @@ pub enum Algorithm {
}
/// TOTP holds informations as to how to generate an auth code and validate it. Its [secret](struct.TOTP.html#structfield.secret) field is sensitive data, treat it accordingly
-#[derive(Debug)]
+#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct TOTP {
/// SHA-1 is the most widespread algorithm used, and for totp pursposes, SHA-1 hash collisions are [not a problem](https://tools.ietf.org/html/rfc4226#appendix-B.2) as HMAC-SHA-1 is not impacted. It's also the main one cited in [rfc-6238](https://tools.ietf.org/html/rfc6238#section-3) even though the [reference implementation](https://tools.ietf.org/html/rfc6238#appendix-A) permits the use of SHA-1, SHA-256 and SHA-512. Not all clients support other algorithms then SHA-1
pub algorithm: Algorithm,