passgen: add fast track field; make security data optional
This commit is contained in:
parent
09610ee555
commit
789e31e2d9
1 changed files with 29 additions and 17 deletions
|
@ -351,23 +351,25 @@ impl BoardingPass {
|
|||
boarding_pass.legs.push(leg);
|
||||
}
|
||||
|
||||
// What's left is the security data.
|
||||
if data[p] != b'^' {
|
||||
return Err(anyhow!(
|
||||
"expected security data beginning indicator (^) but got {} ({})",
|
||||
data[p],
|
||||
data[p] as char
|
||||
));
|
||||
}
|
||||
boarding_pass.security_data_type = data[p + 1];
|
||||
let security_data_size: usize =
|
||||
usize::from_str_radix(std::str::from_utf8(&data[p + 2..p + 4])?, 16)?;
|
||||
boarding_pass.security_data = data[p + 4..p + 4 + security_data_size].to_vec();
|
||||
if data.len() > p + 4 + security_data_size {
|
||||
return Err(anyhow!(
|
||||
"trailing bytes after security data (expected {} bytes of security data)",
|
||||
security_data_size
|
||||
));
|
||||
if data.len() > p {
|
||||
// What's left is the security data.
|
||||
if data[p] != b'^' {
|
||||
return Err(anyhow!(
|
||||
"expected security data beginning indicator (^) but got {} ({})",
|
||||
data[p],
|
||||
data[p] as char
|
||||
));
|
||||
}
|
||||
boarding_pass.security_data_type = data[p + 1];
|
||||
let security_data_size: usize =
|
||||
usize::from_str_radix(std::str::from_utf8(&data[p + 2..p + 4])?, 16)?;
|
||||
boarding_pass.security_data = data[p + 4..p + 4 + security_data_size].to_vec();
|
||||
if data.len() > p + 4 + security_data_size {
|
||||
return Err(anyhow!(
|
||||
"trailing bytes after security data (expected {} bytes of security data)",
|
||||
security_data_size
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
Ok(boarding_pass)
|
||||
|
@ -397,6 +399,7 @@ pub struct BoardingPassLeg {
|
|||
pub frequent_flyer_number: Option<String>,
|
||||
pub id_ad_indicator: Option<char>,
|
||||
pub free_baggage_allowance: Option<String>,
|
||||
pub fast_track: Option<char>,
|
||||
pub airline_data: Option<Vec<u8>>,
|
||||
}
|
||||
|
||||
|
@ -444,6 +447,7 @@ impl BoardingPassLeg {
|
|||
frequent_flyer_number: None,
|
||||
id_ad_indicator: None,
|
||||
free_baggage_allowance: None,
|
||||
fast_track: None,
|
||||
airline_data: None,
|
||||
},
|
||||
35,
|
||||
|
@ -537,6 +541,14 @@ impl BoardingPassLeg {
|
|||
};
|
||||
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() {
|
||||
return Err(anyhow!(
|
||||
"trailing data in structured data section ({} bytes)",
|
||||
|
|
Loading…
Reference in a new issue