mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-27 10:07:15 +02:00
LibWeb: Support the importing of ml-kem keys in raw-public format
This commit is contained in:
Notes:
github-actions[bot]
2026-01-06 00:08:04 +00:00
Author: https://github.com/tete17 Commit: https://github.com/LadybirdBrowser/ladybird/commit/0fc7746b963 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/7320 Reviewed-by: https://github.com/shannonbooth ✅
@@ -9140,7 +9140,33 @@ WebIDL::ExceptionOr<GC::Ref<CryptoKey>> MLKEM::import_key(AlgorithmParams const&
|
||||
key->set_usages(usages);
|
||||
}
|
||||
// FIXME: -> If format is "pkcs8":
|
||||
// FIXME: -> If format is "raw-public":
|
||||
// -> If format is "raw-public":
|
||||
else if (key_format == Bindings::KeyFormat::RawPublic) {
|
||||
// 1. If usages contains a value which is not "encapsulateKey" or "encapsulateBits" then throw a SyntaxError.
|
||||
for (auto const usage : usages) {
|
||||
if (usage != Bindings::KeyUsage::Encapsulatekey && usage != Bindings::KeyUsage::Encapsulatebits)
|
||||
return WebIDL::SyntaxError::create(m_realm, Utf16String::formatted("Invalid key usage '{}'", idl_enum_to_string(usage)));
|
||||
}
|
||||
|
||||
// 2. Let data be keyData.
|
||||
auto const& data = key_data;
|
||||
|
||||
// 3. Let key be a new CryptoKey that represents the ML-KEM public key data in data.
|
||||
ASSERT(data.has<ByteBuffer>());
|
||||
key = CryptoKey::create(m_realm, ::Crypto::PK::MLKEMPublicKey { data.get<ByteBuffer>() });
|
||||
|
||||
// 4. Set the [[type]] internal slot of key to "public"
|
||||
key->set_type(Bindings::KeyType::Public);
|
||||
|
||||
// 5. Let algorithm be a new KeyAlgorithm object.
|
||||
auto algorithm = KeyAlgorithm::create(m_realm);
|
||||
|
||||
// 6. Set the name attribute of algorithm to the name attribute of normalizedAlgorithm.
|
||||
algorithm->set_name(params.name);
|
||||
|
||||
// 6. Set the [[algorithm]] internal slot of key to algorithm.
|
||||
key->set_algorithm(algorithm);
|
||||
}
|
||||
// FIXME: -> If format is "raw-seed":
|
||||
// FIXME: -> If format is "jwk":
|
||||
// -> Otherwise:
|
||||
|
||||
Reference in New Issue
Block a user