@@ -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.
129
- pub ( super ) fn decrypt_in_place ( & mut self , input_output : & mut [ u8 ] ) {
125
+ pub fn decrypt_in_place ( & mut self , input_output : & mut [ u8 ] , tag : & [ u8 ] ) -> Result < ( ) , ( ) > {
126
+ self . just_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.
134
+ pub ( super ) fn just_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 ;
@@ -168,7 +173,7 @@ impl<'a, R: Read> Read for ChaChaPolyReader<'a, R> {
168
173
fn read ( & mut self , dest : & mut [ u8 ] ) -> Result < usize , io:: Error > {
169
174
let res = self . read . read ( dest) ?;
170
175
if res > 0 {
171
- self . chacha . decrypt_in_place ( & mut dest[ 0 ..res] ) ;
176
+ self . chacha . just_decrypt_in_place ( & mut dest[ 0 ..res] ) ;
172
177
}
173
178
Ok ( res)
174
179
}
@@ -313,7 +318,7 @@ mod fuzzy_chachapoly {
313
318
true
314
319
}
315
320
316
- pub ( super ) fn decrypt_in_place ( & mut self , _input : & mut [ u8 ] ) {
321
+ pub ( super ) fn just_decrypt_in_place ( & mut self , _input : & mut [ u8 ] ) {
317
322
assert ! ( self . finished == false ) ;
318
323
}
319
324
0 commit comments