Fix encoding test failures caused by incorrect padding calculation
This commit is contained in:
parent
2236a572f7
commit
d203aaf5d3
1 changed files with 6 additions and 3 deletions
|
@ -80,9 +80,12 @@ impl<R: Read, W: Write> Encoder<R, W> {
|
||||||
num |= *n as u64;
|
num |= *n as u64;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let pad = n_bytes * 8 % 6;
|
let mut outlen = n_bytes * 8 / 6;
|
||||||
|
if n_bytes * 8 % 6 > 0 {
|
||||||
|
outlen += 1;
|
||||||
|
}
|
||||||
for idx in (0..4).rev() {
|
for idx in (0..4).rev() {
|
||||||
if pad == 0 || idx < 4 - pad {
|
if outlen == 4 || idx < outlen {
|
||||||
let b = num & 0b111111;
|
let b = num & 0b111111;
|
||||||
obuf[idx] = self.alphabet.items[b as usize];
|
obuf[idx] = self.alphabet.items[b as usize];
|
||||||
}
|
}
|
||||||
|
@ -96,7 +99,7 @@ impl<R: Read, W: Write> Encoder<R, W> {
|
||||||
char::try_from(obuf[2]).unwrap(),
|
char::try_from(obuf[2]).unwrap(),
|
||||||
char::try_from(obuf[3]).unwrap()
|
char::try_from(obuf[3]).unwrap()
|
||||||
)?;
|
)?;
|
||||||
if pad > 0 {
|
if outlen < 4 {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue