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 {
175175 contents : self . contents ,
176176 }
177177 }
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+ }
178187}
179188
180189impl core:: fmt:: Display for ShortFileName {
@@ -302,6 +311,16 @@ mod test {
302311 assert ! ( ShortFileName :: create_from_str( "123456789" ) . is_err( ) ) ;
303312 assert ! ( ShortFileName :: create_from_str( "12345678.ABCD" ) . is_err( ) ) ;
304313 }
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+ }
305324}
306325
307326// ****************************************************************************
You can’t perform that action at this time.
0 commit comments