LibWeb: Implement importKey for RSA-OAEP

This commit is contained in:
Andrew Kaster 2024-03-14 21:57:32 -06:00 committed by Andrew Kaster
parent 28dc076764
commit a0623a47de
Notes: sideshowbarker 2024-07-17 05:05:51 +09:00
5 changed files with 421 additions and 3 deletions

View file

@ -87,6 +87,21 @@ struct RsaHashedKeyGenParams : public RsaKeyGenParams {
static JS::ThrowCompletionOr<NonnullOwnPtr<AlgorithmParams>> from_value(JS::VM&, JS::Value);
};
// https://w3c.github.io/webcrypto/#dfn-RsaHashedImportParams
struct RsaHashedImportParams : public AlgorithmParams {
virtual ~RsaHashedImportParams() override;
RsaHashedImportParams(String name, HashAlgorithmIdentifier hash)
: AlgorithmParams(move(name))
, hash(move(hash))
{
}
HashAlgorithmIdentifier hash;
static JS::ThrowCompletionOr<NonnullOwnPtr<AlgorithmParams>> from_value(JS::VM&, JS::Value);
};
class AlgorithmMethods {
public:
virtual ~AlgorithmMethods();
@ -125,6 +140,8 @@ protected:
class RSAOAEP : public AlgorithmMethods {
public:
virtual WebIDL::ExceptionOr<Variant<JS::NonnullGCPtr<CryptoKey>, JS::NonnullGCPtr<CryptoKeyPair>>> generate_key(AlgorithmParams const&, bool, Vector<Bindings::KeyUsage> const&) override;
virtual WebIDL::ExceptionOr<JS::NonnullGCPtr<CryptoKey>> import_key(AlgorithmParams const&, Bindings::KeyFormat, CryptoKey::InternalKeyData, bool, Vector<Bindings::KeyUsage> const&) override;
virtual WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::Object>> export_key(Bindings::KeyFormat, JS::NonnullGCPtr<CryptoKey>) override;
static NonnullOwnPtr<AlgorithmMethods> create(JS::Realm& realm) { return adopt_own(*new RSAOAEP(realm)); }
@ -163,5 +180,6 @@ private:
};
ErrorOr<String> base64_url_uint_encode(::Crypto::UnsignedBigInteger);
WebIDL::ExceptionOr<::Crypto::UnsignedBigInteger> base64_url_uint_decode(JS::Realm&, String const& base64_url_string);
}