mirror of
https://github.com/chirpstack/chirpstack.git
synced 2025-01-30 23:53:54 +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")]
|
||||
EuiPrefixFormat,
|
||||
|
||||
#[error("DevAddrPrefix max prefix size is 32")]
|
||||
DevAddrPrefixSize,
|
||||
|
||||
#[error("EuiPrefix max prefix size is 64")]
|
||||
EuiPrefixSize,
|
||||
|
||||
#[error(transparent)]
|
||||
FromHexError(#[from] hex::FromHexError),
|
||||
}
|
||||
|
@ -146,6 +146,10 @@ impl FromStr for DevAddrPrefix {
|
||||
.parse()
|
||||
.map_err(|_| error::Error::DevAddrPrefixFormat)?;
|
||||
|
||||
if size > 32 {
|
||||
return Err(error::Error::DevAddrPrefixSize);
|
||||
}
|
||||
|
||||
Ok(DevAddrPrefix(mask, size))
|
||||
}
|
||||
}
|
||||
@ -237,6 +241,10 @@ impl FromStr for EuiPrefix {
|
||||
.parse()
|
||||
.map_err(|_| error::Error::EuiPrefixFormat)?;
|
||||
|
||||
if size > 64 {
|
||||
return Err(error::Error::EuiPrefixSize);
|
||||
}
|
||||
|
||||
Ok(EuiPrefix(mask, size))
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user