@@ -26,6 +26,7 @@ pub const SPLITSTREAM_MAGIC : [u8; 7] = [b'S', b'p', b'l', b't', b'S', b't', b'r
26
26
pub struct SplitstreamHeader {
27
27
pub magic : [ u8 ; 7 ] , // Contains SPLITSTREAM_MAGIC
28
28
pub algorithm : u8 ,
29
+ pub content_type : u64 , // User can put whatever magic identifier they want there
29
30
pub total_size : u64 , // total size of inline chunks and external chunks
30
31
pub n_refs : u64 ,
31
32
pub n_mappings : u64 ,
@@ -92,6 +93,7 @@ pub struct SplitStreamWriter<ObjectID: FsVerityHashValue> {
92
93
inline_content : Vec < u8 > ,
93
94
total_size : u64 ,
94
95
writer : Encoder < ' static , Vec < u8 > > ,
96
+ pub content_type : u64 ,
95
97
pub sha256 : Option < ( Sha256 , Sha256Digest ) > ,
96
98
}
97
99
@@ -109,13 +111,15 @@ impl<ObjectID: FsVerityHashValue> std::fmt::Debug for SplitStreamWriter<ObjectID
109
111
impl < ObjectID : FsVerityHashValue > SplitStreamWriter < ObjectID > {
110
112
pub fn new (
111
113
repo : & Arc < Repository < ObjectID > > ,
114
+ content_type : u64 ,
112
115
sha256 : Option < Sha256Digest > ,
113
116
) -> Self {
114
117
// SAFETY: we surely can't get an error writing the header to a Vec<u8>
115
118
let writer = Encoder :: new ( vec ! [ ] , 0 ) . unwrap ( ) ;
116
119
117
120
Self {
118
121
repo : Arc :: clone ( repo) ,
122
+ content_type : content_type,
119
123
inline_content : vec ! [ ] ,
120
124
refs : vec ! [ ] ,
121
125
total_size : 0 ,
@@ -218,6 +222,7 @@ impl<ObjectID: FsVerityHashValue> SplitStreamWriter<ObjectID> {
218
222
let header = SplitstreamHeader {
219
223
magic : SPLITSTREAM_MAGIC ,
220
224
algorithm : ObjectID :: ALGORITHM ,
225
+ content_type : self . content_type ,
221
226
total_size : u64:: to_le ( self . total_size ) ,
222
227
n_refs : u64:: to_le ( self . refs . len ( ) as u64 ) ,
223
228
n_mappings : u64:: to_le ( self . mappings . map . len ( ) as u64 ) ,
@@ -252,6 +257,7 @@ pub enum SplitStreamData<ObjectID: FsVerityHashValue> {
252
257
pub struct SplitStreamReader < R : Read , ObjectID : FsVerityHashValue > {
253
258
decoder : Decoder < ' static , BufReader < R > > ,
254
259
inline_bytes : usize ,
260
+ pub content_type : u64 ,
255
261
pub total_size : u64 ,
256
262
pub refs : Vec < ObjectID > ,
257
263
mappings : Vec < MappingEntry > ,
@@ -293,17 +299,24 @@ enum ChunkType<ObjectID: FsVerityHashValue> {
293
299
}
294
300
295
301
impl < R : Read , ObjectID : FsVerityHashValue > SplitStreamReader < R , ObjectID > {
296
- pub fn new ( mut reader : R ) -> Result < Self > {
302
+ pub fn new ( mut reader : R , expected_content_type : Option < u64 > ) -> Result < Self > {
297
303
298
304
let header = SplitstreamHeader :: read_from_io ( & mut reader)
299
305
. map_err ( |e| Error :: msg ( format ! ( "Error reading splitstream header: {:?}" , e) ) ) ?;
300
306
301
307
if header. magic != SPLITSTREAM_MAGIC {
302
- bail ! ( "Invalida splitstream header magic value" ) ;
308
+ bail ! ( "Invalid splitstream header magic value" ) ;
303
309
}
304
310
305
311
if header. algorithm != ObjectID :: ALGORITHM {
306
- bail ! ( "Invalida splitstream algorithm type" ) ;
312
+ bail ! ( "Invalid splitstream algorithm type" ) ;
313
+ }
314
+
315
+ let content_type = u64:: from_le ( header. content_type ) ;
316
+ if let Some ( expected) = expected_content_type {
317
+ if content_type != expected {
318
+ bail ! ( "Invalid splitstream content type" ) ;
319
+ }
307
320
}
308
321
309
322
let total_size = u64:: from_le ( header. total_size ) ;
@@ -333,6 +346,7 @@ impl<R: Read, ObjectID: FsVerityHashValue> SplitStreamReader<R, ObjectID> {
333
346
Ok ( Self {
334
347
decoder,
335
348
inline_bytes : 0 ,
349
+ content_type,
336
350
total_size,
337
351
refs,
338
352
mappings,
0 commit comments