mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-20 18:12:53 +00:00
LibCrypto: Make PKSystem
methods return ErrorOr
Make `encrypt`, `decrypt`, `sign` and `verify` return `ErrorOr` for better error propagation.
This commit is contained in:
parent
6ba627b047
commit
df05cc8478
Notes:
github-actions[bot]
2025-01-12 00:14:44 +00:00
Author: https://github.com/devgianlu
Commit: df05cc8478
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3225
Reviewed-by: https://github.com/alimpfard
Reviewed-by: https://github.com/gmta ✅
9 changed files with 68 additions and 82 deletions
|
@ -691,7 +691,9 @@ WebIDL::ExceptionOr<GC::Ref<JS::ArrayBuffer>> RSAOAEP::encrypt(AlgorithmParams c
|
|||
auto ciphertext_bytes = ciphertext.bytes();
|
||||
|
||||
auto rsa = ::Crypto::PK::RSA { public_key };
|
||||
rsa.encrypt(padding, ciphertext_bytes);
|
||||
auto maybe_encrypt_error = rsa.encrypt(padding, ciphertext_bytes);
|
||||
if (maybe_encrypt_error.is_error())
|
||||
return WebIDL::OperationError::create(realm, "Failed to encrypt"_string);
|
||||
|
||||
// 6. Return the result of creating an ArrayBuffer containing ciphertext.
|
||||
return JS::ArrayBuffer::create(realm, move(ciphertext));
|
||||
|
@ -723,7 +725,9 @@ WebIDL::ExceptionOr<GC::Ref<JS::ArrayBuffer>> RSAOAEP::decrypt(AlgorithmParams c
|
|||
|
||||
auto padding = TRY_OR_THROW_OOM(vm, ByteBuffer::create_uninitialized(private_key_length));
|
||||
auto padding_bytes = padding.bytes();
|
||||
rsa.decrypt(ciphertext, padding_bytes);
|
||||
auto maybe_encrypt_error = rsa.decrypt(ciphertext, padding_bytes);
|
||||
if (maybe_encrypt_error.is_error())
|
||||
return WebIDL::OperationError::create(realm, "Failed to encrypt"_string);
|
||||
|
||||
auto error_message = MUST(String::formatted("Invalid hash function '{}'", hash));
|
||||
ErrorOr<ByteBuffer> maybe_plaintext = Error::from_string_view(error_message.bytes_as_string_view());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue