diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2023-03-14 18:35:21 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2023-03-14 18:36:19 +0100 |
commit | b473bf1c9be9d1fe0e8ad76736f07ca20ffe73a5 (patch) | |
tree | 5e0ce0a94f6074c0ab2a658f1f68fdd358b8aa7d | |
parent | 7914568a309b7692bdcb9cebd1b8820c34e71c87 (diff) |
openpgp: Fix labeling fields ending on a 16 byte boundary.
- This is a more comprehensive fix than
bee82c2952512a5585e93f180180ca45468d4f2b.
-rw-r--r-- | openpgp/src/fmt.rs | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/openpgp/src/fmt.rs b/openpgp/src/fmt.rs index 65b1b79c..ea9eec3d 100644 --- a/openpgp/src/fmt.rs +++ b/openpgp/src/fmt.rs @@ -119,10 +119,6 @@ pub mod hex { where B: AsRef<[u8]>, { self.write_labeled(buf, |offset, data| { - if data.is_empty() { - return None; - } - let mut l = String::new(); for _ in 0..offset { l.push(' '); @@ -176,8 +172,9 @@ pub mod hex { self.offset += 1; match self.offset % 16 { 0 => { - if let Some(msg) = labeler( - first_label_offset, &buf[data_start..i + 1]) + if let Some(msg) = Some(&buf[data_start..i + 1]) + .filter(|b| ! b.is_empty()) + .and_then(|b| labeler(first_label_offset, b)) { write!(self.inner, " {}", msg)?; // Only the first label is offset. @@ -191,8 +188,9 @@ pub mod hex { } } - if let Some(msg) = labeler( - first_label_offset, &buf[data_start..]) + if let Some(msg) = Some(&buf[data_start..]) + .filter(|b| ! b.is_empty()) + .and_then(|b| labeler(first_label_offset, b)) { for i in self.offset % 16 .. 16 { if i != 7 { |