Commit 10274b5 1 parent 78155de commit 10274b5 Copy full SHA for 10274b5
File tree 1 file changed +20
-1
lines changed
1 file changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -149,14 +149,33 @@ fn blkfiles_fetcher(
149
149
fn blkfiles_reader ( blk_files : Vec < PathBuf > ) -> Fetcher < Vec < u8 > > {
150
150
let chan = SyncChannel :: new ( 1 ) ;
151
151
let sender = chan. sender ( ) ;
152
+ let xor_key = blk_files. first ( ) . and_then ( |p| {
153
+ let xor_file = p
154
+ . parent ( )
155
+ . expect ( "blk.dat files must exist in a directory" )
156
+ . join ( "xor.dat" ) ;
157
+ if xor_file. exists ( ) {
158
+ Some ( fs:: read ( xor_file) . expect ( "xor.dat exists" ) )
159
+ } else {
160
+ None
161
+ }
162
+ } ) ;
152
163
153
164
Fetcher :: from (
154
165
chan. into_receiver ( ) ,
155
166
spawn_thread ( "blkfiles_reader" , move || {
156
167
for path in blk_files {
157
168
trace ! ( "reading {:?}" , path) ;
158
- let blob = fs:: read ( & path)
169
+ let mut blob = fs:: read ( & path)
159
170
. unwrap_or_else ( |e| panic ! ( "failed to read {:?}: {:?}" , path, e) ) ;
171
+
172
+ // If the xor.dat exists. Use it to decrypt the block files.
173
+ if let Some ( xor_key) = & xor_key {
174
+ for ( & key, byte) in xor_key. iter ( ) . cycle ( ) . zip ( blob. iter_mut ( ) ) {
175
+ * byte ^= key;
176
+ }
177
+ }
178
+
160
179
sender
161
180
. send ( blob)
162
181
. unwrap_or_else ( |_| panic ! ( "failed to send {:?} contents" , path) ) ;
You can’t perform that action at this time.
0 commit comments