summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Applications/Mail/MailWidget.cpp4
-rw-r--r--Userland/Applications/PixelPaint/Image.cpp7
-rw-r--r--Userland/Libraries/LibCrypto/ASN1/PEM.cpp4
-rw-r--r--Userland/Libraries/LibHTTP/HttpRequest.cpp2
-rw-r--r--Userland/Libraries/LibWeb/Bindings/WindowObject.cpp2
-rw-r--r--Userland/Libraries/LibWeb/Loader/ResourceLoader.cpp4
-rw-r--r--Userland/Utilities/base64.cpp8
-rw-r--r--Userland/Utilities/telws.cpp6
8 files changed, 16 insertions, 21 deletions
diff --git a/Userland/Applications/Mail/MailWidget.cpp b/Userland/Applications/Mail/MailWidget.cpp
index 15c01513f7..e5e6670233 100644
--- a/Userland/Applications/Mail/MailWidget.cpp
+++ b/Userland/Applications/Mail/MailWidget.cpp
@@ -499,7 +499,9 @@ void MailWidget::selected_email_to_load()
if (selected_alternative_encoding.equals_ignoring_case("7bit") || selected_alternative_encoding.equals_ignoring_case("8bit")) {
decoded_data = encoded_data;
} else if (selected_alternative_encoding.equals_ignoring_case("base64")) {
- decoded_data = decode_base64(encoded_data).value_or(ByteBuffer());
+ auto decoded_base64 = decode_base64(encoded_data);
+ if (!decoded_base64.is_error())
+ decoded_data = decoded_base64.release_value();
} else if (selected_alternative_encoding.equals_ignoring_case("quoted-printable")) {
decoded_data = IMAP::decode_quoted_printable(encoded_data);
} else {
diff --git a/Userland/Applications/PixelPaint/Image.cpp b/Userland/Applications/PixelPaint/Image.cpp
index c16f337d95..b61152a4ae 100644
--- a/Userland/Applications/PixelPaint/Image.cpp
+++ b/Userland/Applications/PixelPaint/Image.cpp
@@ -88,11 +88,8 @@ ErrorOr<NonnullRefPtr<Image>> Image::try_create_from_pixel_paint_json(JsonObject
auto name = layer_object.get("name").as_string();
auto bitmap_base64_encoded = layer_object.get("bitmap").as_string();
- auto bitmap_data = decode_base64(bitmap_base64_encoded);
- if (!bitmap_data.has_value())
- return Error::from_string_literal("Base64 decode failed"sv);
-
- auto bitmap = TRY(try_decode_bitmap(bitmap_data.value()));
+ auto bitmap_data = TRY(decode_base64(bitmap_base64_encoded));
+ auto bitmap = TRY(try_decode_bitmap(bitmap_data));
auto layer = TRY(Layer::try_create_with_bitmap(*image, move(bitmap), name));
auto width = layer_object.get("width").to_i32();
diff --git a/Userland/Libraries/LibCrypto/ASN1/PEM.cpp b/Userland/Libraries/LibCrypto/ASN1/PEM.cpp
index 90f957cfc9..a23bed08bf 100644
--- a/Userland/Libraries/LibCrypto/ASN1/PEM.cpp
+++ b/Userland/Libraries/LibCrypto/ASN1/PEM.cpp
@@ -35,8 +35,8 @@ ByteBuffer decode_pem(ReadonlyBytes data)
break;
}
auto b64decoded = decode_base64(lexer.consume_line().trim_whitespace(TrimMode::Right));
- if (!b64decoded.has_value()) {
- dbgln("Failed to decode PEM, likely bad Base64");
+ if (b64decoded.is_error()) {
+ dbgln("Failed to decode PEM: {}", b64decoded.error().string_literal());
return {};
}
if (decoded.try_append(b64decoded.value().data(), b64decoded.value().size()).is_error()) {
diff --git a/Userland/Libraries/LibHTTP/HttpRequest.cpp b/Userland/Libraries/LibHTTP/HttpRequest.cpp
index fc8e003694..034bc56766 100644
--- a/Userland/Libraries/LibHTTP/HttpRequest.cpp
+++ b/Userland/Libraries/LibHTTP/HttpRequest.cpp
@@ -198,7 +198,7 @@ Optional<HttpRequest::BasicAuthenticationCredentials> HttpRequest::parse_http_ba
if (token.is_empty())
return {};
auto decoded_token_bb = decode_base64(token);
- if (!decoded_token_bb.has_value())
+ if (decoded_token_bb.is_error())
return {};
auto decoded_token = String::copy(decoded_token_bb.value());
auto colon_index = decoded_token.find(':');
diff --git a/Userland/Libraries/LibWeb/Bindings/WindowObject.cpp b/Userland/Libraries/LibWeb/Bindings/WindowObject.cpp
index 85eaf2632d..88a20ab02a 100644
--- a/Userland/Libraries/LibWeb/Bindings/WindowObject.cpp
+++ b/Userland/Libraries/LibWeb/Bindings/WindowObject.cpp
@@ -340,7 +340,7 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::atob)
return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::BadArgCountOne, "atob");
auto string = TRY(vm.argument(0).to_string(global_object));
auto decoded = decode_base64(StringView(string));
- if (!decoded.has_value())
+ if (decoded.is_error())
return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::InvalidFormat, "Base64");
// decode_base64() returns a byte string. LibJS uses UTF-8 for strings. Use Latin1Decoder to convert bytes 128-255 to UTF-8.
diff --git a/Userland/Libraries/LibWeb/Loader/ResourceLoader.cpp b/Userland/Libraries/LibWeb/Loader/ResourceLoader.cpp
index cb41f1ea73..818a992bb8 100644
--- a/Userland/Libraries/LibWeb/Loader/ResourceLoader.cpp
+++ b/Userland/Libraries/LibWeb/Loader/ResourceLoader.cpp
@@ -162,8 +162,8 @@ void ResourceLoader::load(LoadRequest& request, Function<void(ReadonlyBytes, con
ByteBuffer data;
if (url.data_payload_is_base64()) {
auto data_maybe = decode_base64(url.data_payload());
- if (!data_maybe.has_value()) {
- auto error_message = "Base64 data contains an invalid character"sv;
+ if (data_maybe.is_error()) {
+ auto error_message = data_maybe.error().string_literal();
log_failure(request, error_message);
error_callback(error_message, {});
return;
diff --git a/Userland/Utilities/base64.cpp b/Userland/Utilities/base64.cpp
index 0febee2374..c612e39cea 100644
--- a/Userland/Utilities/base64.cpp
+++ b/Userland/Utilities/base64.cpp
@@ -46,12 +46,8 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
TRY(Core::System::pledge("stdio"));
if (decode) {
- auto decoded = decode_base64(StringView(buffer));
- if (!decoded.has_value()) {
- warnln("base64: invalid input");
- return 1;
- }
- fwrite(decoded.value().data(), sizeof(u8), decoded.value().size(), stdout);
+ auto decoded = TRY(decode_base64(StringView(buffer)));
+ fwrite(decoded.data(), sizeof(u8), decoded.size(), stdout);
return 0;
}
diff --git a/Userland/Utilities/telws.cpp b/Userland/Utilities/telws.cpp
index 502b13fc8b..7d70d6f68b 100644
--- a/Userland/Utilities/telws.cpp
+++ b/Userland/Utilities/telws.cpp
@@ -119,10 +119,10 @@ int main(int argc, char** argv)
}
auto base64_data = line.substring(8);
auto buffer = decode_base64(base64_data);
- if (buffer.has_value()) {
- socket->send(buffer.value(), false);
+ if (buffer.is_error()) {
+ outln("Could not send message : {}", buffer.error().string_literal());
} else {
- outln("Could not send message : Base64 string contains an invalid character.");
+ socket->send(buffer.value(), false);
}
continue;
}