diff --git a/ext/crypto/lib.rs b/ext/crypto/lib.rs index ef32499b91..0cb8ed9942 100644 --- a/ext/crypto/lib.rs +++ b/ext/crypto/lib.rs @@ -1007,8 +1007,10 @@ pub async fn op_crypto_import_key( // 7. if let Some(pk_hash) = pk_hash { if pk_hash != hash { - // TODO(@littledivy): DataError - return Err(type_error("Hash mismatch".to_string())); + return Err(custom_error( + "DOMExceptionDataError", + "Hash mismatch".to_string(), + )); } } @@ -1019,15 +1021,16 @@ pub async fn op_crypto_import_key( )?; let bytes_consumed = private_key.encoded_len().map_err(|e| { - // TODO(@littledivy): DataError - custom_error("DOMExceptionOperationError", e.to_string()) + custom_error("DOMExceptionDataError", e.to_string()) })?; if bytes_consumed != rsa::pkcs1::der::Length::new(pk_info.private_key.len() as u16) { - // TODO(@littledivy): DataError - return Err(type_error("Some bytes were not consumed".to_string())); + return Err(custom_error( + "DOMExceptionDataError", + "Some bytes were not consumed".to_string(), + )); } Ok(ImportKeyResult { @@ -1083,9 +1086,9 @@ pub async fn op_crypto_import_key( ID_SHA384_OID => Some(CryptoHash::Sha384), // id-sha256 ID_SHA512_OID => Some(CryptoHash::Sha512), - // TODO(@littledivy): DataError _ => { - return Err(type_error( + return Err(custom_error( + "DOMExceptionDataError", "Unsupported hash algorithm".to_string(), )) } @@ -1100,15 +1103,21 @@ pub async fn op_crypto_import_key( hash } - // TODO(@littledivy): DataError - _ => return Err(type_error("Unsupported algorithm".to_string())), + _ => { + return Err(custom_error( + "DOMExceptionDataError", + "Unsupported algorithm".to_string(), + )) + } }; // 7. if let Some(pk_hash) = pk_hash { if pk_hash != hash { - // TODO(@littledivy): DataError - return Err(type_error("Hash mismatch".to_string())); + return Err(custom_error( + "DOMExceptionDataError", + "Hash mismatch".to_string(), + )); } } @@ -1118,16 +1127,17 @@ pub async fn op_crypto_import_key( |e| custom_error("DOMExceptionOperationError", e.to_string()), )?; - let bytes_consumed = private_key.encoded_len().map_err(|e| { - // TODO(@littledivy): DataError - custom_error("DOMExceptionOperationError", e.to_string()) - })?; + let bytes_consumed = private_key + .encoded_len() + .map_err(|e| custom_error("DataError", e.to_string()))?; if bytes_consumed != rsa::pkcs1::der::Length::new(pk_info.private_key.len() as u16) { - // TODO(@littledivy): DataError - return Err(type_error("Some bytes were not consumed".to_string())); + return Err(custom_error( + "DOMExceptionDataError", + "Some bytes were not consumed".to_string(), + )); } Ok(ImportKeyResult { @@ -1183,9 +1193,9 @@ pub async fn op_crypto_import_key( ID_SHA384_OID => Some(CryptoHash::Sha384), // id-sha256 ID_SHA512_OID => Some(CryptoHash::Sha512), - // TODO(@littledivy): DataError _ => { - return Err(type_error( + return Err(custom_error( + "DOMExceptionDataError", "Unsupported hash algorithm".to_string(), )) } @@ -1200,15 +1210,21 @@ pub async fn op_crypto_import_key( hash } - // TODO(@littledivy): DataError - _ => return Err(type_error("Unsupported algorithm".to_string())), + _ => { + return Err(custom_error( + "DOMExceptionDataError", + "Unsupported algorithm".to_string(), + )) + } }; // 7. if let Some(pk_hash) = pk_hash { if pk_hash != hash { - // TODO(@littledivy): DataError - return Err(type_error("Hash mismatch".to_string())); + return Err(custom_error( + "DOMExceptionDataError", + "Hash mismatch".to_string(), + )); } } @@ -1219,15 +1235,16 @@ pub async fn op_crypto_import_key( )?; let bytes_consumed = private_key.encoded_len().map_err(|e| { - // TODO(@littledivy): DataError - custom_error("DOMExceptionOperationError", e.to_string()) + custom_error("DOMExceptionDataError", e.to_string()) })?; if bytes_consumed != rsa::pkcs1::der::Length::new(pk_info.private_key.len() as u16) { - // TODO(@littledivy): DataError - return Err(type_error("Some bytes were not consumed".to_string())); + return Err(custom_error( + "DOMExceptionDataError", + "Some bytes were not consumed".to_string(), + )); } Ok(ImportKeyResult { diff --git a/runtime/js/99_main.js b/runtime/js/99_main.js index 4fa10bad0f..5c1c047664 100644 --- a/runtime/js/99_main.js +++ b/runtime/js/99_main.js @@ -289,6 +289,12 @@ delete Object.prototype.__proto__; return new domException.DOMException(msg, "InvalidCharacterError"); }, ); + core.registerErrorBuilder( + "DOMExceptionDataError", + function DOMExceptionDataError(msg) { + return new domException.DOMException(msg, "DataError"); + }, + ); } class Navigator {