use crate::smb::error::SmbError;
use nom;
use nom::IResult;
pub fn smb_get_unicode_string(blob: &[u8]) -> IResult<&[u8], Vec<u8>, SmbError>
{
SCLogDebug!("get_unicode_string: blob {} {:?}", blob.len(), blob);
let mut name : Vec<u8> = Vec::new();
let mut c = blob;
while c.len() >= 1 {
if c.len() == 1 && c[0] == 0 {
let rem = &c[1..];
SCLogDebug!("get_unicode_string: name {:?}", name);
return Ok((rem, name))
} else if c.len() == 1 {
break;
} else if c[0] == 0 && c[1] == 0 {
let rem = &c[2..];
SCLogDebug!("get_unicode_string: name {:?}", name);
return Ok((rem, name))
}
name.push(c[0]);
c = &c[2..];
}
Err(nom::Err::Error(SmbError::BadEncoding))
}
named!(pub smb_get_ascii_string<&[u8], Vec<u8>, SmbError>,
do_parse!(
s: take_until_and_consume!("\x00")
>> ( s.to_vec() )
));