@@ -57,9 +57,7 @@ impl RekeyStage {
5757 3 => Ok ( Self :: HeaderTargetPublished ) ,
5858 4 => Ok ( Self :: MainDone ) ,
5959 5 => Ok ( Self :: SegmentsPending ) ,
60- _ => Err ( PagedbError :: corruption (
61- crate :: errors:: CorruptionDetail :: HeaderUnverifiable ,
62- ) ) ,
60+ _ => Err ( PagedbError :: catalog_row_invalid ( "rekey.stage" ) ) ,
6361 }
6462 }
6563}
@@ -111,8 +109,8 @@ impl RekeySegmentProgressState {
111109 fn from_byte ( byte : u8 ) -> Result < Self > {
112110 match byte {
113111 1 => Ok ( Self :: Sealed ) ,
114- _ => Err ( PagedbError :: corruption (
115- crate :: errors :: CorruptionDetail :: HeaderUnverifiable ,
112+ _ => Err ( PagedbError :: catalog_row_invalid (
113+ "rekey.segment_progress.state" ,
116114 ) ) ,
117115 }
118116 }
@@ -257,12 +255,13 @@ impl Catalog {
257255 /// positional progress is deliberately preserved only for diagnostics.
258256 pub fn decode_rekey_state ( bytes : & [ u8 ] ) -> Result < RekeyStateRow > {
259257 if bytes. len ( ) == LEGACY_REKEY_STATE_LEN {
260- let target_mk_epoch = u64:: from_le_bytes ( bytes[ 0 ..8 ] . try_into ( ) . map_err ( |_| {
261- PagedbError :: corruption ( crate :: errors:: CorruptionDetail :: HeaderUnverifiable )
262- } ) ?) ;
258+ let target_mk_epoch =
259+ u64:: from_le_bytes ( bytes[ 0 ..8 ] . try_into ( ) . map_err ( |_| {
260+ PagedbError :: catalog_row_invalid ( "rekey.legacy.target_mk_epoch" )
261+ } ) ?) ;
263262 if target_mk_epoch == 0 {
264- return Err ( PagedbError :: corruption (
265- crate :: errors :: CorruptionDetail :: HeaderUnverifiable ,
263+ return Err ( PagedbError :: catalog_row_invalid (
264+ "rekey.legacy.target_mk_epoch" ,
266265 ) ) ;
267266 }
268267 return Ok ( RekeyStateRow :: Legacy ( LegacyRekeyState {
@@ -271,15 +270,13 @@ impl Catalog {
271270 0 => false ,
272271 1 => true ,
273272 _ => {
274- return Err ( PagedbError :: corruption (
275- crate :: errors :: CorruptionDetail :: HeaderUnverifiable ,
273+ return Err ( PagedbError :: catalog_row_invalid (
274+ "rekey.legacy.main_db_done" ,
276275 ) ) ;
277276 }
278277 } ,
279278 discarded_segments_index : u32:: from_le_bytes ( bytes[ 9 ..13 ] . try_into ( ) . map_err (
280- |_| {
281- PagedbError :: corruption ( crate :: errors:: CorruptionDetail :: HeaderUnverifiable )
282- } ,
279+ |_| PagedbError :: catalog_row_invalid ( "rekey.legacy.discarded_segments_index" ) ,
283280 ) ?) ,
284281 } ) ) ;
285282 }
@@ -289,28 +286,26 @@ impl Catalog {
289286 || bytes[ 22 ..24 ] . iter ( ) . any ( |byte| * byte != 0 )
290287 || bytes[ 56 ..] . iter ( ) . any ( |byte| * byte != 0 )
291288 {
292- return Err ( PagedbError :: corruption (
293- crate :: errors:: CorruptionDetail :: HeaderUnverifiable ,
294- ) ) ;
289+ return Err ( PagedbError :: catalog_row_invalid ( "rekey.framing" ) ) ;
295290 }
296- let source_mk_epoch = u64:: from_le_bytes ( bytes[ 4 ..12 ] . try_into ( ) . map_err ( |_| {
297- PagedbError :: corruption ( crate :: errors:: CorruptionDetail :: HeaderUnverifiable )
298- } ) ?) ;
299- let target_mk_epoch = u64:: from_le_bytes ( bytes[ 12 ..20 ] . try_into ( ) . map_err ( |_| {
300- PagedbError :: corruption ( crate :: errors:: CorruptionDetail :: HeaderUnverifiable )
301- } ) ?) ;
291+ let source_mk_epoch = u64:: from_le_bytes (
292+ bytes[ 4 ..12 ]
293+ . try_into ( )
294+ . map_err ( |_| PagedbError :: catalog_row_invalid ( "rekey.source_mk_epoch" ) ) ?,
295+ ) ;
296+ let target_mk_epoch = u64:: from_le_bytes (
297+ bytes[ 12 ..20 ]
298+ . try_into ( )
299+ . map_err ( |_| PagedbError :: catalog_row_invalid ( "rekey.target_mk_epoch" ) ) ?,
300+ ) ;
302301 if target_mk_epoch == 0 || target_mk_epoch <= source_mk_epoch {
303- return Err ( PagedbError :: corruption (
304- crate :: errors:: CorruptionDetail :: HeaderUnverifiable ,
305- ) ) ;
302+ return Err ( PagedbError :: catalog_row_invalid ( "rekey.epoch_ordering" ) ) ;
306303 }
307304 let same_kek = match bytes[ 2 ] {
308305 0 => false ,
309306 1 => true ,
310307 _ => {
311- return Err ( PagedbError :: corruption (
312- crate :: errors:: CorruptionDetail :: HeaderUnverifiable ,
313- ) ) ;
308+ return Err ( PagedbError :: catalog_row_invalid ( "rekey.same_kek" ) ) ;
314309 }
315310 } ;
316311 crate :: crypto:: CipherId :: from_byte ( bytes[ 20 ] ) ?;
@@ -352,8 +347,8 @@ impl Catalog {
352347 || bytes[ 0 ] != 1
353348 || bytes[ 2 ..4 ] . iter ( ) . any ( |byte| * byte != 0 )
354349 {
355- return Err ( PagedbError :: corruption (
356- crate :: errors :: CorruptionDetail :: HeaderUnverifiable ,
350+ return Err ( PagedbError :: catalog_row_invalid (
351+ "rekey.segment_progress.framing" ,
357352 ) ) ;
358353 }
359354 let mut replacement_segment_id = [ 0u8 ; 16 ] ;
@@ -385,9 +380,7 @@ impl Catalog {
385380 /// Decode a counter value from an 8-byte little-endian slice.
386381 pub fn decode_counter ( bytes : & [ u8 ] ) -> Result < u64 > {
387382 if bytes. len ( ) != 8 {
388- return Err ( PagedbError :: corruption (
389- crate :: errors:: CorruptionDetail :: HeaderUnverifiable ,
390- ) ) ;
383+ return Err ( PagedbError :: catalog_row_invalid ( "counter.value" ) ) ;
391384 }
392385 let mut b = [ 0u8 ; 8 ] ;
393386 b. copy_from_slice ( bytes) ;
@@ -420,9 +413,7 @@ impl Catalog {
420413
421414 pub fn decode_realm_quotas ( bytes : & [ u8 ] ) -> Result < RealmQuotas > {
422415 if bytes. len ( ) != REALM_QUOTAS_LEN {
423- return Err ( PagedbError :: corruption (
424- crate :: errors:: CorruptionDetail :: HeaderUnverifiable ,
425- ) ) ;
416+ return Err ( PagedbError :: catalog_row_invalid ( "realm_quotas.length" ) ) ;
426417 }
427418 let mask = bytes[ 0 ] ;
428419 let read = |off : usize | -> u64 {
@@ -490,9 +481,7 @@ impl Catalog {
490481
491482 pub fn decode_segment_meta ( bytes : & [ u8 ] ) -> Result < SegmentMeta > {
492483 if bytes. len ( ) != SEGMENT_META_LEN {
493- return Err ( PagedbError :: corruption (
494- crate :: errors:: CorruptionDetail :: HeaderUnverifiable ,
495- ) ) ;
484+ return Err ( PagedbError :: catalog_row_invalid ( "segment_meta.length" ) ) ;
496485 }
497486 let segment_id = {
498487 let mut b = [ 0u8 ; 16 ] ;
@@ -547,9 +536,7 @@ impl Catalog {
547536 0 => Evictable :: Authoritative ,
548537 1 => Evictable :: Replaceable ,
549538 _ => {
550- return Err ( PagedbError :: corruption (
551- crate :: errors:: CorruptionDetail :: HeaderUnverifiable ,
552- ) ) ;
539+ return Err ( PagedbError :: catalog_row_invalid ( "segment_meta.evictable" ) ) ;
553540 }
554541 } ;
555542 Ok ( SegmentMeta {
0 commit comments