passgen: add fast track field; make security data optional

This commit is contained in:
Luke Granger-Brown 2023-01-23 14:49:11 +00:00
parent 09610ee555
commit 789e31e2d9

View file

@ -351,23 +351,25 @@ impl BoardingPass {
boarding_pass.legs.push(leg); boarding_pass.legs.push(leg);
} }
// What's left is the security data. if data.len() > p {
if data[p] != b'^' { // What's left is the security data.
return Err(anyhow!( if data[p] != b'^' {
"expected security data beginning indicator (^) but got {} ({})", return Err(anyhow!(
data[p], "expected security data beginning indicator (^) but got {} ({})",
data[p] as char data[p],
)); data[p] as char
} ));
boarding_pass.security_data_type = data[p + 1]; }
let security_data_size: usize = boarding_pass.security_data_type = data[p + 1];
usize::from_str_radix(std::str::from_utf8(&data[p + 2..p + 4])?, 16)?; let security_data_size: usize =
boarding_pass.security_data = data[p + 4..p + 4 + security_data_size].to_vec(); usize::from_str_radix(std::str::from_utf8(&data[p + 2..p + 4])?, 16)?;
if data.len() > p + 4 + security_data_size { boarding_pass.security_data = data[p + 4..p + 4 + security_data_size].to_vec();
return Err(anyhow!( if data.len() > p + 4 + security_data_size {
"trailing bytes after security data (expected {} bytes of security data)", return Err(anyhow!(
security_data_size "trailing bytes after security data (expected {} bytes of security data)",
)); security_data_size
));
}
} }
Ok(boarding_pass) Ok(boarding_pass)
@ -397,6 +399,7 @@ pub struct BoardingPassLeg {
pub frequent_flyer_number: Option<String>, pub frequent_flyer_number: Option<String>,
pub id_ad_indicator: Option<char>, pub id_ad_indicator: Option<char>,
pub free_baggage_allowance: Option<String>, pub free_baggage_allowance: Option<String>,
pub fast_track: Option<char>,
pub airline_data: Option<Vec<u8>>, pub airline_data: Option<Vec<u8>>,
} }
@ -444,6 +447,7 @@ impl BoardingPassLeg {
frequent_flyer_number: None, frequent_flyer_number: None,
id_ad_indicator: None, id_ad_indicator: None,
free_baggage_allowance: None, free_baggage_allowance: None,
fast_track: None,
airline_data: None, airline_data: None,
}, },
35, 35,
@ -537,6 +541,14 @@ impl BoardingPassLeg {
}; };
structured_data = &structured_data[3..]; structured_data = &structured_data[3..];
} }
if !structured_data.is_empty() {
self.fast_track = if structured_data[0] == b' ' {
None
} else {
Some(structured_data[0] as char)
};
structured_data = &structured_data[1..];
}
if !structured_data.is_empty() { if !structured_data.is_empty() {
return Err(anyhow!( return Err(anyhow!(
"trailing data in structured data section ({} bytes)", "trailing data in structured data section ({} bytes)",