summaryrefslogtreecommitdiff
path: root/ext/crypto/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'ext/crypto/lib.rs')
-rw-r--r--ext/crypto/lib.rs73
1 files changed, 45 insertions, 28 deletions
diff --git a/ext/crypto/lib.rs b/ext/crypto/lib.rs
index ef32499b9..0cb8ed994 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 {