File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -175,6 +175,15 @@ impl ShortFileName {
175
175
contents : self . contents ,
176
176
}
177
177
}
178
+
179
+ /// Get the LFN checksum for this short filename
180
+ pub fn csum ( & self ) -> u8 {
181
+ let mut result = 0u8 ;
182
+ for b in self . contents . iter ( ) {
183
+ result = result. rotate_right ( 1 ) . wrapping_add ( * b) ;
184
+ }
185
+ result
186
+ }
178
187
}
179
188
180
189
impl core:: fmt:: Display for ShortFileName {
@@ -302,6 +311,16 @@ mod test {
302
311
assert ! ( ShortFileName :: create_from_str( "123456789" ) . is_err( ) ) ;
303
312
assert ! ( ShortFileName :: create_from_str( "12345678.ABCD" ) . is_err( ) ) ;
304
313
}
314
+
315
+ #[ test]
316
+ fn checksum ( ) {
317
+ assert_eq ! (
318
+ 0xB3 ,
319
+ ShortFileName :: create_from_str( "UNARCH~1.DAT" )
320
+ . unwrap( )
321
+ . csum( )
322
+ ) ;
323
+ }
305
324
}
306
325
307
326
// ****************************************************************************
You can’t perform that action at this time.
0 commit comments