@@ -40,7 +40,15 @@ pub use scrypt;
4040#[ cfg( all( feature = "alloc" , feature = "pbes2" ) ) ]
4141use alloc:: vec:: Vec ;
4242
43- /// Supported PKCS#5 password-based encryption schemes.
43+ /// Configuration for supported PKCS#5 password-based encryption schemes.
44+ ///
45+ /// <div class="warning">
46+ /// <strong>Security Warning</strong>
47+ ///
48+ /// This type should not be used to encrypt multiple plaintexts under the same IV/salt values.
49+ ///
50+ /// Instead, new values should be randomly generated for every usage.
51+ /// </div>
4452#[ derive( Clone , Debug , Eq , PartialEq ) ]
4553#[ non_exhaustive]
4654#[ allow( clippy:: large_enum_variant) ]
@@ -57,13 +65,23 @@ pub enum EncryptionScheme {
5765}
5866
5967impl EncryptionScheme {
68+ /// Generate PBES2 parameters using recommended algorithm settings and parameters (salt/IV)
69+ /// generated using the system's secure random number generator.
70+ ///
71+ /// # Panics
72+ /// In the event the system's secure random generator experiences an internal failure.
73+ #[ cfg( all( feature = "pbes2" , feature = "getrandom" ) ) ]
74+ pub fn generate ( ) -> Self {
75+ Self :: Pbes2 ( pbes2:: Parameters :: generate ( ) )
76+ }
77+
6078 /// Attempt to decrypt the given ciphertext, allocating and returning a byte vector containing
6179 /// the plaintext.
6280 ///
6381 /// # Errors
6482 /// Returns an error if the algorithm specified in this scheme's parameters is unsupported
65- /// (e.g. PBES1 is completely unsupported), or if the ciphertext is malformed (e.g. not a
66- /// multiple of a block mode's padding).
83+ /// (e.g. PBES1 is completely unsupported), or if the ciphertext is malformed (e.g. ciphertext
84+ /// length is not a multiple of a block mode's padding).
6785 #[ cfg( all( feature = "alloc" , feature = "pbes2" ) ) ]
6886 pub fn decrypt ( & self , password : impl AsRef < [ u8 ] > , ciphertext : & [ u8 ] ) -> Result < Vec < u8 > > {
6987 match self {
0 commit comments