Skip to content
Snippets Groups Projects
Commit c973618e authored by James Munns's avatar James Munns
Browse files

Options should be parsed even if there is no token

parent 670c3aae
No related branches found
No related tags found
No related merge requests found
...@@ -199,23 +199,21 @@ impl Packet { ...@@ -199,23 +199,21 @@ impl Packet {
match header_result { match header_result {
Ok(header) => { Ok(header) => {
let token_length = header.get_token_length(); let token_length = header.get_token_length();
let (mut token, mut payload) = (Vec::new(), Vec::new()); let options_start: usize = 4 + token_length as usize;
let mut options: BTreeMap<usize, LinkedList<Vec<u8>>> = BTreeMap::new();
if token_length > 0 {
if token_length > 8 { if token_length > 8 {
return Err(ParseError::InvalidTokenLength); return Err(ParseError::InvalidTokenLength);
} }
let options_start: usize = 4 + token_length as usize;
if options_start > buf.len() { if options_start > buf.len() {
return Err(ParseError::InvalidTokenLength); return Err(ParseError::InvalidTokenLength);
} }
token = buf[4..options_start].to_vec(); let token = buf[4..options_start].to_vec();
let mut idx = options_start; let mut idx = options_start;
let mut options_number = 0; let mut options_number = 0;
let mut options: BTreeMap<usize, LinkedList<Vec<u8>>> = BTreeMap::new();
while idx < buf.len() { while idx < buf.len() {
let byte = buf[idx]; let byte = buf[idx];
...@@ -283,10 +281,11 @@ impl Packet { ...@@ -283,10 +281,11 @@ impl Packet {
idx += length; idx += length;
} }
let mut payload = Vec::new();
if idx < buf.len() { if idx < buf.len() {
payload = buf[(idx + 1)..buf.len()].to_vec(); payload = buf[(idx + 1)..buf.len()].to_vec();
} }
}
Ok(Packet { Ok(Packet {
header: header, header: header,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment