summaryrefslogtreecommitdiff
path: root/ext/crypto
diff options
context:
space:
mode:
authorDivy Srivastava <dj.srivastava23@gmail.com>2022-03-14 23:14:15 +0530
committerGitHub <noreply@github.com>2022-03-14 18:44:15 +0100
commitb4e42953e1d243f2eda20e5be6b845d60b7bf688 (patch)
tree10b3bfff165f9c04f9174c7c399d44b9b724c3b3 /ext/crypto
parent4e3ed37037a2aa1edeac260dc3463a81d9cf9b88 (diff)
feat(core): codegen ops (#13861)
Co-authored-by: Aaron O'Mullan <aaron.omullan@gmail.com>
Diffstat (limited to 'ext/crypto')
-rw-r--r--ext/crypto/decrypt.rs2
-rw-r--r--ext/crypto/encrypt.rs3
-rw-r--r--ext/crypto/export_key.rs2
-rw-r--r--ext/crypto/generate_key.rs2
-rw-r--r--ext/crypto/import_key.rs3
-rw-r--r--ext/crypto/lib.rs41
6 files changed, 35 insertions, 18 deletions
diff --git a/ext/crypto/decrypt.rs b/ext/crypto/decrypt.rs
index 801e72ea0..a8666de89 100644
--- a/ext/crypto/decrypt.rs
+++ b/ext/crypto/decrypt.rs
@@ -24,6 +24,7 @@ use ctr::Ctr;
use deno_core::error::custom_error;
use deno_core::error::type_error;
use deno_core::error::AnyError;
+use deno_core::op;
use deno_core::OpState;
use deno_core::ZeroCopyBuf;
use rsa::pkcs1::FromRsaPrivateKey;
@@ -76,6 +77,7 @@ pub enum DecryptAlgorithm {
},
}
+#[op]
pub async fn op_crypto_decrypt(
_state: Rc<RefCell<OpState>>,
opts: DecryptOptions,
diff --git a/ext/crypto/encrypt.rs b/ext/crypto/encrypt.rs
index 63f8af889..b93ca0952 100644
--- a/ext/crypto/encrypt.rs
+++ b/ext/crypto/encrypt.rs
@@ -16,6 +16,7 @@ use aes_gcm::AeadInPlace;
use aes_gcm::NewAead;
use aes_gcm::Nonce;
use ctr::Ctr;
+use deno_core::op;
use block_modes::BlockMode;
use ctr::cipher::StreamCipher;
@@ -79,6 +80,8 @@ pub enum EncryptAlgorithm {
key_length: usize,
},
}
+
+#[op]
pub async fn op_crypto_encrypt(
_state: Rc<RefCell<OpState>>,
opts: EncryptOptions,
diff --git a/ext/crypto/export_key.rs b/ext/crypto/export_key.rs
index 891aea92a..8131f859d 100644
--- a/ext/crypto/export_key.rs
+++ b/ext/crypto/export_key.rs
@@ -1,5 +1,6 @@
use deno_core::error::custom_error;
use deno_core::error::AnyError;
+use deno_core::op;
use deno_core::OpState;
use deno_core::ZeroCopyBuf;
use rsa::pkcs1::UIntBytes;
@@ -84,6 +85,7 @@ pub enum ExportKeyResult {
},
}
+#[op]
pub fn op_crypto_export_key(
_state: &mut OpState,
opts: ExportKeyOptions,
diff --git a/ext/crypto/generate_key.rs b/ext/crypto/generate_key.rs
index 190a8b424..9fe1b62f4 100644
--- a/ext/crypto/generate_key.rs
+++ b/ext/crypto/generate_key.rs
@@ -3,6 +3,7 @@ use std::rc::Rc;
use crate::shared::*;
use deno_core::error::AnyError;
+use deno_core::op;
use deno_core::OpState;
use deno_core::ZeroCopyBuf;
use elliptic_curve::rand_core::OsRng;
@@ -41,6 +42,7 @@ pub enum GenerateKeyOptions {
},
}
+#[op]
pub async fn op_crypto_generate_key(
_state: Rc<RefCell<OpState>>,
opts: GenerateKeyOptions,
diff --git a/ext/crypto/import_key.rs b/ext/crypto/import_key.rs
index b929f38bb..3d29c9947 100644
--- a/ext/crypto/import_key.rs
+++ b/ext/crypto/import_key.rs
@@ -1,4 +1,5 @@
use deno_core::error::AnyError;
+use deno_core::op;
use deno_core::OpState;
use deno_core::ZeroCopyBuf;
use elliptic_curve::pkcs8::der::Decodable as Pkcs8Decodable;
@@ -81,11 +82,13 @@ pub enum ImportKeyResult {
#[serde(rename_all = "camelCase")]
Ec { raw_data: RawKeyData },
#[serde(rename_all = "camelCase")]
+ #[allow(dead_code)]
Aes { raw_data: RawKeyData },
#[serde(rename_all = "camelCase")]
Hmac { raw_data: RawKeyData },
}
+#[op]
pub fn op_crypto_import_key(
_state: &mut OpState,
opts: ImportKeyOptions,
diff --git a/ext/crypto/lib.rs b/ext/crypto/lib.rs
index 69381e139..3b33830d3 100644
--- a/ext/crypto/lib.rs
+++ b/ext/crypto/lib.rs
@@ -9,8 +9,8 @@ use deno_core::error::not_supported;
use deno_core::error::type_error;
use deno_core::error::AnyError;
use deno_core::include_js_files;
-use deno_core::op_async;
-use deno_core::op_sync;
+use deno_core::op;
+
use deno_core::Extension;
use deno_core::OpState;
use deno_core::ZeroCopyBuf;
@@ -88,22 +88,19 @@ pub fn init(maybe_seed: Option<u64>) -> Extension {
"01_webidl.js",
))
.ops(vec![
- (
- "op_crypto_get_random_values",
- op_sync(op_crypto_get_random_values),
- ),
- ("op_crypto_generate_key", op_async(op_crypto_generate_key)),
- ("op_crypto_sign_key", op_async(op_crypto_sign_key)),
- ("op_crypto_verify_key", op_async(op_crypto_verify_key)),
- ("op_crypto_derive_bits", op_async(op_crypto_derive_bits)),
- ("op_crypto_import_key", op_sync(op_crypto_import_key)),
- ("op_crypto_export_key", op_sync(op_crypto_export_key)),
- ("op_crypto_encrypt", op_async(op_crypto_encrypt)),
- ("op_crypto_decrypt", op_async(op_crypto_decrypt)),
- ("op_crypto_subtle_digest", op_async(op_crypto_subtle_digest)),
- ("op_crypto_random_uuid", op_sync(op_crypto_random_uuid)),
- ("op_crypto_wrap_key", op_sync(op_crypto_wrap_key)),
- ("op_crypto_unwrap_key", op_sync(op_crypto_unwrap_key)),
+ op_crypto_get_random_values::decl(),
+ op_crypto_generate_key::decl(),
+ op_crypto_sign_key::decl(),
+ op_crypto_verify_key::decl(),
+ op_crypto_derive_bits::decl(),
+ op_crypto_import_key::decl(),
+ op_crypto_export_key::decl(),
+ op_crypto_encrypt::decl(),
+ op_crypto_decrypt::decl(),
+ op_crypto_subtle_digest::decl(),
+ op_crypto_random_uuid::decl(),
+ op_crypto_wrap_key::decl(),
+ op_crypto_unwrap_key::decl(),
])
.state(move |state| {
if let Some(seed) = maybe_seed {
@@ -114,6 +111,7 @@ pub fn init(maybe_seed: Option<u64>) -> Extension {
.build()
}
+#[op]
pub fn op_crypto_get_random_values(
state: &mut OpState,
mut zero_copy: ZeroCopyBuf,
@@ -170,6 +168,7 @@ pub struct SignArg {
named_curve: Option<CryptoNamedCurve>,
}
+#[op]
pub async fn op_crypto_sign_key(
_state: Rc<RefCell<OpState>>,
args: SignArg,
@@ -324,6 +323,7 @@ pub struct VerifyArg {
named_curve: Option<CryptoNamedCurve>,
}
+#[op]
pub async fn op_crypto_verify_key(
_state: Rc<RefCell<OpState>>,
args: VerifyArg,
@@ -484,6 +484,7 @@ pub struct DeriveKeyArg {
info: Option<ZeroCopyBuf>,
}
+#[op]
pub async fn op_crypto_derive_bits(
_state: Rc<RefCell<OpState>>,
args: DeriveKeyArg,
@@ -789,6 +790,7 @@ impl<'a> TryFrom<rsa::pkcs8::der::asn1::Any<'a>>
}
}
+#[op]
pub fn op_crypto_random_uuid(
state: &mut OpState,
_: (),
@@ -808,6 +810,7 @@ pub fn op_crypto_random_uuid(
Ok(uuid.to_string())
}
+#[op]
pub async fn op_crypto_subtle_digest(
_state: Rc<RefCell<OpState>>,
algorithm: CryptoHash,
@@ -831,6 +834,7 @@ pub struct WrapUnwrapKeyArg {
algorithm: Algorithm,
}
+#[op]
pub fn op_crypto_wrap_key(
_state: &mut OpState,
args: WrapUnwrapKeyArg,
@@ -860,6 +864,7 @@ pub fn op_crypto_wrap_key(
}
}
+#[op]
pub fn op_crypto_unwrap_key(
_state: &mut OpState,
args: WrapUnwrapKeyArg,