Revert "temporarily comment out checking zero prefixed int"
This reverts commit 500dd1480d
.
This commit is contained in:
parent
4e52aa8f8a
commit
e068bad4e0
@ -274,8 +274,8 @@ pub enum FromBytesError {
|
|||||||
DataIsTooShort,
|
DataIsTooShort,
|
||||||
/// TODO [debris] Please document me
|
/// TODO [debris] Please document me
|
||||||
DataIsTooLong,
|
DataIsTooLong,
|
||||||
// Integer-representation is non-canonically prefixed with zero byte(s).
|
/// Integer-representation is non-canonically prefixed with zero byte(s).
|
||||||
//ZeroPrefixedInt,
|
ZeroPrefixedInt,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StdError for FromBytesError {
|
impl StdError for FromBytesError {
|
||||||
@ -312,9 +312,9 @@ macro_rules! impl_uint_from_bytes {
|
|||||||
match bytes.len() {
|
match bytes.len() {
|
||||||
0 => Ok(0),
|
0 => Ok(0),
|
||||||
l if l <= mem::size_of::<$to>() => {
|
l if l <= mem::size_of::<$to>() => {
|
||||||
//if bytes[0] == 0 {
|
if bytes[0] == 0 {
|
||||||
//return Err(FromBytesError::ZeroPrefixedInt)
|
return Err(FromBytesError::ZeroPrefixedInt)
|
||||||
//}
|
}
|
||||||
let mut res = 0 as $to;
|
let mut res = 0 as $to;
|
||||||
for i in 0..l {
|
for i in 0..l {
|
||||||
let shift = (l - 1 - i) * 8;
|
let shift = (l - 1 - i) * 8;
|
||||||
@ -349,10 +349,9 @@ macro_rules! impl_uint_from_bytes {
|
|||||||
($name: ident) => {
|
($name: ident) => {
|
||||||
impl FromBytes for $name {
|
impl FromBytes for $name {
|
||||||
fn from_bytes(bytes: &[u8]) -> FromBytesResult<$name> {
|
fn from_bytes(bytes: &[u8]) -> FromBytesResult<$name> {
|
||||||
//if !bytes.is_empty() && bytes[0] == 0 {
|
if !bytes.is_empty() && bytes[0] == 0 {
|
||||||
//Err(FromBytesError::ZeroPrefixedInt)
|
Err(FromBytesError::ZeroPrefixedInt)
|
||||||
//} else
|
} else if bytes.len() <= $name::SIZE {
|
||||||
if bytes.len() <= $name::SIZE {
|
|
||||||
Ok($name::from(bytes))
|
Ok($name::from(bytes))
|
||||||
} else {
|
} else {
|
||||||
Err(FromBytesError::DataIsTooLong)
|
Err(FromBytesError::DataIsTooLong)
|
||||||
|
Loading…
Reference in New Issue
Block a user