Commit 608b6f28963f3efcc1e127b678cd3ff03d2f0431

Cléo Rebert 2022-12-22T16:40:19

Merge pull request #40 from tmpfs/zeroize Support zeroize feature.

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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
diff --git a/Cargo.toml b/Cargo.toml
index 4268802..235d25b 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -20,6 +20,7 @@ otpauth = ["url", "urlencoding"]
 qr = ["qrcodegen", "image", "base64", "otpauth"]
 serde_support = ["serde"]
 gen_secret = ["rand"]
+zeroize = ["dep:zeroize"]
 
 [dependencies]
 serde = { version = "1.0", features = ["derive"], optional = true }
@@ -33,4 +34,5 @@ constant_time_eq = "~0.2.1"
 qrcodegen = { version = "~1.8", optional = true }
 image = { version = "~0.24.2", features = ["png"], optional = true, default-features = false}
 base64 = { version = "~0.13", optional = true }
-rand = { version = "~0.8.5", features = ["std_rng", "std"], optional = true, default-features = false }
\ No newline at end of file
+rand = { version = "~0.8.5", features = ["std_rng", "std"], optional = true, default-features = false }
+zeroize = { version = "1.5.7", features = ["alloc", "derive"], optional = true }
\ No newline at end of file
diff --git a/README.md b/README.md
index ec36ab6..7aea502 100644
--- a/README.md
+++ b/README.md
@@ -17,6 +17,8 @@ With optional feature "otpauth", support parsing the TOTP parameters from an `ot
 With optional feature "serde_support", library-defined types `TOTP` and `Algorithm` and will be Deserialize-able and Serialize-able.
 ### gen_secret
 With optional feature "gen_secret", a secret will be generated for you to store in database.
+### zeroize
+Securely zero secret information when the TOTP struct is dropped.
 
 
 # Examples
diff --git a/examples/rfc-6238.rs b/examples/rfc-6238.rs
index 0dc9912..eefe4ed 100644
--- a/examples/rfc-6238.rs
+++ b/examples/rfc-6238.rs
@@ -2,7 +2,7 @@ use totp_rs::{Rfc6238, TOTP};
 
 #[cfg(feature = "otpauth")]
 fn main() {
-    let mut rfc = Rfc6238::with_defaults("totp-sercret-123").unwrap();
+    let mut rfc = Rfc6238::with_defaults("totp-sercret-123".as_bytes().to_vec()).unwrap();
 
     // optional, set digits, issuer, account_name
     rfc.digits(8).unwrap();
diff --git a/examples/ttl.rs b/examples/ttl.rs
index 3de5891..806f6c4 100644
--- a/examples/ttl.rs
+++ b/examples/ttl.rs
@@ -2,7 +2,7 @@ use totp_rs::{Algorithm, TOTP};
 
 #[cfg(not(feature = "otpauth"))]
 fn main() {
-    let totp = TOTP::new(Algorithm::SHA1, 6, 1, 30, "my-secret".to_string()).unwrap();
+    let totp = TOTP::new(Algorithm::SHA1, 6, 1, 30, "my-secret".as_bytes().to_vec()).unwrap();
 
     loop {
         println!(
@@ -22,7 +22,7 @@ fn main() {
         6,
         1,
         30,
-        "my-secret".to_string(),
+        "my-secret".as_bytes().to_vec(),
         Some("Github".to_string()),
         "constantoine@github.com".to_string(),
     )
diff --git a/src/lib.rs b/src/lib.rs
index 3b1a9d4..6fe89f9 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -36,7 +36,7 @@
 //!     6,
 //!     1,
 //!     30,
-//!     "supersecret_topsecret",
+//!     "supersecret_topsecret".as_bytes().to_vec(),
 //!     Some("Github".to_string()),
 //!     "constantoine@github.com".to_string(),
 //! ).unwrap();
@@ -126,8 +126,10 @@ fn system_time() -> Result<u64, SystemTimeError> {
 /// 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, Clone)]
 #[cfg_attr(feature = "serde_support", derive(Serialize, Deserialize))]
-pub struct TOTP<T = Vec<u8>> {
+#[cfg_attr(feature = "zeroize", derive(zeroize::Zeroize, zeroize::ZeroizeOnDrop))]
+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
+    #[cfg_attr(feature = "zeroize", zeroize(skip))]
     pub algorithm: Algorithm,
     /// The number of digits composing the auth code. Per [rfc-4226](https://tools.ietf.org/html/rfc4226#section-5.3), this can oscilate between 6 and 8 digits
     pub digits: usize,
@@ -138,7 +140,7 @@ pub struct TOTP<T = Vec<u8>> {
     /// As per [rfc-4226](https://tools.ietf.org/html/rfc4226#section-4) the secret should come from a strong source, most likely a CSPRNG. It should be at least 128 bits, but 160 are recommended
     ///
     /// non-encoded value
-    pub secret: T,
+    pub secret: Vec<u8>,
     #[cfg(feature = "otpauth")]
     /// The "Github" part of "Github:constantoine@github.com". Must not contain a colon `:`
     /// For example, the name of your service/website.
@@ -150,7 +152,7 @@ pub struct TOTP<T = Vec<u8>> {
     pub account_name: String,
 }
 
-impl<T: AsRef<[u8]>> PartialEq for TOTP<T> {
+impl PartialEq for TOTP {
     /// Will not check for issuer and account_name equality
     /// As they aren't taken in account for token generation/token checking
     fn eq(&self, other: &Self) -> bool {
@@ -226,7 +228,7 @@ impl Default for TOTP {
     }
 }
 
-impl<T: AsRef<[u8]>> TOTP<T> {
+impl TOTP {
     #[cfg(feature = "otpauth")]
     /// Will create a new instance of TOTP with given parameters. See [the doc](struct.TOTP.html#fields) for reference as to how to choose those values
     ///
@@ -251,10 +253,10 @@ impl<T: AsRef<[u8]>> TOTP<T> {
         digits: usize,
         skew: u8,
         step: u64,
-        secret: T,
+        secret: Vec<u8>,
         issuer: Option<String>,
         account_name: String,
-    ) -> Result<TOTP<T>, TotpUrlError> {
+    ) -> Result<TOTP, TotpUrlError> {
         crate::rfc::assert_digits(&digits)?;
         crate::rfc::assert_secret_length(secret.as_ref())?;
         if issuer.is_some() && issuer.as_ref().unwrap().contains(':') {
@@ -314,7 +316,7 @@ impl<T: AsRef<[u8]>> TOTP<T> {
     /// # Errors
     ///
     /// Will return an error in case issuer or label contain the character ':'
-    pub fn from_rfc6238(rfc: Rfc6238<T>) -> Result<TOTP<T>, TotpUrlError> {
+    pub fn from_rfc6238(rfc: Rfc6238) -> Result<TOTP, TotpUrlError> {
         TOTP::try_from(rfc)
     }
 
@@ -395,7 +397,7 @@ impl<T: AsRef<[u8]>> TOTP<T> {
 
     /// Generate a TOTP from the standard otpauth URL
     #[cfg(feature = "otpauth")]
-    pub fn from_url<S: AsRef<str>>(url: S) -> Result<TOTP<Vec<u8>>, TotpUrlError> {
+    pub fn from_url<S: AsRef<str>>(url: S) -> Result<TOTP, TotpUrlError> {
         let url = Url::parse(url.as_ref()).map_err(TotpUrlError::Url)?;
         if url.scheme() != "otpauth" {
             return Err(TotpUrlError::Scheme(url.scheme().to_string()));
@@ -615,7 +617,7 @@ mod tests {
             6,
             1,
             1,
-            "TestSecretSuperSecret",
+            "TestSecretSuperSecret".as_bytes().to_vec(),
             Some("Github:".to_string()),
             "constantoine@github.com".to_string(),
         );
@@ -631,7 +633,7 @@ mod tests {
             6,
             1,
             1,
-            "TestSecretSuperSecret",
+            "TestSecretSuperSecret".as_bytes().to_vec(),
             Some("Github".to_string()),
             "constantoine:github.com".to_string(),
         );
@@ -647,7 +649,7 @@ mod tests {
             6,
             1,
             1,
-            "TestSecretSuperSecret",
+            "TestSecretSuperSecret".as_bytes().to_vec(),
             None,
             "constantoine:github.com".to_string(),
         );
@@ -663,7 +665,7 @@ mod tests {
             6,
             1,
             1,
-            "TestSecretSuperSecret",
+            "TestSecretSuperSecret".as_bytes().to_vec(),
             Some("Github".to_string()),
             "constantoine@github.com".to_string(),
         )
@@ -673,7 +675,7 @@ mod tests {
             6,
             1,
             1,
-            "TestSecretSuperSecret",
+            "TestSecretSuperSecret".as_bytes().to_vec(),
             Some("Github".to_string()),
             "constantoine@github.com".to_string(),
         )
@@ -729,7 +731,7 @@ mod tests {
             6,
             1,
             1,
-            "TestSecretSuperSecret",
+            "TestSecretSuperSecret".as_bytes().to_vec(),
             None,
             "constantoine@github.com".to_string(),
         )
@@ -746,7 +748,7 @@ mod tests {
             6,
             1,
             1,
-            "TestSecretSuperSecret",
+            "TestSecretSuperSecret".as_bytes().to_vec(),
             Some("Github".to_string()),
             "constantoine@github.com".to_string(),
         )
@@ -763,7 +765,7 @@ mod tests {
             6,
             1,
             1,
-            "TestSecretSuperSecret",
+            "TestSecretSuperSecret".as_bytes().to_vec(),
             Some("Github".to_string()),
             "constantoine@github.com".to_string(),
         )
@@ -780,7 +782,7 @@ mod tests {
             6,
             1,
             1,
-            "TestSecretSuperSecret",
+            "TestSecretSuperSecret".as_bytes().to_vec(),
             Some("Github".to_string()),
             "constantoine@github.com".to_string(),
         )
@@ -806,7 +808,7 @@ mod tests {
             6,
             1,
             1,
-            "TestSecretSuperSecret",
+            "TestSecretSuperSecret".as_bytes().to_vec(),
             Some("Github".to_string()),
             "constantoine@github.com".to_string(),
         )
@@ -905,19 +907,19 @@ mod tests {
     #[test]
     #[cfg(feature = "otpauth")]
     fn from_url_err() {
-        assert!(TOTP::<Vec<u8>>::from_url("otpauth://hotp/123").is_err());
-        assert!(TOTP::<Vec<u8>>::from_url("otpauth://totp/GitHub:test").is_err());
-        assert!(TOTP::<Vec<u8>>::from_url(
+        assert!(TOTP::from_url("otpauth://hotp/123").is_err());
+        assert!(TOTP::from_url("otpauth://totp/GitHub:test").is_err());
+        assert!(TOTP::from_url(
             "otpauth://totp/GitHub:test:?secret=ABC&digits=8&period=60&algorithm=SHA256"
         )
         .is_err());
-        assert!(TOTP::<Vec<u8>>::from_url("otpauth://totp/Github:constantoine%40github.com?issuer=GitHub&secret=KRSXG5CTMVRXEZLUKN2XAZLSKNSWG4TFOQ&digits=6&algorithm=SHA1").is_err())
+        assert!(TOTP::from_url("otpauth://totp/Github:constantoine%40github.com?issuer=GitHub&secret=KRSXG5CTMVRXEZLUKN2XAZLSKNSWG4TFOQ&digits=6&algorithm=SHA1").is_err())
     }
 
     #[test]
     #[cfg(feature = "otpauth")]
     fn from_url_default() {
-        let totp = TOTP::<Vec<u8>>::from_url(
+        let totp = TOTP::from_url(
             "otpauth://totp/GitHub:test?secret=KRSXG5CTMVRXEZLUKN2XAZLSKNSWG4TFOQ",
         )
         .unwrap();
@@ -938,7 +940,7 @@ mod tests {
     #[test]
     #[cfg(feature = "otpauth")]
     fn from_url_query() {
-        let totp = TOTP::<Vec<u8>>::from_url("otpauth://totp/GitHub:test?secret=KRSXG5CTMVRXEZLUKN2XAZLSKNSWG4TFOQ&digits=8&period=60&algorithm=SHA256").unwrap();
+        let totp = TOTP::from_url("otpauth://totp/GitHub:test?secret=KRSXG5CTMVRXEZLUKN2XAZLSKNSWG4TFOQ&digits=8&period=60&algorithm=SHA256").unwrap();
         assert_eq!(
             totp.secret,
             base32::decode(
@@ -956,7 +958,7 @@ mod tests {
     #[test]
     #[cfg(feature = "otpauth")]
     fn from_url_query_sha512() {
-        let totp = TOTP::<Vec<u8>>::from_url("otpauth://totp/GitHub:test?secret=KRSXG5CTMVRXEZLUKN2XAZLSKNSWG4TFOQ&digits=8&period=60&algorithm=SHA512").unwrap();
+        let totp = TOTP::from_url("otpauth://totp/GitHub:test?secret=KRSXG5CTMVRXEZLUKN2XAZLSKNSWG4TFOQ&digits=8&period=60&algorithm=SHA512").unwrap();
         assert_eq!(
             totp.secret,
             base32::decode(
@@ -974,13 +976,13 @@ mod tests {
     #[test]
     #[cfg(feature = "otpauth")]
     fn from_url_to_url() {
-        let totp = TOTP::<Vec<u8>>::from_url("otpauth://totp/Github:constantoine%40github.com?issuer=Github&secret=KRSXG5CTMVRXEZLUKN2XAZLSKNSWG4TFOQ&digits=6&algorithm=SHA1").unwrap();
+        let totp = TOTP::from_url("otpauth://totp/Github:constantoine%40github.com?issuer=Github&secret=KRSXG5CTMVRXEZLUKN2XAZLSKNSWG4TFOQ&digits=6&algorithm=SHA1").unwrap();
         let totp_bis = TOTP::new(
             Algorithm::SHA1,
             6,
             1,
             1,
-            "TestSecretSuperSecret",
+            "TestSecretSuperSecret".as_bytes().to_vec(),
             Some("Github".to_string()),
             "constantoine@github.com".to_string(),
         )
@@ -991,7 +993,7 @@ mod tests {
     #[test]
     #[cfg(feature = "otpauth")]
     fn from_url_unknown_param() {
-        let totp = TOTP::<Vec<u8>>::from_url("otpauth://totp/GitHub:test?secret=KRSXG5CTMVRXEZLUKN2XAZLSKNSWG4TFOQ&digits=8&period=60&algorithm=SHA256&foo=bar").unwrap();
+        let totp = TOTP::from_url("otpauth://totp/GitHub:test?secret=KRSXG5CTMVRXEZLUKN2XAZLSKNSWG4TFOQ&digits=8&period=60&algorithm=SHA256&foo=bar").unwrap();
         assert_eq!(
             totp.secret,
             base32::decode(
@@ -1009,25 +1011,25 @@ mod tests {
     #[test]
     #[cfg(feature = "otpauth")]
     fn from_url_issuer_special() {
-        let totp = TOTP::<Vec<u8>>::from_url("otpauth://totp/Github%40:constantoine%40github.com?issuer=Github%40&secret=KRSXG5CTMVRXEZLUKN2XAZLSKNSWG4TFOQ&digits=6&algorithm=SHA1").unwrap();
+        let totp = TOTP::from_url("otpauth://totp/Github%40:constantoine%40github.com?issuer=Github%40&secret=KRSXG5CTMVRXEZLUKN2XAZLSKNSWG4TFOQ&digits=6&algorithm=SHA1").unwrap();
         let totp_bis = TOTP::new(
             Algorithm::SHA1,
             6,
             1,
             1,
-            "TestSecretSuperSecret",
+            "TestSecretSuperSecret".as_bytes().to_vec(),
             Some("Github@".to_string()),
             "constantoine@github.com".to_string(),
         )
         .unwrap();
         assert_eq!(totp.get_url(), totp_bis.get_url());
-        assert_eq!(totp.issuer.unwrap(), "Github@");
+        assert_eq!(totp.issuer.as_ref().unwrap(), "Github@");
     }
 
     #[test]
     #[cfg(feature = "otpauth")]
     fn from_url_query_issuer() {
-        let totp = TOTP::<Vec<u8>>::from_url("otpauth://totp/GitHub:test?issuer=GitHub&secret=KRSXG5CTMVRXEZLUKN2XAZLSKNSWG4TFOQ&digits=8&period=60&algorithm=SHA256").unwrap();
+        let totp = TOTP::from_url("otpauth://totp/GitHub:test?issuer=GitHub&secret=KRSXG5CTMVRXEZLUKN2XAZLSKNSWG4TFOQ&digits=8&period=60&algorithm=SHA256").unwrap();
         assert_eq!(
             totp.secret,
             base32::decode(
@@ -1040,13 +1042,13 @@ mod tests {
         assert_eq!(totp.digits, 8);
         assert_eq!(totp.skew, 1);
         assert_eq!(totp.step, 60);
-        assert_eq!(totp.issuer.unwrap(), "GitHub");
+        assert_eq!(totp.issuer.as_ref().unwrap(), "GitHub");
     }
 
     #[test]
     #[cfg(feature = "otpauth")]
     fn from_url_wrong_scheme() {
-        let totp = TOTP::<Vec<u8>>::from_url("http://totp/GitHub:test?issuer=GitHub&secret=KRSXG5CTMVRXEZLUKN2XAZLSKNSWG4TFOQ&digits=8&period=60&algorithm=SHA256");
+        let totp = TOTP::from_url("http://totp/GitHub:test?issuer=GitHub&secret=KRSXG5CTMVRXEZLUKN2XAZLSKNSWG4TFOQ&digits=8&period=60&algorithm=SHA256");
         assert!(totp.is_err());
         let err = totp.unwrap_err();
         assert!(matches!(err, TotpUrlError::Scheme(_)));
@@ -1055,7 +1057,7 @@ mod tests {
     #[test]
     #[cfg(feature = "otpauth")]
     fn from_url_wrong_algo() {
-        let totp = TOTP::<Vec<u8>>::from_url("otpauth://totp/GitHub:test?issuer=GitHub&secret=KRSXG5CTMVRXEZLUKN2XAZLSKNSWG4TFOQ&digits=8&period=60&algorithm=MD5");
+        let totp = TOTP::from_url("otpauth://totp/GitHub:test?issuer=GitHub&secret=KRSXG5CTMVRXEZLUKN2XAZLSKNSWG4TFOQ&digits=8&period=60&algorithm=MD5");
         assert!(totp.is_err());
         let err = totp.unwrap_err();
         assert!(matches!(err, TotpUrlError::Algorithm(_)));
@@ -1064,7 +1066,7 @@ mod tests {
     #[test]
     #[cfg(feature = "otpauth")]
     fn from_url_query_different_issuers() {
-        let totp = TOTP::<Vec<u8>>::from_url("otpauth://totp/GitHub:test?issuer=Gitlab&secret=KRSXG5CTMVRXEZLUKN2XAZLSKNSWG4TFOQ&digits=8&period=60&algorithm=SHA256");
+        let totp = TOTP::from_url("otpauth://totp/GitHub:test?issuer=Gitlab&secret=KRSXG5CTMVRXEZLUKN2XAZLSKNSWG4TFOQ&digits=8&period=60&algorithm=SHA256");
         assert!(totp.is_err());
         assert!(matches!(
             totp.unwrap_err(),
@@ -1082,7 +1084,7 @@ mod tests {
             6,
             1,
             1,
-            "TestSecretSuperSecret",
+            "TestSecretSuperSecret".as_bytes().to_vec(),
             Some("Github".to_string()),
             "constantoine@github.com".to_string(),
         )
@@ -1108,7 +1110,7 @@ mod tests {
             6,
             1,
             1,
-            "TestSecretSuperSecret",
+            "TestSecretSuperSecret".as_bytes().to_vec(),
             Some("Github".to_string()),
             "constantoine@github.com".to_string(),
         )
diff --git a/src/rfc.rs b/src/rfc.rs
index 5863bb6..0918a20 100644
--- a/src/rfc.rs
+++ b/src/rfc.rs
@@ -56,7 +56,7 @@ pub fn assert_secret_length(secret: &[u8]) -> Result<(), Rfc6238Error> {
 /// use totp_rs::{Rfc6238, TOTP};
 ///
 /// let mut rfc = Rfc6238::with_defaults(
-///     "totp-sercret-123"
+///     "totp-sercret-123".as_bytes().to_vec()
 /// ).unwrap();
 ///
 /// // optional, set digits, issuer, account_name
@@ -66,7 +66,7 @@ pub fn assert_secret_length(secret: &[u8]) -> Result<(), Rfc6238Error> {
 /// ```
 #[derive(Debug, Clone)]
 #[cfg_attr(feature = "serde_support", derive(Serialize, Deserialize))]
-pub struct Rfc6238<T = Vec<u8>> {
+pub struct Rfc6238 {
     /// SHA-1
     algorithm: Algorithm,
     /// The number of digits composing the auth code. Per [rfc-4226](https://tools.ietf.org/html/rfc4226#section-5.3), this can oscilate between 6 and 8 digits
@@ -76,7 +76,7 @@ pub struct Rfc6238<T = Vec<u8>> {
     /// The recommended value per [rfc-6238](https://tools.ietf.org/html/rfc6238#section-5.2) is 30 seconds
     step: u64,
     /// As per [rfc-4226](https://tools.ietf.org/html/rfc4226#section-4) the secret should come from a strong source, most likely a CSPRNG. It should be at least 128 bits, but 160 are recommended
-    secret: T,
+    secret: Vec<u8>,
     #[cfg(feature = "otpauth")]
     /// The "Github" part of "Github:constantoine@github.com". Must not contain a colon `:`
     /// For example, the name of your service/website.
@@ -88,7 +88,7 @@ pub struct Rfc6238<T = Vec<u8>> {
     account_name: String,
 }
 
-impl<T: AsRef<[u8]>> Rfc6238<T> {
+impl Rfc6238 {
     /// Create an [rfc-6238](https://tools.ietf.org/html/rfc6238) compliant set of options that can be turned into a [TOTP](struct.TOTP.html)
     ///
     /// # Errors
@@ -99,10 +99,10 @@ impl<T: AsRef<[u8]>> Rfc6238<T> {
     #[cfg(feature = "otpauth")]
     pub fn new(
         digits: usize,
-        secret: T,
+        secret: Vec<u8>,
         issuer: Option<String>,
         account_name: String,
-    ) -> Result<Rfc6238<T>, Rfc6238Error> {
+    ) -> Result<Rfc6238, Rfc6238Error> {
         assert_digits(&digits)?;
         assert_secret_length(secret.as_ref())?;
 
@@ -139,7 +139,7 @@ impl<T: AsRef<[u8]>> Rfc6238<T> {
     /// - `digits` is lower than 6 or higher than 8
     /// - `secret` is smaller than 128 bits (16 characters)
     #[cfg(feature = "otpauth")]
-    pub fn with_defaults(secret: T) -> Result<Rfc6238<T>, Rfc6238Error> {
+    pub fn with_defaults(secret: Vec<u8>) -> Result<Rfc6238, Rfc6238Error> {
         Rfc6238::new(6, secret, Some("".to_string()), "".to_string())
     }
 
@@ -179,11 +179,11 @@ impl<T: AsRef<[u8]>> TryFrom<Rfc6238<T>> for TOTP<T> {
 }
 
 #[cfg(feature = "otpauth")]
-impl<T: AsRef<[u8]>> TryFrom<Rfc6238<T>> for TOTP<T> {
+impl TryFrom<Rfc6238> for TOTP {
     type Error = TotpUrlError;
 
     /// Try to create a [TOTP](struct.TOTP.html) from a [Rfc6238](struct.Rfc6238.html) config
-    fn try_from(rfc: Rfc6238<T>) -> Result<Self, Self::Error> {
+    fn try_from(rfc: Rfc6238) -> Result<Self, Self::Error> {
         TOTP::new(
             rfc.algorithm,
             rfc.digits,
@@ -291,7 +291,7 @@ mod tests {
     fn rfc_to_totp_fail() {
         let rfc = Rfc6238::new(
             8,
-            GOOD_SECRET.to_string(),
+            GOOD_SECRET.as_bytes().to_vec(),
             ISSUER.map(str::to_string),
             INVALID_ACCOUNT.to_string(),
         )
@@ -306,7 +306,7 @@ mod tests {
     fn rfc_to_totp_ok() {
         let rfc = Rfc6238::new(
             8,
-            GOOD_SECRET.to_string(),
+            GOOD_SECRET.as_bytes().to_vec(),
             ISSUER.map(str::to_string),
             ACCOUNT.to_string(),
         )
@@ -318,7 +318,7 @@ mod tests {
     #[test]
     #[cfg(feature = "otpauth")]
     fn rfc_with_default_set_values() {
-        let mut rfc = Rfc6238::with_defaults(GOOD_SECRET.to_string()).unwrap();
+        let mut rfc = Rfc6238::with_defaults(GOOD_SECRET.as_bytes().to_vec()).unwrap();
         let ok = rfc.digits(8);
         assert!(ok.is_ok());
         assert_eq!(rfc.account_name, "");
@@ -333,7 +333,7 @@ mod tests {
     #[test]
     #[cfg(not(feature = "otpauth"))]
     fn rfc_with_default_set_values() {
-        let mut rfc = Rfc6238::with_defaults(GOOD_SECRET.to_string()).unwrap();
+        let mut rfc = Rfc6238::with_defaults(GOOD_SECRET.as_bytes().to_vec()).unwrap();
         let fail = rfc.digits(4);
         assert!(fail.is_err());
         assert!(matches!(fail.unwrap_err(), Rfc6238Error::InvalidDigits(_)));