Skip to content

Commit

Permalink
Merge pull request #3 from saleel/saleel/optimizations
Browse files Browse the repository at this point in the history
chore: improve encode length calc
  • Loading branch information
grjte authored Oct 28, 2024
2 parents 1b51198 + 61f8541 commit ed82d92
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/encoder.nr
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,12 @@ impl Base64EncodeBE {
let non_padded_output_length = OutputElements - num_padding_chars;

// Assert that the output length is correct
// Every 3 chars will be encoded as 4 base64 chars
let encoded_length = (InputBytes + 2) / 3 * 4; // ceil(input * 4 / 3)
if self.pad {
assert((InputBytes + 2) / 3 * 4 == OutputElements, "invalid output length");
assert(encoded_length == OutputElements, "invalid output length");
} else {
assert(
((InputBytes + 2) / 3 * 4) - num_padding_chars == OutputElements,
"invalid output length",
);
assert(encoded_length - num_padding_chars == OutputElements, "invalid output length");
}

let mut result: [u8; OutputElements] = [0; OutputElements];
Expand Down

0 comments on commit ed82d92

Please sign in to comment.