@@ -26,6 +26,7 @@ pub const SPLITSTREAM_MAGIC : [u8; 7] = [b'S', b'p', b'l', b't', b'S', b't', b'r
2626pub struct SplitstreamHeader {
2727 pub magic : [ u8 ; 7 ] , // Contains SPLITSTREAM_MAGIC
2828 pub algorithm : u8 ,
29+ pub content_type : u64 , // User can put whatever magic identifier they want there
2930 pub total_size : u64 , // total size of inline chunks and external chunks
3031 pub n_refs : u64 ,
3132 pub n_mappings : u64 ,
@@ -92,6 +93,7 @@ pub struct SplitStreamWriter<ObjectID: FsVerityHashValue> {
9293 inline_content : Vec < u8 > ,
9394 total_size : u64 ,
9495 writer : Encoder < ' static , Vec < u8 > > ,
96+ pub content_type : u64 ,
9597 pub sha256 : Option < ( Sha256 , Sha256Digest ) > ,
9698}
9799
@@ -109,13 +111,15 @@ impl<ObjectID: FsVerityHashValue> std::fmt::Debug for SplitStreamWriter<ObjectID
109111impl < ObjectID : FsVerityHashValue > SplitStreamWriter < ObjectID > {
110112 pub fn new (
111113 repo : & Arc < Repository < ObjectID > > ,
114+ content_type : u64 ,
112115 sha256 : Option < Sha256Digest > ,
113116 ) -> Self {
114117 // SAFETY: we surely can't get an error writing the header to a Vec<u8>
115118 let writer = Encoder :: new ( vec ! [ ] , 0 ) . unwrap ( ) ;
116119
117120 Self {
118121 repo : Arc :: clone ( repo) ,
122+ content_type : content_type,
119123 inline_content : vec ! [ ] ,
120124 refs : vec ! [ ] ,
121125 total_size : 0 ,
@@ -218,6 +222,7 @@ impl<ObjectID: FsVerityHashValue> SplitStreamWriter<ObjectID> {
218222 let header = SplitstreamHeader {
219223 magic : SPLITSTREAM_MAGIC ,
220224 algorithm : ObjectID :: ALGORITHM ,
225+ content_type : self . content_type ,
221226 total_size : u64:: to_le ( self . total_size ) ,
222227 n_refs : u64:: to_le ( self . refs . len ( ) as u64 ) ,
223228 n_mappings : u64:: to_le ( self . mappings . map . len ( ) as u64 ) ,
@@ -252,6 +257,7 @@ pub enum SplitStreamData<ObjectID: FsVerityHashValue> {
252257pub struct SplitStreamReader < R : Read , ObjectID : FsVerityHashValue > {
253258 decoder : Decoder < ' static , BufReader < R > > ,
254259 inline_bytes : usize ,
260+ pub content_type : u64 ,
255261 pub total_size : u64 ,
256262 pub refs : Vec < ObjectID > ,
257263 mappings : Vec < MappingEntry > ,
@@ -293,17 +299,24 @@ enum ChunkType<ObjectID: FsVerityHashValue> {
293299}
294300
295301impl < 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 > {
297303
298304 let header = SplitstreamHeader :: read_from_io ( & mut reader)
299305 . map_err ( |e| Error :: msg ( format ! ( "Error reading splitstream header: {:?}" , e) ) ) ?;
300306
301307 if header. magic != SPLITSTREAM_MAGIC {
302- bail ! ( "Invalida splitstream header magic value" ) ;
308+ bail ! ( "Invalid splitstream header magic value" ) ;
303309 }
304310
305311 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+ }
307320 }
308321
309322 let total_size = u64:: from_le ( header. total_size ) ;
@@ -333,6 +346,7 @@ impl<R: Read, ObjectID: FsVerityHashValue> SplitStreamReader<R, ObjectID> {
333346 Ok ( Self {
334347 decoder,
335348 inline_bytes : 0 ,
349+ content_type,
336350 total_size,
337351 refs,
338352 mappings,
0 commit comments