Skip to content

Commit

Permalink
Use add_padding now that it uses encoded len
Browse files Browse the repository at this point in the history
  • Loading branch information
marshallpierce committed Feb 5, 2023
1 parent 7831083 commit d175648
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions src/chunked_encoder.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use crate::{
encode::add_padding,
engine::{Config, Engine},
};
#[cfg(any(feature = "alloc", feature = "std", test))]
use alloc::string::String;
#[cfg(any(feature = "alloc", feature = "std", test))]
use core::str;

use crate::engine::{Config, Engine};

/// The output mechanism for ChunkedEncoder's encoded bytes.
pub trait Sink {
type Error;
Expand All @@ -31,13 +33,9 @@ impl<'e, E: Engine + ?Sized> ChunkedEncoder<'e, E> {
for chunk in bytes.chunks(CHUNK_SIZE) {
let mut len = self.engine.internal_encode(chunk, &mut buf);
if chunk.len() != CHUNK_SIZE && self.engine.config().encode_padding() {
// Final, potentially partial, chunk. Pad output to multiple of
// four bytes if required by config.
let padding = 4 - (len % 4);
if padding != 4 {
buf[len..(len + padding)].fill(crate::PAD_BYTE);
len += padding;
}
// Final, potentially partial, chunk.
// Pad output to multiple of four bytes if required by config.
len += add_padding(len, &mut buf[len..]);
}
sink.write_encoded_bytes(&buf[..len])?;
}
Expand Down

0 comments on commit d175648

Please sign in to comment.