Truly independent web browser
LibCrypto+LibWeb: Read ML-KEM public keys without an Option
Shannon Booth40fcbca4197f
diff --git a/Libraries/LibCrypto/Rust/src/ml.rs b/Libraries/LibCrypto/Rust/src/ml.rsindex 4e81572f061..5ecea38dc6d 100644--- a/Libraries/LibCrypto/Rust/src/ml.rs+++ b/Libraries/LibCrypto/Rust/src/ml.rs@@ -217,8 +217,8 @@ pub fn mldsa_read_public_key(size: MlDsaSize, bytes: &[u8]) -> Option<KeyHandle>(public_key.size == size).then(|| KeyHandle(Key::MlDsaPublic(public_key)))}-pub fn mlkem_read_public_key(bytes: &[u8]) -> Option<KeyHandle> {- Some(KeyHandle(Key::MlKemPublic(mlkem_public_key_from_bytes(bytes))))+pub fn mlkem_read_public_key(bytes: &[u8]) -> KeyHandle {+ KeyHandle(Key::MlKemPublic(mlkem_public_key_from_bytes(bytes)))}pub fn mldsa_public_bytes(key: &KeyHandle) -> &[u8] {diff --git a/Libraries/LibWeb/Bindings/Rust/src/crypto/crypto_algorithms.rs b/Libraries/LibWeb/Bindings/Rust/src/crypto/crypto_algorithms.rsindex 2902050588b..13c3c1f703e 100644--- a/Libraries/LibWeb/Bindings/Rust/src/crypto/crypto_algorithms.rs+++ b/Libraries/LibWeb/Bindings/Rust/src/crypto/crypto_algorithms.rs@@ -12912,13 +12912,6 @@ impl AlgorithmMethods for MlDsa {}}-fn mlkem_read_public_key(vm: &Vm, bytes: &[u8]) -> WebIdlResult<Ref<CryptoKey>> {- let Some(key) = libcrypto_rust::mlkem_read_public_key(bytes) else {- return Err(dom_error("DataError", b"Invalid key"));- };- Ok(CryptoKey::create(vm, key))-}-#[derive(Clone, Trace)]#[gc(crate = libjs_rust)]pub(crate) struct MlKem;@@ -13094,7 +13087,7 @@ impl AlgorithmMethods for MlKem {};// 8. Let key be a new CryptoKey that represents publicKey.- key = mlkem_read_public_key(cx.vm(), &public_key)?;+ key = CryptoKey::create(cx.vm(), libcrypto_rust::mlkem_read_public_key(&public_key));// 9. Set the [[type]] internal slot of key to "public"key.set_type(KeyType::Public);@@ -13212,7 +13205,7 @@ impl AlgorithmMethods for MlKem {};// 3. Let key be a new CryptoKey that represents the ML-KEM public key data in data.- key = mlkem_read_public_key(cx.vm(), data.as_slice())?;+ key = CryptoKey::create(cx.vm(), libcrypto_rust::mlkem_read_public_key(data.as_slice()));// 4. Set the [[type]] internal slot of key to "public"key.set_type(KeyType::Public);