@@ -23,8 +23,10 @@ pub struct Encryptor<'m> {
23
23
impl < ' m > Encryptor < ' m > {
24
24
/// Creates a new `Encryptor`.
25
25
///
26
- /// This uses the [recommended Argon2 parameters] created by
27
- /// [`Params::default`].
26
+ /// This uses the recommended Argon2 parameters according to the [OWASP
27
+ /// Password Storage Cheat Sheet] created by [`Params::default`]. This also
28
+ /// uses the Argon2 type created by [`Algorithm::default`] and the Argon2
29
+ /// version created by [`Version::default`].
28
30
///
29
31
/// # Errors
30
32
///
@@ -41,7 +43,7 @@ impl<'m> Encryptor<'m> {
41
43
/// let cipher = Encryptor::new(data, passphrase).unwrap();
42
44
/// ```
43
45
///
44
- /// [recommended Argon2 parameters ]: https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html
46
+ /// [OWASP Password Storage Cheat Sheet ]: https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html#argon2id
45
47
#[ cfg( feature = "alloc" ) ]
46
48
#[ inline]
47
49
pub fn new ( plaintext : & ' m impl AsRef < [ u8 ] > , passphrase : impl AsRef < [ u8 ] > ) -> Result < Self > {
@@ -50,7 +52,8 @@ impl<'m> Encryptor<'m> {
50
52
51
53
/// Creates a new `Encryptor` with the specified [`Params`].
52
54
///
53
- /// This uses the Argon2 type created by [`Algorithm::default`].
55
+ /// This uses the Argon2 type created by [`Algorithm::default`] and the
56
+ /// Argon2 version created by [`Version::default`].
54
57
///
55
58
/// # Errors
56
59
///
@@ -73,43 +76,10 @@ impl<'m> Encryptor<'m> {
73
76
passphrase : impl AsRef < [ u8 ] > ,
74
77
params : Params ,
75
78
) -> Result < Self > {
76
- Self :: with_type ( plaintext, passphrase, Algorithm :: default ( ) , params)
77
- }
78
-
79
- /// Creates a new `Encryptor` with the specified [`Algorithm`] and
80
- /// [`Params`].
81
- ///
82
- /// This uses the Argon2 version created by [`Version::default`].
83
- ///
84
- /// # Errors
85
- ///
86
- /// Returns [`Err`] if the Argon2 context is invalid.
87
- ///
88
- /// # Examples
89
- ///
90
- /// ```
91
- /// # use abcrypt::{
92
- /// # argon2::{Algorithm, Params},
93
- /// # Encryptor,
94
- /// # };
95
- /// #
96
- /// let data = b"Hello, world!\n";
97
- /// let passphrase = "passphrase";
98
- ///
99
- /// let params = Params::new(32, 3, 4, None).unwrap();
100
- /// let cipher = Encryptor::with_type(data, passphrase, Algorithm::Argon2d, params).unwrap();
101
- /// ```
102
- #[ inline]
103
- pub fn with_type (
104
- plaintext : & ' m impl AsRef < [ u8 ] > ,
105
- passphrase : impl AsRef < [ u8 ] > ,
106
- argon2_type : Algorithm ,
107
- params : Params ,
108
- ) -> Result < Self > {
109
- Self :: with_version (
79
+ Self :: with_context (
110
80
plaintext,
111
81
passphrase,
112
- argon2_type ,
82
+ Algorithm :: default ( ) ,
113
83
Version :: default ( ) ,
114
84
params,
115
85
)
@@ -135,10 +105,10 @@ impl<'m> Encryptor<'m> {
135
105
///
136
106
/// let params = Params::new(32, 3, 4, None).unwrap();
137
107
/// let cipher =
138
- /// Encryptor::with_version (data, passphrase, Algorithm::Argon2i, Version::V0x10, params)
108
+ /// Encryptor::with_context (data, passphrase, Algorithm::Argon2i, Version::V0x10, params)
139
109
/// .unwrap();
140
110
/// ```
141
- pub fn with_version (
111
+ pub fn with_context (
142
112
plaintext : & ' m impl AsRef < [ u8 ] > ,
143
113
passphrase : impl AsRef < [ u8 ] > ,
144
114
argon2_type : Algorithm ,
@@ -283,8 +253,10 @@ impl<'m> Encryptor<'m> {
283
253
284
254
/// Encrypts `plaintext` and into a newly allocated [`Vec`](alloc::vec::Vec).
285
255
///
286
- /// This uses the [recommended Argon2 parameters] created by
287
- /// [`Params::default`].
256
+ /// This uses the recommended Argon2 parameters according to the [OWASP Password
257
+ /// Storage Cheat Sheet] created by [`Params::default`]. This also uses the
258
+ /// Argon2 type created by [`Algorithm::default`] and the Argon2 version created
259
+ /// by [`Version::default`].
288
260
///
289
261
/// This is a convenience function for using [`Encryptor::new`] and
290
262
/// [`Encryptor::encrypt_to_vec`].
@@ -303,7 +275,7 @@ impl<'m> Encryptor<'m> {
303
275
/// # assert_ne!(ciphertext, data);
304
276
/// ```
305
277
///
306
- /// [recommended Argon2 parameters ]: https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html
278
+ /// [OWASP Password Storage Cheat Sheet ]: https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html#argon2id
307
279
#[ cfg( feature = "alloc" ) ]
308
280
#[ inline]
309
281
pub fn encrypt (
@@ -317,7 +289,8 @@ pub fn encrypt(
317
289
/// Encrypts `plaintext` with the specified [`Params`] and into a newly
318
290
/// allocated [`Vec`](alloc::vec::Vec).
319
291
///
320
- /// This uses the Argon2 type created by [`Algorithm::default`].
292
+ /// This uses the Argon2 type created by [`Algorithm::default`] and the Argon2
293
+ /// version created by [`Version::default`].
321
294
///
322
295
/// This is a convenience function for using [`Encryptor::with_params`] and
323
296
/// [`Encryptor::encrypt_to_vec`].
@@ -348,48 +321,11 @@ pub fn encrypt_with_params(
348
321
Encryptor :: with_params ( & plaintext, passphrase, params) . map ( |c| c. encrypt_to_vec ( ) )
349
322
}
350
323
351
- #[ allow( clippy:: module_name_repetitions) ]
352
- /// Encrypts `plaintext` with the specified [`Algorithm`] and [`Params`] and
353
- /// into a newly allocated [`Vec`](alloc::vec::Vec).
354
- ///
355
- /// This uses the Argon2 version created by [`Version::default`].
356
- ///
357
- /// This is a convenience function for using [`Encryptor::with_type`] and
358
- /// [`Encryptor::encrypt_to_vec`].
359
- ///
360
- /// # Errors
361
- ///
362
- /// Returns [`Err`] if the Argon2 context is invalid.
363
- ///
364
- /// # Examples
365
- ///
366
- /// ```
367
- /// # use abcrypt::argon2::{Algorithm, Params};
368
- /// #
369
- /// let data = b"Hello, world!\n";
370
- /// let passphrase = "passphrase";
371
- ///
372
- /// let params = Params::new(32, 3, 4, None).unwrap();
373
- /// let ciphertext =
374
- /// abcrypt::encrypt_with_type(data, passphrase, Algorithm::Argon2d, params).unwrap();
375
- /// # assert_ne!(ciphertext, data);
376
- /// ```
377
- #[ cfg( feature = "alloc" ) ]
378
- #[ inline]
379
- pub fn encrypt_with_type (
380
- plaintext : impl AsRef < [ u8 ] > ,
381
- passphrase : impl AsRef < [ u8 ] > ,
382
- argon2_type : Algorithm ,
383
- params : Params ,
384
- ) -> Result < alloc:: vec:: Vec < u8 > > {
385
- Encryptor :: with_type ( & plaintext, passphrase, argon2_type, params) . map ( |c| c. encrypt_to_vec ( ) )
386
- }
387
-
388
324
#[ allow( clippy:: module_name_repetitions) ]
389
325
/// Encrypts `plaintext` with the specified [`Algorithm`], [`Version`] and
390
326
/// [`Params`] and into a newly allocated [`Vec`](alloc::vec::Vec).
391
327
///
392
- /// This is a convenience function for using [`Encryptor::with_version `] and
328
+ /// This is a convenience function for using [`Encryptor::with_context `] and
393
329
/// [`Encryptor::encrypt_to_vec`].
394
330
///
395
331
/// # Errors
@@ -406,19 +342,19 @@ pub fn encrypt_with_type(
406
342
///
407
343
/// let params = Params::new(32, 3, 4, None).unwrap();
408
344
/// let ciphertext =
409
- /// abcrypt::encrypt_with_version (data, passphrase, Algorithm::Argon2i, Version::V0x10, params)
345
+ /// abcrypt::encrypt_with_context (data, passphrase, Algorithm::Argon2i, Version::V0x10, params)
410
346
/// .unwrap();
411
347
/// # assert_ne!(ciphertext, data);
412
348
/// ```
413
349
#[ cfg( feature = "alloc" ) ]
414
350
#[ inline]
415
- pub fn encrypt_with_version (
351
+ pub fn encrypt_with_context (
416
352
plaintext : impl AsRef < [ u8 ] > ,
417
353
passphrase : impl AsRef < [ u8 ] > ,
418
354
argon2_type : Algorithm ,
419
355
argon2_version : Version ,
420
356
params : Params ,
421
357
) -> Result < alloc:: vec:: Vec < u8 > > {
422
- Encryptor :: with_version ( & plaintext, passphrase, argon2_type, argon2_version, params)
358
+ Encryptor :: with_context ( & plaintext, passphrase, argon2_type, argon2_version, params)
423
359
. map ( |c| c. encrypt_to_vec ( ) )
424
360
}
0 commit comments