Skip to content

Commit

Permalink
Merge branch 'main' into node_tty
Browse files Browse the repository at this point in the history
Signed-off-by: Divy Srivastava <[email protected]>
  • Loading branch information
littledivy authored Oct 29, 2023
2 parents 71bae42 + f3b580d commit 74659d0
Show file tree
Hide file tree
Showing 15 changed files with 140 additions and 144 deletions.
185 changes: 99 additions & 86 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ deno_runtime = { version = "0.129.0", path = "./runtime" }
napi_sym = { version = "0.51.0", path = "./cli/napi/sym" }
deno_bench_util = { version = "0.115.0", path = "./bench_util" }
test_util = { path = "./test_util" }
deno_lockfile = "0.17.1"
deno_lockfile = "0.17.2"
deno_media_type = { version = "0.1.1", features = ["module_specifier"] }

# exts
Expand Down Expand Up @@ -118,9 +118,9 @@ rand = "=0.8.5"
regex = "^1.7.0"
lazy-regex = "3"
reqwest = { version = "0.11.20", default-features = false, features = ["rustls-tls", "stream", "gzip", "brotli", "socks", "json"] }
ring = "=0.16.20"
ring = "^0.17.0"
rusqlite = { version = "=0.29.0", features = ["unlock_notify", "bundled"] }
rustls = "0.21.0"
rustls = "0.21.8"
rustls-pemfile = "1.0.0"
rustls-webpki = "0.101.4"
rustls-native-certs = "0.6.2"
Expand Down
6 changes: 3 additions & 3 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ winres.workspace = true

[dependencies]
deno_ast = { workspace = true, features = ["bundler", "cjs", "codegen", "dep_graph", "module_specifier", "proposal", "react", "sourcemap", "transforms", "typescript", "view", "visit"] }
deno_cache_dir = "=0.6.0"
deno_cache_dir = "=0.6.1"
deno_config = "=0.4.0"
deno_core = { workspace = true, features = ["include_js_files_for_snapshotting"] }
deno_doc = "=0.70.0"
Expand All @@ -57,7 +57,7 @@ deno_lockfile.workspace = true
deno_npm = "0.15.2"
deno_runtime = { workspace = true, features = ["dont_create_runtime_snapshot", "exclude_runtime_main_js", "include_js_files_for_snapshotting"] }
deno_semver = "0.5.1"
deno_task_shell = "=0.13.2"
deno_task_shell = "=0.14.0"
eszip = "=0.55.2"
napi_sym.workspace = true

Expand Down Expand Up @@ -103,7 +103,7 @@ once_cell.workspace = true
os_pipe.workspace = true
percent-encoding.workspace = true
pin-project.workspace = true
quick-junit = "^0.3.3"
quick-junit = "^0.3.5"
rand = { workspace = true, features = ["small_rng"] }
regex.workspace = true
ring.workspace = true
Expand Down
6 changes: 3 additions & 3 deletions cli/args/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1123,9 +1123,9 @@ Unless --reload is specified, this command will not re-download already cached d

fn compile_subcommand() -> Command {
Command::new("compile")
.about("UNSTABLE: Compile the script into a self contained executable")
.about("Compile the script into a self contained executable")
.long_about(
"UNSTABLE: Compiles the given script into a self contained executable.
"Compiles the given script into a self contained executable.
deno compile -A https://deno.land/std/http/file_server.ts
deno compile --output color_util https://deno.land/std/examples/colors.ts
Expand All @@ -1152,7 +1152,7 @@ supported in canary.
.arg(
Arg::new("include")
.long("include")
.help("UNSTABLE: Additional module to include in the module graph")
.help("Additional module to include in the module graph")
.long_help(
"Includes an additional module in the compiled executable's module
graph. Use this flag if a dynamically imported module or a web worker main
Expand Down
2 changes: 1 addition & 1 deletion cli/tests/integration/flags_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fn help_output() {
"Bundle module and dependencies into single file",
"Cache the dependencies",
"Type-check the dependencies",
"UNSTABLE: Compile the script into a self contained executable",
"Compile the script into a self contained executable",
"Generate shell completions",
"Print coverage reports",
"Show documentation for a module",
Expand Down
14 changes: 10 additions & 4 deletions cli/tsc/dts/lib.deno.ns.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5911,7 +5911,7 @@ declare namespace Deno {
*
* @category HTTP Server
*/
export interface Server {
export interface HttpServer {
/** A promise that resolves once server finishes - eg. when aborted using
* the signal passed to {@linkcode ServeOptions.signal}.
*/
Expand All @@ -5929,6 +5929,12 @@ declare namespace Deno {
unref(): void;
}

/**
* @category HTTP Server
* @deprecated Use {@linkcode HttpServer} instead.
*/
export type Server = HttpServer;

/** Serves HTTP requests with the given handler.
*
* The below example serves with the port `8000` on hostname `"127.0.0.1"`.
Expand All @@ -5939,7 +5945,7 @@ declare namespace Deno {
*
* @category HTTP Server
*/
export function serve(handler: ServeHandler): Server;
export function serve(handler: ServeHandler): HttpServer;
/** Serves HTTP requests with the given option bag and handler.
*
* You can specify an object with a port and hostname option, which is the
Expand Down Expand Up @@ -5999,7 +6005,7 @@ declare namespace Deno {
export function serve(
options: ServeOptions | ServeTlsOptions,
handler: ServeHandler,
): Server;
): HttpServer;
/** Serves HTTP requests with the given option bag.
*
* You can specify an object with a port and hostname option, which is the
Expand Down Expand Up @@ -6027,5 +6033,5 @@ declare namespace Deno {
*/
export function serve(
options: ServeInit & (ServeOptions | ServeTlsOptions),
): Server;
): HttpServer;
}
2 changes: 1 addition & 1 deletion cli/tsc/dts/lib.deno.unstable.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1941,7 +1941,7 @@ declare namespace Deno {
*
* @category HTTP Server
*/
export interface Server {
export interface HttpServer {
/** Gracefully close the server. No more new connections will be accepted,
* while pending requests will be allowed to finish.
*/
Expand Down
2 changes: 1 addition & 1 deletion ext/crypto/generate_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ fn generate_key_hmac(

length
} else {
hash.digest_algorithm().block_len
hash.digest_algorithm().block_len()
};

let rng = ring::rand::SystemRandom::new();
Expand Down
5 changes: 4 additions & 1 deletion ext/crypto/import_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,10 +556,12 @@ fn import_key_ec_jwk(
}
};

let rng = ring::rand::SystemRandom::new();
let _key_pair = EcdsaKeyPair::from_private_key_and_public_key(
key_alg,
private_d.as_bytes(),
point_bytes.as_ref(),
&rng,
);

Ok(ImportKeyResult::Ec {
Expand Down Expand Up @@ -658,8 +660,9 @@ fn import_key_ec(
}
};

let rng = ring::rand::SystemRandom::new();
// deserialize pkcs8 using ring crate, to VALIDATE public key
let _private_key = EcdsaKeyPair::from_pkcs8(signing_alg, &data)?;
let _private_key = EcdsaKeyPair::from_pkcs8(signing_alg, &data, &rng)?;

// 11.
if named_curve != pk_named_curve {
Expand Down
8 changes: 5 additions & 3 deletions ext/crypto/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,8 @@ pub async fn op_crypto_sign_key(
let curve: &EcdsaSigningAlgorithm =
args.named_curve.ok_or_else(not_supported)?.try_into()?;

let key_pair = EcdsaKeyPair::from_pkcs8(curve, &args.key.data)?;
let rng = RingRand::SystemRandom::new();
let key_pair = EcdsaKeyPair::from_pkcs8(curve, &args.key.data, &rng)?;
// We only support P256-SHA256 & P384-SHA384. These are recommended signature pairs.
// https://briansmith.org/rustdoc/ring/signature/index.html#statics
if let Some(hash) = args.hash {
Expand All @@ -276,7 +277,6 @@ pub async fn op_crypto_sign_key(
}
};

let rng = RingRand::SystemRandom::new();
let signature = key_pair.sign(&rng, data)?;

// Signature data as buffer.
Expand Down Expand Up @@ -388,7 +388,9 @@ pub async fn op_crypto_verify_key(

let public_key_bytes = match args.key.r#type {
KeyType::Private => {
private_key = EcdsaKeyPair::from_pkcs8(signing_alg, &args.key.data)?;
let rng = RingRand::SystemRandom::new();
private_key =
EcdsaKeyPair::from_pkcs8(signing_alg, &args.key.data, &rng)?;

private_key.public_key().as_ref()
}
Expand Down
2 changes: 1 addition & 1 deletion ext/ffi/repr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ pub fn op_ffi_buf_copy_into<FP>(
state: &mut OpState,
src: *mut c_void,
#[number] offset: isize,
#[buffer] dst: &mut [u8],
#[anybuffer] dst: &mut [u8],
#[number] len: usize,
) -> Result<(), AnyError>
where
Expand Down
21 changes: 5 additions & 16 deletions ext/http/00_serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -435,29 +435,18 @@ function fastSyncResponseOrStream(req, respBody, status) {
*/
function mapToCallback(context, callback, onError) {
const signal = context.abortController.signal;
const hasCallback = callback.length > 0;
const hasOneCallback = callback.length === 1;

return async function (req) {
// Get the response from the user-provided callback. If that fails, use onError. If that fails, return a fallback
// 500 error.
let innerRequest;
let response;
try {
if (hasCallback) {
innerRequest = new InnerRequest(req, context);
const request = fromInnerRequest(innerRequest, signal, "immutable");
if (hasOneCallback) {
response = await callback(request);
} else {
response = await callback(
request,
new ServeHandlerInfo(innerRequest),
);
}
} else {
response = await callback();
}
innerRequest = new InnerRequest(req, context);
response = await callback(
fromInnerRequest(innerRequest, signal, "immutable"),
new ServeHandlerInfo(innerRequest),
);
} catch (error) {
try {
response = await onError(error);
Expand Down
2 changes: 1 addition & 1 deletion ext/node/ops/crypto/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ fn ec_generate(
let pkcs8 = EcdsaKeyPair::generate_pkcs8(curve, &rng)
.map_err(|_| type_error("Failed to generate EC key"))?;

let public_key = EcdsaKeyPair::from_pkcs8(curve, pkcs8.as_ref())
let public_key = EcdsaKeyPair::from_pkcs8(curve, pkcs8.as_ref(), &rng)
.map_err(|_| type_error("Failed to generate EC key"))?
.public_key()
.as_ref()
Expand Down
21 changes: 1 addition & 20 deletions runtime/ops/tty.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.

use std::io::Error;
use std::io::IsTerminal;

use deno_core::error::AnyError;
use deno_core::op2;
use deno_core::OpState;
use deno_core::ResourceHandle;

#[cfg(unix)]
use deno_core::ResourceId;
Expand Down Expand Up @@ -167,24 +165,7 @@ fn op_stdin_set_raw(
#[op2(fast)]
fn op_isatty(state: &mut OpState, rid: u32) -> Result<bool, AnyError> {
let handle = state.resource_table.get_handle(rid)?;
// TODO(mmastrac): this can migrate to the deno_core implementation when it lands
Ok(match handle {
ResourceHandle::Fd(fd) if handle.is_valid() => {
#[cfg(windows)]
{
// SAFETY: The resource remains open for the for the duration of borrow_raw
unsafe {
std::os::windows::io::BorrowedHandle::borrow_raw(fd).is_terminal()
}
}
#[cfg(unix)]
{
// SAFETY: The resource remains open for the for the duration of borrow_raw
unsafe { std::os::fd::BorrowedFd::borrow_raw(fd).is_terminal() }
}
}
_ => false,
})
Ok(handle.is_terminal())
}

#[op2(fast)]
Expand Down
2 changes: 2 additions & 0 deletions test_ffi/tests/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,8 @@ const into2 = new Uint8Array(3);
const into2ptr = Deno.UnsafePointer.of(into2);
const into2ptrView = new Deno.UnsafePointerView(into2ptr);
const into3 = new Uint8Array(3);
const into4 = new Uint16Array(3);
ptrView.copyInto(into4);
ptrView.copyInto(into);
console.log([...into]);
ptrView.copyInto(into2, 3);
Expand Down

0 comments on commit 74659d0

Please sign in to comment.