@@ -10,7 +10,7 @@ use anyhow::{bail, Context, Result};
10
10
use zstd:: Encoder ;
11
11
12
12
use crate :: {
13
- fsverity:: { FsVerityHashValue , Sha256HashValue } ,
13
+ fsverity:: Sha256HashValue ,
14
14
repository:: Repository ,
15
15
splitstream:: {
16
16
DigestMap , EnsureObjectMessages , FinishMessage , ResultChannelSender ,
@@ -198,15 +198,19 @@ impl ZstdWriter {
198
198
Ok ( self . writer . write_all ( data) ?)
199
199
}
200
200
201
+ pub ( crate ) fn update_sha ( & mut self , data : & [ u8 ] ) {
202
+ if let Some ( ( sha256, ..) ) = & mut self . sha256_builder {
203
+ sha256. update ( & data) ;
204
+ }
205
+ }
206
+
201
207
/// Writes all the data in `inline_content`, updating the internal SHA
202
208
pub ( crate ) fn flush_inline ( & mut self , inline_content : & Vec < u8 > ) -> Result < ( ) > {
203
209
if inline_content. is_empty ( ) {
204
210
return Ok ( ( ) ) ;
205
211
}
206
212
207
- if let Some ( ( sha256, ..) ) = & mut self . sha256_builder {
208
- sha256. update ( & inline_content) ;
209
- }
213
+ self . update_sha ( inline_content) ;
210
214
211
215
self . write_fragment ( inline_content. len ( ) , & inline_content) ?;
212
216
@@ -263,8 +267,6 @@ impl ZstdWriter {
263
267
pub ( crate ) fn finalize_sha256_builder ( & mut self ) -> Result < Sha256HashValue > {
264
268
let sha256_builder = std:: mem:: replace ( & mut self . sha256_builder , None ) ;
265
269
266
- let mut sha = Sha256HashValue :: EMPTY ;
267
-
268
270
if let Some ( ( context, expected) ) = sha256_builder {
269
271
let final_sha = Into :: < Sha256HashValue > :: into ( context. finalize ( ) ) ;
270
272
@@ -276,10 +278,10 @@ impl ZstdWriter {
276
278
) ;
277
279
}
278
280
279
- sha = final_sha;
281
+ return Ok ( final_sha) ;
280
282
}
281
283
282
- return Ok ( sha ) ;
284
+ bail ! ( "SHA not enabled for writer" ) ;
283
285
}
284
286
285
287
/// Calls `finish` on the internal writer
0 commit comments