@@ -122,19 +122,24 @@ mod real_chachapoly {
122
122
}
123
123
}
124
124
125
- // Decrypt in place, without checking the tag. Use `finish_and_check_tag` to check it
126
- // later when decryption finishes.
127
- //
128
- // Should never be `pub` because the public API should always enforce tag checking.
125
+ pub fn check_decrypt_in_place ( & mut self , input_output : & mut [ u8 ] , tag : & [ u8 ] ) -> Result < ( ) , ( ) > {
126
+ self . decrypt_in_place ( input_output) ;
127
+ if self . finish_and_check_tag ( tag) { Ok ( ( ) ) } else { Err ( ( ) ) }
128
+ }
129
+
130
+ /// Decrypt in place, without checking the tag. Use `finish_and_check_tag` to check it
131
+ /// later when decryption finishes.
132
+ ///
133
+ /// Should never be `pub` because the public API should always enforce tag checking.
129
134
pub ( super ) fn decrypt_in_place ( & mut self , input_output : & mut [ u8 ] ) {
130
135
debug_assert ! ( self . finished == false ) ;
131
136
self . mac . input ( input_output) ;
132
137
self . data_len += input_output. len ( ) ;
133
138
self . cipher . process_in_place ( input_output) ;
134
139
}
135
140
136
- // If we were previously decrypting with `decrypt_in_place `, this method must be used to finish
137
- // decrypting and check the tag. Returns whether or not the tag is valid.
141
+ /// If we were previously decrypting with `just_decrypt_in_place `, this method must be used
142
+ /// to check the tag. Returns whether or not the tag is valid.
138
143
pub ( super ) fn finish_and_check_tag ( & mut self , tag : & [ u8 ] ) -> bool {
139
144
debug_assert ! ( self . finished == false ) ;
140
145
self . finished = true ;
@@ -313,6 +318,11 @@ mod fuzzy_chachapoly {
313
318
true
314
319
}
315
320
321
+ pub fn check_decrypt_in_place ( & mut self , input_output : & mut [ u8 ] , tag : & [ u8 ] ) -> Result < ( ) , ( ) > {
322
+ self . decrypt_in_place ( input_output) ;
323
+ if self . finish_and_check_tag ( tag) { Ok ( ( ) ) } else { Err ( ( ) ) }
324
+ }
325
+
316
326
pub ( super ) fn decrypt_in_place ( & mut self , _input : & mut [ u8 ] ) {
317
327
assert ! ( self . finished == false ) ;
318
328
}
0 commit comments