summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJustus Winter <justus@pep-project.org>2017-11-28 14:53:54 +0100
committerJustus Winter <justus@pep-project.org>2017-11-28 14:57:25 +0100
commit4399a10f0e5baada52a8019b12a4cfb818cef135 (patch)
treef1d4116f23bbc9027a6d8aa6346ce5c88be048ff /src
parent1c5b8fb42d22ea58481d8539e0f7638cbeaf31c2 (diff)
Return the correct number of bytes written.
- Return the number of unencoded bytes written. Assert that the return value is sane. - Improve the test so that it demonstrates the problem.
Diffstat (limited to 'src')
-rw-r--r--src/armor.rs6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/armor.rs b/src/armor.rs
index e070d2ab..39628caf 100644
--- a/src/armor.rs
+++ b/src/armor.rs
@@ -207,15 +207,17 @@ impl<'a, W: Write> Write for Writer<'a, W> {
// We know that we have a multiple of 3 bytes, encode them and write them out.
assert!(input.len() % 3 == 0);
let encoded = base64::encode_config(input, base64::STANDARD_NO_PAD);
+ written += input.len();
let mut enc = encoded.as_bytes();
while enc.len() > 0 {
let n = min(LINE_LENGTH - self.column, enc.len());
self.sink.write_all(&enc[..n])?;
enc = &enc[n..];
- written += n;
self.column += n;
self.linebreak()?;
}
+
+ assert_eq!(written, buf.len());
Ok(written)
}
@@ -535,7 +537,7 @@ mod test {
let mut buf = Vec::new();
{
let mut w = Writer::new(&mut buf, Kind::File);
- w.write(&bin).unwrap();
+ w.write_all(&bin).unwrap();
}
assert_eq!(String::from_utf8_lossy(&buf),
String::from_utf8_lossy(&asc));