summaryrefslogtreecommitdiff
path: root/AK/Base64.cpp
AgeCommit message (Collapse)Author
2022-01-24AK+Userland: Make AK::decode_base64 return ErrorOrSam Atkins
2022-01-24Everywhere: Convert ByteBuffer factory methods from Optional -> ErrorOrSam Atkins
Apologies for the enormous commit, but I don't see a way to split this up nicely. In the vast majority of cases it's a simple change. A few extra places can use TRY instead of manual error checking though. :^)
2021-11-11Everywhere: Pass AK::StringView by valueAndreas Kling
2021-10-23AK+Everywhere: Make Base64 decoding fallibleBen Wiederhake
2021-10-23AK: Don't crash on invalid Base64 inputBen Wiederhake
In the long-term, we should probably have a way to signal decoding failure. For now, it should suffice to at least not crash. This is particularly relevant because apparently this can be triggered while parsing a PEM certificate, which happens during every TLS connection. Found by OSS Fuzz https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=38979
2021-09-06Everywhere: Make ByteBuffer::{create_*,copy}() OOM-safeAli Mohammad Pur
2021-06-09Meta: Disable -Wmaybe-uninitializedAli Mohammad Pur
It's prone to finding "technically uninitialized but can never happen" cases, particularly in Optional<T> and Variant<Ts...>. The general case seems to be that it cannot infer the dependency between Variant's index (or Optional's boolean state) and a particular alternative (or Optional's buffer) being untouched. So it can flag cases like this: ```c++ if (index == StaticIndexForF) new (new_buffer) F(move(*bit_cast<F*>(old_buffer))); ``` The code in that branch can _technically_ make a partially initialized `F`, but that path can never be taken since the buffer holding an object of type `F` and the condition being true are correlated, and so will never be taken _unless_ the buffer holds an object of type `F`. This commit also removed the various 'diagnostic ignored' pragmas used to work around this warning, as they no longer do anything.
2021-05-22AK: Use calculate_base64_encoded_length in encode_base64Idan Horowitz
We were accidentally calling calculate_base64_decoded_length instead, which resulted in extra allocations during the StringBuilder::append calls that can be avoided.
2021-05-03AK: Silence -Wmaybe-uninitialized warningGunnar Beutner
Adding -fno-semantic-interposition to the GCC command line caused this new warning. I don't see how output.data() could be uninitialized here. Also, commenting out the ensure_capacity() call for the Vector also gets rid of this warning.
2021-04-22Everything: Move to SPDX license identifiers in all files.Brian Gianforcaro
SPDX License Identifiers are a more compact / standardized way of representing file license information. See: https://spdx.dev/resources/use/#identifiers This was done with the `ambr` search and replace tool. ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-03-04Everywhere: Remove unnecessary `clang-format off`sWilliam McPherson
Mostly due to the fact that clang-format allows aligned comments via AlignTrailingComments. We could also use raw string literals in inline asm, which clang-format deals with properly (and would be nicer in a lot of places).
2020-11-22AK: Fix base64 decoding '/'BenJilks
When creating the lookup table, it wouldn't add the last character
2020-10-13Base64: Pre-allocate size of input and outputLenny Maiorani
Problem: - Output of decode and encode grow as the decode and encode happen. This is inefficient because a large size will require many reallocations. - `const` qualifiers are missing on variables which are not intended to change. Solution: - Since the size of the decoded or encoded message is known prior to starting, calculate the size and set the output to that size immediately. All appends will not incur the reallocation overhead. - Add `const` qualifiers to show intent.
2020-10-13Base64: constexpr initialization of alphabet and lookup tableLenny Maiorani
Problem: - The Base64 alphabet and lookup table are initialized at run-time. This results in an initial start-up cost as well as a boolean evaluation and branch every time the function is called. Solution: - Provide `constexpr` functions which initialize the alphabet and lookup table at compile-time. These can be called and assigned to a `constexpr` variable so that there is no run-time cost associated with the initialization or lookup.
2020-08-12AK: Mark compilation-unit-only functions as staticBen Wiederhake
This enables a nice warning in case a function becomes dead code. Also, add forgotten header to Base64.cpp, which would cause an issue later when we enable -Wmissing-declarations.
2020-07-27AK: Change the signature of AK::encode_base64() to use Span.asynts
2020-07-22AK: Make encode_base64 take a ByteBuffer and return a StringNico Weber
That makes the interface symmetric with decode_base64 and it's what all current callers want (except for one, which is buggy).
2020-06-18AK: Add a simple and inefficient Base64 encoderTom Lebreux
The test cases are taken from RFC 4648.
2020-04-26AK: Add a simple and inefficient Base64 decoderAndreas Kling