BigUint(0) bug fixed (encode_base127)

This commit is contained in:
nyamnyam
2019-09-12 10:16:53 +09:00
parent 5b62a49298
commit 7c8e01f5b2

View File

@@ -983,6 +983,11 @@ fn encode_base127(v: &BigUint) -> Vec<u8> {
let u128 = BigUint::from_u8(128).unwrap();
let zero = BigUint::zero();
if acc == zero {
res.push(0);
return res;
}
while acc > zero {
// we build this vector backwards
let digit = &acc % &u128;
@@ -1494,4 +1499,12 @@ mod tests {
can_parse("test/server.bin").unwrap();
can_parse("test/key.bin").unwrap();
}
#[test]
fn encode_base127_zero() {
let zero = BigUint::from(0 as u64);
let encoded = encode_base127(&zero);
let expected: Vec::<u8> = vec![0x0];
assert_eq!(expected, encoded);
}
}