prevent utf8 iteration for ascii str from shred
@@ -24,7 +24,7 @@ extern crate uucore;
static NAME: &str = "shred";
const BLOCK_SIZE: usize = 512;
-const NAME_CHARSET: &str = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_.";
+const NAME_CHARSET: &[u8] = b"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_.";
// Patterns as shown in the GNU coreutils shred implementation
const PATTERNS: [&[u8]; 22] = [
@@ -89,7 +89,7 @@ impl Iterator for FilenameGenerator {
// Make the return value, then increment
let mut ret = String::new();
for i in name_charset_indices.iter() {
- let c: char = NAME_CHARSET.chars().nth(*i).unwrap();
+ let c = char::from(NAME_CHARSET[*i]);
ret.push(c);
}
@@ -163,8 +163,7 @@ impl<'a> BytesGenerator<'a> {
return None;
}
- let this_block_size = {
- if !self.exact {
+ let this_block_size = if !self.exact {
self.block_size
} else {
let bytes_left = self.total_bytes - self.bytes_generated.get();
@@ -173,7 +172,6 @@ impl<'a> BytesGenerator<'a> {
} else {
(bytes_left % self.block_size as u64) as usize
}
- }
};
let bytes = &mut self.bytes[..this_block_size];
@@ -184,12 +182,10 @@ impl<'a> BytesGenerator<'a> {
rng.fill(bytes);
}
PassType::Pattern(pattern) => {
- let skip = {
- if self.bytes_generated.get() == 0 {
+ let skip = if self.bytes_generated.get() == 0 {
0
} else {
(pattern.len() as u64 % self.bytes_generated.get()) as usize
- }
};
// Copy the pattern in chunks rather than simply one byte at a time
