11#![ no_std]
2- #![ cfg_attr( docsrs, feature( doc_auto_cfg ) ) ]
2+ #![ cfg_attr( docsrs, feature( doc_cfg ) ) ]
33#![ doc = include_str ! ( "../README.md" ) ]
44#![ doc(
55 html_logo_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg" ,
66 html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg"
77) ]
8- #![ forbid( unsafe_code) ]
9- #![ warn(
10- clippy:: alloc_instead_of_core,
11- clippy:: arithmetic_side_effects,
12- clippy:: mod_module_files,
13- clippy:: panic,
14- clippy:: panic_in_result_fn,
15- clippy:: std_instead_of_alloc,
16- clippy:: std_instead_of_core,
17- clippy:: unwrap_used,
18- missing_docs,
19- rust_2018_idioms,
20- unused_lifetimes,
21- unused_qualifications
22- ) ]
238
249mod error;
2510
@@ -138,12 +123,25 @@ impl Cipher {
138123 /// Decode cipher algorithm from the given `ciphername`.
139124 ///
140125 /// # Supported cipher names
141- /// - `aes256-ctr`
126+ /// `aes128-cbc`
127+ /// `aes192-cbc`
128+ /// `aes256-cbc`
129+ /// `aes128-ctr`
130+ /// `aes192-ctr`
131+ /// `aes256-ctr`
132+ /// `aes128-gcm@openssh.com`
133+ /// `aes256-gcm@openssh.com`
134+ /// `chacha20-poly1305@openssh.com`
135+ /// `3des-cbc`
136+ ///
137+ /// # Errors
138+ /// Returns [`LabelError`] if the provided `ciphername` is unknown.
142139 pub fn new ( ciphername : & str ) -> core:: result:: Result < Self , LabelError > {
143140 ciphername. parse ( )
144141 }
145142
146143 /// Get the string identifier which corresponds to this algorithm.
144+ #[ must_use]
147145 pub fn as_str ( self ) -> & ' static str {
148146 match self {
149147 Self :: None => "none" ,
@@ -161,6 +159,7 @@ impl Cipher {
161159 }
162160
163161 /// Get the key and IV size for this cipher in bytes.
162+ #[ must_use]
164163 pub fn key_and_iv_size ( self ) -> Option < ( usize , usize ) > {
165164 match self {
166165 Self :: None => None ,
@@ -178,6 +177,7 @@ impl Cipher {
178177 }
179178
180179 /// Get the block size for this cipher in bytes.
180+ #[ must_use]
181181 pub fn block_size ( self ) -> usize {
182182 match self {
183183 Self :: None | Self :: ChaCha20Poly1305 | Self :: TDesCbc => 8 ,
@@ -195,14 +195,20 @@ impl Cipher {
195195 /// Compute the length of padding necessary to pad the given input to
196196 /// the block size.
197197 #[ allow( clippy:: arithmetic_side_effects) ]
198+ #[ must_use]
198199 pub fn padding_len ( self , input_size : usize ) -> usize {
200+ #[ allow(
201+ clippy:: integer_division_remainder_used,
202+ reason = "input_size is non-secret"
203+ ) ]
199204 match input_size % self . block_size ( ) {
200205 0 => 0 ,
201206 input_rem => self . block_size ( ) - input_rem,
202207 }
203208 }
204209
205210 /// Does this cipher have an authentication tag? (i.e. is it an AEAD mode?)
211+ #[ must_use]
206212 pub fn has_tag ( self ) -> bool {
207213 matches ! (
208214 self ,
@@ -211,17 +217,20 @@ impl Cipher {
211217 }
212218
213219 /// Is this cipher `none`?
220+ #[ must_use]
214221 pub fn is_none ( self ) -> bool {
215222 self == Self :: None
216223 }
217224
218225 /// Is the cipher anything other than `none`?
226+ #[ must_use]
219227 pub fn is_some ( self ) -> bool {
220228 !self . is_none ( )
221229 }
222230
223231 /// Decrypt the ciphertext in the `buffer` in-place using this cipher.
224232 ///
233+ /// # Errors
225234 /// Returns [`Error::Length`] in the event that `buffer` is not a multiple of the cipher's
226235 /// block size.
227236 #[ cfg_attr(
@@ -280,13 +289,17 @@ impl Cipher {
280289 ///
281290 /// Only applicable to unauthenticated modes (e.g. AES-CBC, AES-CTR). Not usable with
282291 /// authenticated modes which are inherently one-shot (AES-GCM, ChaCha20Poly1305).
292+ ///
293+ /// # Errors
294+ /// Propagates errors from [`Decryptor::new`].
283295 #[ cfg( any( feature = "aes-cbc" , feature = "aes-ctr" , feature = "tdes" ) ) ]
284296 pub fn decryptor ( self , key : & [ u8 ] , iv : & [ u8 ] ) -> Result < Decryptor > {
285297 Decryptor :: new ( self , key, iv)
286298 }
287299
288300 /// Encrypt the ciphertext in the `buffer` in-place using this cipher.
289301 ///
302+ /// # Errors
290303 /// Returns [`Error::Length`] in the event that `buffer` is not a multiple of the cipher's
291304 /// block size.
292305 #[ cfg_attr(
@@ -339,6 +352,9 @@ impl Cipher {
339352 ///
340353 /// Only applicable to unauthenticated modes (e.g. AES-CBC, AES-CTR). Not usable with
341354 /// authenticated modes which are inherently one-shot (AES-GCM, ChaCha20Poly1305).
355+ ///
356+ /// # Errors
357+ /// Propagates errors from [`Encryptor::new`].
342358 #[ cfg( any( feature = "aes-cbc" , feature = "aes-ctr" , feature = "tdes" ) ) ]
343359 pub fn encryptor ( self , key : & [ u8 ] , iv : & [ u8 ] ) -> Result < Encryptor > {
344360 Encryptor :: new ( self , key, iv)
0 commit comments