mirror of
https://github.com/chirpstack/chirpstack.git
synced 2025-02-07 11:10:15 +00:00
Validate prefix size.
This commit is contained in:
parent
21896e65d7
commit
cfadb9c78a
@ -8,6 +8,12 @@ pub enum Error {
|
|||||||
#[error("EuiPrefix must be in the form 0000000000000000/0")]
|
#[error("EuiPrefix must be in the form 0000000000000000/0")]
|
||||||
EuiPrefixFormat,
|
EuiPrefixFormat,
|
||||||
|
|
||||||
|
#[error("DevAddrPrefix max prefix size is 32")]
|
||||||
|
DevAddrPrefixSize,
|
||||||
|
|
||||||
|
#[error("EuiPrefix max prefix size is 64")]
|
||||||
|
EuiPrefixSize,
|
||||||
|
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
FromHexError(#[from] hex::FromHexError),
|
FromHexError(#[from] hex::FromHexError),
|
||||||
}
|
}
|
||||||
|
@ -146,6 +146,10 @@ impl FromStr for DevAddrPrefix {
|
|||||||
.parse()
|
.parse()
|
||||||
.map_err(|_| error::Error::DevAddrPrefixFormat)?;
|
.map_err(|_| error::Error::DevAddrPrefixFormat)?;
|
||||||
|
|
||||||
|
if size > 32 {
|
||||||
|
return Err(error::Error::DevAddrPrefixSize);
|
||||||
|
}
|
||||||
|
|
||||||
Ok(DevAddrPrefix(mask, size))
|
Ok(DevAddrPrefix(mask, size))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -237,6 +241,10 @@ impl FromStr for EuiPrefix {
|
|||||||
.parse()
|
.parse()
|
||||||
.map_err(|_| error::Error::EuiPrefixFormat)?;
|
.map_err(|_| error::Error::EuiPrefixFormat)?;
|
||||||
|
|
||||||
|
if size > 64 {
|
||||||
|
return Err(error::Error::EuiPrefixSize);
|
||||||
|
}
|
||||||
|
|
||||||
Ok(EuiPrefix(mask, size))
|
Ok(EuiPrefix(mask, size))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user