summaryrefslogtreecommitdiff
path: root/ext/crypto/lib.rs
diff options
context:
space:
mode:
authorDivy Srivastava <dj.srivastava23@gmail.com>2021-09-16 13:28:29 +0530
committerGitHub <noreply@github.com>2021-09-16 09:58:29 +0200
commit868f38d4528bae508fdb222402441ba374db0721 (patch)
tree73aac0f9b3f063d80a8b35378bd17c0ba746fb9a /ext/crypto/lib.rs
parent9270cad67cffefa4c7ced8361580834d92a00732 (diff)
fix(ext/crypto): use DataError in importKey() (#12071)
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 {