Skip to content

Commit 4e6f967

Browse files
committed
Switch from cryptox to crypto namespace
Also drop javy_ prefix in anticipation of switching to winter cg.
1 parent f379f9a commit 4e6f967

File tree

6 files changed

+21
-22
lines changed

6 files changed

+21
-22
lines changed

crates/config/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ bitflags! {
3131
const JAVY_STREAM_IO = 1 << 2;
3232
const REDIRECT_STDOUT_TO_STDERR = 1 << 3;
3333
const TEXT_ENCODING = 1 << 4;
34-
const JAVY_CRYPTOX = 1 << 5;
34+
const CRYPTO = 1 << 5;
3535
}
3636
}
3737

@@ -45,6 +45,6 @@ mod tests {
4545
assert!(Config::JAVY_STREAM_IO == Config::from_bits(1 << 2).unwrap());
4646
assert!(Config::REDIRECT_STDOUT_TO_STDERR == Config::from_bits(1 << 3).unwrap());
4747
assert!(Config::TEXT_ENCODING == Config::from_bits(1 << 4).unwrap());
48-
assert!(Config::JAVY_CRYPTOX == Config::from_bits(1 << 5).unwrap());
48+
assert!(Config::CRYPTO == Config::from_bits(1 << 5).unwrap());
4949
}
5050
}

crates/core/src/runtime.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub(crate) fn new(shared_config: SharedConfig) -> Result<Runtime> {
1313
// fix forward.
1414
.override_json_parse_and_stringify(false)
1515
.javy_json(false)
16-
.javy_cryptox(shared_config.contains(SharedConfig::JAVY_CRYPTOX));
16+
.crypto(shared_config.contains(SharedConfig::CRYPTO));
1717

1818
Runtime::new(std::mem::take(config))
1919
}

crates/javy/src/apis/cryptox/mod.rs crates/javy/src/apis/crypto/mod.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,13 @@ use hmac::{Hmac, Mac};
1010

1111
/// An implemetation of crypto APIs to optimize fuel.
1212
/// Currently, hmacSHA256 is the only function implemented.
13-
pub struct Cryptox;
13+
pub struct Crypto;
1414

15-
impl Intrinsic for Cryptox {
15+
impl Intrinsic for Crypto {
1616
unsafe fn add_intrinsic(ctx: std::ptr::NonNull<qjs::JSContext>) {
17-
register(Ctx::from_raw(ctx)).expect("`Cryptox` APIs to succeed")
17+
register(Ctx::from_raw(ctx)).expect("`Crypto` APIs to succeed")
1818
}
1919
}
20-
2120
fn register(this: Ctx<'_>) -> Result<()> {
2221
let globals = this.globals();
2322

@@ -32,7 +31,7 @@ fn register(this: Ctx<'_>) -> Result<()> {
3231
}),
3332
)?;
3433

35-
globals.set("cryptox", crypto_obj)?;
34+
globals.set("crypto", crypto_obj)?;
3635

3736
Ok::<_, Error>(())
3837
}
@@ -72,14 +71,14 @@ mod tests {
7271
#[test]
7372
fn test_text_encoder_decoder() -> Result<()> {
7473
let mut config = Config::default();
75-
config.javy_cryptox(true);
74+
config.crypto(true);
7675
let runtime = Runtime::new(config)?;
7776

7877
runtime.context().with(|this| {
7978
let result: Value<'_> = this.eval(
8079
r#"
8180
let expectedHex = "97d2a569059bbcd8ead4444ff99071f4c01d005bcefe0d3567e1be628e5fdcd9";
82-
let result = cryptox.hmacSHA256("my secret and secure key", "input message");
81+
let result = crypto.hmacSHA256("my secret and secure key", "input message");
8382
expectedHex === result;
8483
"#,
8584
)?;
@@ -89,4 +88,4 @@ mod tests {
8988
})?;
9089
Ok(())
9190
}
92-
}
91+
}

crates/javy/src/apis/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@ pub(crate) mod json;
6262
pub(crate) mod random;
6363
pub(crate) mod stream_io;
6464
pub(crate) mod text_encoding;
65-
pub(crate) mod cryptox;
65+
pub(crate) mod crypto;
6666

6767
pub(crate) use console::*;
6868
#[cfg(feature = "json")]
6969
pub(crate) use json::*;
7070
pub(crate) use random::*;
7171
pub(crate) use stream_io::*;
7272
pub(crate) use text_encoding::*;
73-
pub(crate) use cryptox::*;
73+
pub(crate) use crypto::*;

crates/javy/src/config.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ bitflags! {
1919
const OPERATORS = 1 << 12;
2020
const BIGNUM_EXTENSION = 1 << 13;
2121
const TEXT_ENCODING = 1 << 14;
22+
const CRYPTO = 1 << 15;
2223
}
2324
}
2425

@@ -38,7 +39,6 @@ bitflags! {
3839
pub(crate) struct JavyIntrinsics: u32 {
3940
const STREAM_IO = 1;
4041
const JSON = 1 << 1;
41-
const CRYPTOX = 1 << 2;
4242
}
4343
}
4444

@@ -180,11 +180,11 @@ impl Config {
180180
self
181181
}
182182

183-
/// Whether the `Javy.CRYPTOX` intrinsic will be available.
183+
/// Whether the `crypto` intrinsic will be available.
184184
/// Enabled by default.
185-
// #[cfg(feature = "cryptox")]
186-
pub fn javy_cryptox(&mut self, enable: bool) -> &mut Self {
187-
self.javy_intrinsics.set(JavyIntrinsics::CRYPTOX, enable);
185+
// #[cfg(feature = "crypto")]
186+
pub fn crypto(&mut self, enable: bool) -> &mut Self {
187+
self.intrinsics.set(JSIntrinsics::CRYPTO, enable);
188188
self
189189
}
190190

crates/javy/src/runtime.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// use crate::quickjs::JSContextRef;
22
use super::from_js_error;
33
use crate::{
4-
apis::{Cryptox, Console, NonStandardConsole, Random, StreamIO, TextEncoding},
4+
apis::{Crypto, Console, NonStandardConsole, Random, StreamIO, TextEncoding},
55
config::{JSIntrinsics, JavyIntrinsics},
66
Config,
77
};
@@ -145,10 +145,10 @@ impl Runtime {
145145
}
146146
}
147147

148-
if javy_intrinsics.contains(JavyIntrinsics::CRYPTOX) {
149-
// #[cfg(feature = "cryptox")]
148+
if intrinsics.contains(JSIntrinsics::CRYPTO) {
149+
// #[cfg(feature = "crypto")]
150150
unsafe {
151-
Cryptox::add_intrinsic(ctx.as_raw())
151+
Crypto::add_intrinsic(ctx.as_raw())
152152
}
153153
}
154154
});

0 commit comments

Comments
 (0)