summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
Diffstat (limited to 'ext')
-rw-r--r--ext/crypto/Cargo.toml2
-rw-r--r--ext/crypto/generate_key.rs12
-rw-r--r--ext/crypto/lib.rs105
-rw-r--r--ext/tls/Cargo.toml2
-rw-r--r--ext/tls/lib.rs5
5 files changed, 62 insertions, 64 deletions
diff --git a/ext/crypto/Cargo.toml b/ext/crypto/Cargo.toml
index 90cb3ceb3..67f549c4c 100644
--- a/ext/crypto/Cargo.toml
+++ b/ext/crypto/Cargo.toml
@@ -20,8 +20,8 @@ block-modes = "0.8.1"
deno_core = { version = "0.111.0", path = "../../core" }
deno_web = { version = "0.60.0", path = "../web" }
elliptic-curve = { version = "0.10.6", features = ["std", "pem"] }
-lazy_static = "1.4.0"
num-traits = "0.2.14"
+once_cell = "=1.9.0"
p256 = { version = "0.9.0", features = ["ecdh"] }
p384 = "0.8.0"
rand = "0.8.4"
diff --git a/ext/crypto/generate_key.rs b/ext/crypto/generate_key.rs
index 7ed841297..190a8b424 100644
--- a/ext/crypto/generate_key.rs
+++ b/ext/crypto/generate_key.rs
@@ -1,11 +1,13 @@
use std::cell::RefCell;
use std::rc::Rc;
+use crate::shared::*;
use deno_core::error::AnyError;
use deno_core::OpState;
use deno_core::ZeroCopyBuf;
use elliptic_curve::rand_core::OsRng;
use num_traits::FromPrimitive;
+use once_cell::sync::Lazy;
use ring::rand::SecureRandom;
use ring::signature::EcdsaKeyPair;
use rsa::pkcs1::ToRsaPrivateKey;
@@ -13,13 +15,11 @@ use rsa::BigUint;
use rsa::RsaPrivateKey;
use serde::Deserialize;
-use crate::shared::*;
-
// Allowlist for RSA public exponents.
-lazy_static::lazy_static! {
- static ref PUB_EXPONENT_1: BigUint = BigUint::from_u64(3).unwrap();
- static ref PUB_EXPONENT_2: BigUint = BigUint::from_u64(65537).unwrap();
-}
+static PUB_EXPONENT_1: Lazy<BigUint> =
+ Lazy::new(|| BigUint::from_u64(3).unwrap());
+static PUB_EXPONENT_2: Lazy<BigUint> =
+ Lazy::new(|| BigUint::from_u64(65537).unwrap());
#[derive(Deserialize)]
#[serde(rename_all = "camelCase", tag = "algorithm")]
diff --git a/ext/crypto/lib.rs b/ext/crypto/lib.rs
index b46b27d74..1bca433ff 100644
--- a/ext/crypto/lib.rs
+++ b/ext/crypto/lib.rs
@@ -17,8 +17,6 @@ use std::num::NonZeroU32;
use std::rc::Rc;
use block_modes::BlockMode;
-use lazy_static::lazy_static;
-use num_traits::cast::FromPrimitive;
use p256::elliptic_curve::sec1::FromEncodedPoint;
use p256::pkcs8::FromPrivateKey;
use rand::rngs::OsRng;
@@ -42,7 +40,6 @@ use rsa::pkcs1::der::Encodable;
use rsa::pkcs1::FromRsaPrivateKey;
use rsa::pkcs1::FromRsaPublicKey;
use rsa::pkcs8::der::asn1;
-use rsa::BigUint;
use rsa::PublicKey;
use rsa::RsaPrivateKey;
use rsa::RsaPublicKey;
@@ -73,12 +70,7 @@ use crate::key::HkdfOutput;
use crate::shared::ID_MFG1;
use crate::shared::ID_P_SPECIFIED;
use crate::shared::ID_SHA1_OID;
-
-// Allowlist for RSA public exponents.
-lazy_static! {
- static ref PUB_EXPONENT_1: BigUint = BigUint::from_u64(3).unwrap();
- static ref PUB_EXPONENT_2: BigUint = BigUint::from_u64(65537).unwrap();
-}
+use once_cell::sync::Lazy;
pub fn init(maybe_seed: Option<u64>) -> Extension {
Extension::builder()
@@ -642,53 +634,64 @@ const SALT_LENGTH_TAG: rsa::pkcs8::der::TagNumber =
const P_SOURCE_ALGORITHM_TAG: rsa::pkcs8::der::TagNumber =
rsa::pkcs8::der::TagNumber::new(2);
-lazy_static! {
- // Default HashAlgorithm for RSASSA-PSS-params (sha1)
- //
- // sha1 HashAlgorithm ::= {
- // algorithm id-sha1,
- // parameters SHA1Parameters : NULL
- // }
- //
- // SHA1Parameters ::= NULL
- static ref SHA1_HASH_ALGORITHM: rsa::pkcs8::AlgorithmIdentifier<'static> = rsa::pkcs8::AlgorithmIdentifier {
- // id-sha1
- oid: ID_SHA1_OID,
- // NULL
- parameters: Some(asn1::Any::from(asn1::Null)),
- };
+// Default HashAlgorithm for RSASSA-PSS-params (sha1)
+//
+// sha1 HashAlgorithm ::= {
+// algorithm id-sha1,
+// parameters SHA1Parameters : NULL
+// }
+//
+// SHA1Parameters ::= NULL
+static SHA1_HASH_ALGORITHM: Lazy<rsa::pkcs8::AlgorithmIdentifier<'static>> =
+ Lazy::new(|| {
+ rsa::pkcs8::AlgorithmIdentifier {
+ // id-sha1
+ oid: ID_SHA1_OID,
+ // NULL
+ parameters: Some(asn1::Any::from(asn1::Null)),
+ }
+ });
- // TODO(@littledivy): `pkcs8` should provide AlgorithmIdentifier to Any conversion.
- static ref ENCODED_SHA1_HASH_ALGORITHM: Vec<u8> = SHA1_HASH_ALGORITHM.to_vec().unwrap();
- // Default MaskGenAlgrithm for RSASSA-PSS-params (mgf1SHA1)
- //
- // mgf1SHA1 MaskGenAlgorithm ::= {
- // algorithm id-mgf1,
- // parameters HashAlgorithm : sha1
- // }
- static ref MGF1_SHA1_MASK_ALGORITHM: rsa::pkcs8::AlgorithmIdentifier<'static> = rsa::pkcs8::AlgorithmIdentifier {
+// TODO(@littledivy): `pkcs8` should provide AlgorithmIdentifier to Any conversion.
+static ENCODED_SHA1_HASH_ALGORITHM: Lazy<Vec<u8>> =
+ Lazy::new(|| SHA1_HASH_ALGORITHM.to_vec().unwrap());
+// Default MaskGenAlgrithm for RSASSA-PSS-params (mgf1SHA1)
+//
+// mgf1SHA1 MaskGenAlgorithm ::= {
+// algorithm id-mgf1,
+// parameters HashAlgorithm : sha1
+// }
+static MGF1_SHA1_MASK_ALGORITHM: Lazy<
+ rsa::pkcs8::AlgorithmIdentifier<'static>,
+> = Lazy::new(|| {
+ rsa::pkcs8::AlgorithmIdentifier {
// id-mgf1
oid: ID_MFG1,
// sha1
- parameters: Some(asn1::Any::from_der(&ENCODED_SHA1_HASH_ALGORITHM).unwrap()),
- };
+ parameters: Some(
+ asn1::Any::from_der(&ENCODED_SHA1_HASH_ALGORITHM).unwrap(),
+ ),
+ }
+});
- // Default PSourceAlgorithm for RSAES-OAEP-params
- // The default label is an empty string.
- //
- // pSpecifiedEmpty PSourceAlgorithm ::= {
- // algorithm id-pSpecified,
- // parameters EncodingParameters : emptyString
- // }
- //
- // emptyString EncodingParameters ::= ''H
- static ref P_SPECIFIED_EMPTY: rsa::pkcs8::AlgorithmIdentifier<'static> = rsa::pkcs8::AlgorithmIdentifier {
- // id-pSpecified
- oid: ID_P_SPECIFIED,
- // EncodingParameters
- parameters: Some(asn1::Any::from(asn1::OctetString::new(b"").unwrap())),
- };
-}
+// Default PSourceAlgorithm for RSAES-OAEP-params
+// The default label is an empty string.
+//
+// pSpecifiedEmpty PSourceAlgorithm ::= {
+// algorithm id-pSpecified,
+// parameters EncodingParameters : emptyString
+// }
+//
+// emptyString EncodingParameters ::= ''H
+static P_SPECIFIED_EMPTY: Lazy<rsa::pkcs8::AlgorithmIdentifier<'static>> =
+ Lazy::new(|| {
+ rsa::pkcs8::AlgorithmIdentifier {
+ // id-pSpecified
+ oid: ID_P_SPECIFIED,
+ // EncodingParameters
+ parameters: Some(asn1::Any::from(asn1::OctetString::new(b"").unwrap())),
+ }
+ });
impl<'a> TryFrom<rsa::pkcs8::der::asn1::Any<'a>>
for PssPrivateKeyParameters<'a>
diff --git a/ext/tls/Cargo.toml b/ext/tls/Cargo.toml
index 2a757f62d..c3bdb5cab 100644
--- a/ext/tls/Cargo.toml
+++ b/ext/tls/Cargo.toml
@@ -15,7 +15,7 @@ path = "lib.rs"
[dependencies]
deno_core = { version = "0.111.0", path = "../../core" }
-lazy_static = "1.4.0"
+once_cell = "=1.9.0"
rustls = { version = "0.20", features = ["dangerous_configuration"] }
rustls-native-certs = "0.6.1"
rustls-pemfile = "0.2.1"
diff --git a/ext/tls/lib.rs b/ext/tls/lib.rs
index bcaf0f1be..a6775b95d 100644
--- a/ext/tls/lib.rs
+++ b/ext/tls/lib.rs
@@ -89,11 +89,6 @@ pub struct BasicAuth {
pub password: String,
}
-lazy_static::lazy_static! {
- static ref CLIENT_SESSION_MEMORY_CACHE: Arc<ClientSessionMemoryCache> =
- Arc::new(ClientSessionMemoryCache::default());
-}
-
#[derive(Default)]
struct ClientSessionMemoryCache(Mutex<HashMap<Vec<u8>, Vec<u8>>>);