Implemented serialize and clone fot both TOTP and Algorithm. Only Algorithm is copy

This commit is contained in:
Cleo Rebert 2020-04-14 12:51:22 +02:00
parent c9b81c70c1
commit 9064404264
2 changed files with 6 additions and 3 deletions

View File

@ -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"

View File

@ -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,