lrwn: Allow empty string for AES128Key, DevAddr, EUI64 and NetID.

In case an empty string is provided, the default "null" value will be
used.

Fixes #453.
This commit is contained in:
Orne Brocaar 2024-07-11 10:05:23 +01:00
parent 920f485734
commit f76a4b7f83
4 changed files with 12 additions and 4 deletions

View File

@ -62,7 +62,9 @@ impl FromStr for AES128Key {
type Err = Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
let mut bytes: [u8; 16] = [0; 16];
hex::decode_to_slice(s, &mut bytes)?;
if !s.is_empty() {
hex::decode_to_slice(s, &mut bytes)?;
}
Ok(AES128Key(bytes))
}
}

View File

@ -234,7 +234,9 @@ impl FromStr for DevAddr {
type Err = Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
let mut bytes: [u8; 4] = [0; 4];
hex::decode_to_slice(s, &mut bytes)?;
if !s.is_empty() {
hex::decode_to_slice(s, &mut bytes)?;
}
Ok(DevAddr(bytes))
}
}

View File

@ -70,7 +70,9 @@ impl FromStr for EUI64 {
type Err = Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
let mut bytes: [u8; 8] = [0; 8];
hex::decode_to_slice(s, &mut bytes)?;
if !s.is_empty() {
hex::decode_to_slice(s, &mut bytes)?;
}
Ok(EUI64(bytes))
}
}

View File

@ -129,7 +129,9 @@ impl FromStr for NetID {
fn from_str(s: &str) -> Result<Self, Self::Err> {
let mut bytes: [u8; 3] = [0; 3];
hex::decode_to_slice(s, &mut bytes)?;
if !s.is_empty() {
hex::decode_to_slice(s, &mut bytes)?;
}
Ok(NetID(bytes))
}