summaryrefslogtreecommitdiffstats
path: root/openpgp/src/armor.rs
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2018-09-05 12:19:22 +0200
committerJustus Winter <justus@sequoia-pgp.org>2018-09-05 13:08:10 +0200
commit9b99496473c82830d8d6991ee4e1b2a5437b1681 (patch)
treefccb4def27b530475e230718717f5eb2d55db009 /openpgp/src/armor.rs
parent2e9d49a927f6b7cb4c57a65dfc5fdb5d3a9ba334 (diff)
openpgp: Fix error handling in the armor encoder.
- If writing out the stash fails, we might end up with a stash of size 3. - Fixes #73.
Diffstat (limited to 'openpgp/src/armor.rs')
-rw-r--r--openpgp/src/armor.rs8
1 files changed, 6 insertions, 2 deletions
diff --git a/openpgp/src/armor.rs b/openpgp/src/armor.rs
index 4a82355b..f7e2db60 100644
--- a/openpgp/src/armor.rs
+++ b/openpgp/src/armor.rs
@@ -257,8 +257,9 @@ impl<W: Write> Write for Writer<W> {
let mut written = 0;
// First of all, if there are stashed bytes, fill the stash
- // and encode it.
- assert!(self.stash.len() < 3);
+ // and encode it. If writing out the stash fails below, we
+ // might end up with a stash of size 3.
+ assert!(self.stash.len() <= 3);
if self.stash.len() > 0 {
while self.stash.len() < 3 {
if input.len() == 0 {
@@ -271,7 +272,10 @@ impl<W: Write> Write for Writer<W> {
input = &input[1..];
written += 1;
}
+ assert_eq!(self.stash.len(), 3);
+ // If this fails for some reason, and the caller retries
+ // the write, we might end up with a stash of size 3.
self.sink.write_all(base64::encode_config(&self.stash,
base64::STANDARD_NO_PAD).as_bytes())?;
self.column += 4;