1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

chore: enable clippy unused_async rule (#22834)

This commit is contained in:
David Sherret 2024-03-11 23:48:00 -04:00 committed by GitHub
parent c38c14f51f
commit ad6b00a2bf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
38 changed files with 411 additions and 408 deletions

View file

@ -83,20 +83,17 @@ impl CliFactoryBuilder {
} }
} }
pub async fn build_from_flags( pub fn build_from_flags(self, flags: Flags) -> Result<CliFactory, AnyError> {
self,
flags: Flags,
) -> Result<CliFactory, AnyError> {
Ok(self.build_from_cli_options(Arc::new(CliOptions::from_flags(flags)?))) Ok(self.build_from_cli_options(Arc::new(CliOptions::from_flags(flags)?)))
} }
pub async fn build_from_flags_for_watcher( pub fn build_from_flags_for_watcher(
mut self, mut self,
flags: Flags, flags: Flags,
watcher_communicator: Arc<WatcherCommunicator>, watcher_communicator: Arc<WatcherCommunicator>,
) -> Result<CliFactory, AnyError> { ) -> Result<CliFactory, AnyError> {
self.watcher_communicator = Some(watcher_communicator); self.watcher_communicator = Some(watcher_communicator);
self.build_from_flags(flags).await self.build_from_flags(flags)
} }
pub fn build_from_cli_options(self, options: Arc<CliOptions>) -> CliFactory { pub fn build_from_cli_options(self, options: Arc<CliOptions>) -> CliFactory {
@ -190,8 +187,8 @@ pub struct CliFactory {
} }
impl CliFactory { impl CliFactory {
pub async fn from_flags(flags: Flags) -> Result<Self, AnyError> { pub fn from_flags(flags: Flags) -> Result<Self, AnyError> {
CliFactoryBuilder::new().build_from_flags(flags).await CliFactoryBuilder::new().build_from_flags(flags)
} }
pub fn from_cli_options(options: Arc<CliOptions>) -> Self { pub fn from_cli_options(options: Arc<CliOptions>) -> Self {

View file

@ -415,7 +415,7 @@ pub fn collect_test(
} }
/// Return tsc navigation tree code lenses. /// Return tsc navigation tree code lenses.
pub async fn collect_tsc( pub fn collect_tsc(
specifier: &ModuleSpecifier, specifier: &ModuleSpecifier,
code_lens_settings: &CodeLensSettings, code_lens_settings: &CodeLensSettings,
line_index: Arc<LineIndex>, line_index: Arc<LineIndex>,

View file

@ -786,7 +786,7 @@ impl Inner {
}) })
} }
pub async fn update_cache(&mut self) -> Result<(), AnyError> { pub fn update_cache(&mut self) -> Result<(), AnyError> {
let mark = self.performance.mark("lsp.update_cache"); let mark = self.performance.mark("lsp.update_cache");
self.performance.measure(mark); self.performance.measure(mark);
let maybe_cache = &self.config.workspace_settings().cache; let maybe_cache = &self.config.workspace_settings().cache;
@ -816,23 +816,17 @@ impl Inner {
None None
}; };
if self.maybe_global_cache_path != maybe_global_cache_path { if self.maybe_global_cache_path != maybe_global_cache_path {
self self.set_new_global_cache_path(maybe_global_cache_path)?;
.set_new_global_cache_path(maybe_global_cache_path)
.await?;
} }
Ok(()) Ok(())
} }
async fn recreate_http_client_and_dependents( fn recreate_http_client_and_dependents(&mut self) -> Result<(), AnyError> {
&mut self, self.set_new_global_cache_path(self.maybe_global_cache_path.clone())
) -> Result<(), AnyError> {
self
.set_new_global_cache_path(self.maybe_global_cache_path.clone())
.await
} }
/// Recreates the http client and all dependent structs. /// Recreates the http client and all dependent structs.
async fn set_new_global_cache_path( fn set_new_global_cache_path(
&mut self, &mut self,
new_cache_path: Option<PathBuf>, new_cache_path: Option<PathBuf>,
) -> Result<(), AnyError> { ) -> Result<(), AnyError> {
@ -1025,21 +1019,21 @@ impl Inner {
async fn update_registries(&mut self) -> Result<(), AnyError> { async fn update_registries(&mut self) -> Result<(), AnyError> {
let mark = self.performance.mark("lsp.update_registries"); let mark = self.performance.mark("lsp.update_registries");
self.recreate_http_client_and_dependents().await?; self.recreate_http_client_and_dependents()?;
let workspace_settings = self.config.workspace_settings(); let workspace_settings = self.config.workspace_settings();
for (registry, enabled) in workspace_settings.suggest.imports.hosts.iter() { for (registry, enabled) in workspace_settings.suggest.imports.hosts.iter() {
if *enabled { if *enabled {
lsp_log!("Enabling import suggestions for: {}", registry); lsp_log!("Enabling import suggestions for: {}", registry);
self.module_registries.enable(registry).await?; self.module_registries.enable(registry).await?;
} else { } else {
self.module_registries.disable(registry).await?; self.module_registries.disable(registry)?;
} }
} }
self.performance.measure(mark); self.performance.measure(mark);
Ok(()) Ok(())
} }
async fn update_config_file(&mut self) -> Result<(), AnyError> { fn update_config_file(&mut self) -> Result<(), AnyError> {
self.config.clear_config_file(); self.config.clear_config_file();
self.fmt_options = FmtOptions::new_with_base(self.initial_cwd.clone()); self.fmt_options = FmtOptions::new_with_base(self.initial_cwd.clone());
self.lint_options = LintOptions::new_with_base(self.initial_cwd.clone()); self.lint_options = LintOptions::new_with_base(self.initial_cwd.clone());
@ -1064,7 +1058,7 @@ impl Inner {
self.config.set_config_file(config_file); self.config.set_config_file(config_file);
self.lint_options = lint_options; self.lint_options = lint_options;
self.fmt_options = fmt_options; self.fmt_options = fmt_options;
self.recreate_http_client_and_dependents().await?; self.recreate_http_client_and_dependents()?;
if let Some(config_file) = self.config.maybe_config_file() { if let Some(config_file) = self.config.maybe_config_file() {
if let Ok((compiler_options, _)) = config_file.to_compiler_options() { if let Ok((compiler_options, _)) = config_file.to_compiler_options() {
if let Some(compiler_options_obj) = compiler_options.as_object() { if let Some(compiler_options_obj) = compiler_options.as_object() {
@ -1278,11 +1272,11 @@ impl Inner {
self.update_debug_flag(); self.update_debug_flag();
// Check to see if we need to change the cache path // Check to see if we need to change the cache path
if let Err(err) = self.update_cache().await { if let Err(err) = self.update_cache() {
lsp_warn!("Error updating cache: {:#}", err); lsp_warn!("Error updating cache: {:#}", err);
self.client.show_message(MessageType::WARNING, err); self.client.show_message(MessageType::WARNING, err);
} }
if let Err(err) = self.update_config_file().await { if let Err(err) = self.update_config_file() {
lsp_warn!("Error updating config file: {:#}", err); lsp_warn!("Error updating config file: {:#}", err);
self.client.show_message(MessageType::WARNING, err); self.client.show_message(MessageType::WARNING, err);
} }
@ -1349,11 +1343,11 @@ impl Inner {
self.refresh_npm_specifiers().await; self.refresh_npm_specifiers().await;
} }
async fn shutdown(&self) -> LspResult<()> { fn shutdown(&self) -> LspResult<()> {
Ok(()) Ok(())
} }
async fn did_open( fn did_open(
&mut self, &mut self,
specifier: &ModuleSpecifier, specifier: &ModuleSpecifier,
params: DidOpenTextDocumentParams, params: DidOpenTextDocumentParams,
@ -1475,7 +1469,7 @@ impl Inner {
}; };
self.update_debug_flag(); self.update_debug_flag();
if let Err(err) = self.update_cache().await { if let Err(err) = self.update_cache() {
lsp_warn!("Error updating cache: {:#}", err); lsp_warn!("Error updating cache: {:#}", err);
self.client.show_message(MessageType::WARNING, err); self.client.show_message(MessageType::WARNING, err);
} }
@ -1483,7 +1477,7 @@ impl Inner {
lsp_warn!("Error updating registries: {:#}", err); lsp_warn!("Error updating registries: {:#}", err);
self.client.show_message(MessageType::WARNING, err); self.client.show_message(MessageType::WARNING, err);
} }
if let Err(err) = self.update_config_file().await { if let Err(err) = self.update_config_file() {
lsp_warn!("Error updating config file: {:#}", err); lsp_warn!("Error updating config file: {:#}", err);
self.client.show_message(MessageType::WARNING, err); self.client.show_message(MessageType::WARNING, err);
} }
@ -1601,7 +1595,7 @@ impl Inner {
files_to_check.insert(url.clone()); files_to_check.insert(url.clone());
} }
// Update config. // Update config.
if let Err(err) = self.update_config_file().await { if let Err(err) = self.update_config_file() {
lsp_warn!("Error updating config file: {:#}", err); lsp_warn!("Error updating config file: {:#}", err);
self.client.show_message(MessageType::WARNING, err); self.client.show_message(MessageType::WARNING, err);
} }
@ -2246,7 +2240,7 @@ impl Inner {
)), )),
) )
.await?; .await?;
code_action.edit = refactor_edit_info.to_workspace_edit(self).await?; code_action.edit = refactor_edit_info.to_workspace_edit(self)?;
code_action code_action
} else { } else {
// The code action doesn't need to be resolved // The code action doesn't need to be resolved
@ -2314,7 +2308,6 @@ impl Inner {
line_index, line_index,
&navigation_tree, &navigation_tree,
) )
.await
.map_err(|err| { .map_err(|err| {
error!( error!(
"Error getting ts code lenses for \"{:#}\": {:#}", "Error getting ts code lenses for \"{:#}\": {:#}",
@ -2483,7 +2476,7 @@ impl Inner {
.await?; .await?;
if let Some(definition) = maybe_definition { if let Some(definition) = maybe_definition {
let results = definition.to_definition(line_index, self).await; let results = definition.to_definition(line_index, self);
self.performance.measure(mark); self.performance.measure(mark);
Ok(results) Ok(results)
} else { } else {
@ -2978,7 +2971,6 @@ impl Inner {
let rename_locations = tsc::RenameLocations { locations }; let rename_locations = tsc::RenameLocations { locations };
let workspace_edits = rename_locations let workspace_edits = rename_locations
.into_workspace_edit(&params.new_name, self) .into_workspace_edit(&params.new_name, self)
.await
.map_err(|err| { .map_err(|err| {
error!("Failed to get workspace edits: {:#}", err); error!("Failed to get workspace edits: {:#}", err);
LspError::internal_error() LspError::internal_error()
@ -3426,7 +3418,7 @@ impl tower_lsp::LanguageServer for LanguageServer {
async fn shutdown(&self) -> LspResult<()> { async fn shutdown(&self) -> LspResult<()> {
self.1.cancel(); self.1.cancel();
self.0.write().await.shutdown().await self.0.write().await.shutdown()
} }
async fn did_open(&self, params: DidOpenTextDocumentParams) { async fn did_open(&self, params: DidOpenTextDocumentParams) {
@ -3441,7 +3433,7 @@ impl tower_lsp::LanguageServer for LanguageServer {
let specifier = inner let specifier = inner
.url_map .url_map
.normalize_url(&params.text_document.uri, LspUrlKind::File); .normalize_url(&params.text_document.uri, LspUrlKind::File);
let document = inner.did_open(&specifier, params).await; let document = inner.did_open(&specifier, params);
if document.is_diagnosable() { if document.is_diagnosable() {
inner.refresh_npm_specifiers().await; inner.refresh_npm_specifiers().await;
let specifiers = inner.documents.dependents(&specifier); let specifiers = inner.documents.dependents(&specifier);

View file

@ -488,7 +488,7 @@ impl ModuleRegistry {
} }
/// Disable a registry, removing its configuration, if any, from memory. /// Disable a registry, removing its configuration, if any, from memory.
pub async fn disable(&mut self, origin: &str) -> Result<(), AnyError> { pub fn disable(&mut self, origin: &str) -> Result<(), AnyError> {
let origin = base_url(&Url::parse(origin)?); let origin = base_url(&Url::parse(origin)?);
self.origins.remove(&origin); self.origins.remove(&origin);
Ok(()) Ok(())

View file

@ -213,7 +213,7 @@ impl TestRun {
let args = self.get_args(); let args = self.get_args();
lsp_log!("Executing test run with arguments: {}", args.join(" ")); lsp_log!("Executing test run with arguments: {}", args.join(" "));
let flags = flags_from_vec(args.into_iter().map(String::from).collect())?; let flags = flags_from_vec(args.into_iter().map(String::from).collect())?;
let factory = CliFactory::from_flags(flags).await?; let factory = CliFactory::from_flags(flags)?;
// Various test files should not share the same permissions in terms of // Various test files should not share the same permissions in terms of
// `PermissionsContainer` - otherwise granting/revoking permissions in one // `PermissionsContainer` - otherwise granting/revoking permissions in one
// file would have impact on other files, which is undesirable. // file would have impact on other files, which is undesirable.

View file

@ -2106,7 +2106,7 @@ pub struct RenameLocations {
} }
impl RenameLocations { impl RenameLocations {
pub async fn into_workspace_edit( pub fn into_workspace_edit(
self, self,
new_name: &str, new_name: &str,
language_server: &language_server::Inner, language_server: &language_server::Inner,
@ -2226,7 +2226,7 @@ impl DefinitionInfoAndBoundSpan {
Ok(()) Ok(())
} }
pub async fn to_definition( pub fn to_definition(
&self, &self,
line_index: Arc<LineIndex>, line_index: Arc<LineIndex>,
language_server: &language_server::Inner, language_server: &language_server::Inner,
@ -2609,7 +2609,7 @@ impl RefactorEditInfo {
Ok(()) Ok(())
} }
pub async fn to_workspace_edit( pub fn to_workspace_edit(
&self, &self,
language_server: &language_server::Inner, language_server: &language_server::Inner,
) -> LspResult<Option<lsp::WorkspaceEdit>> { ) -> LspResult<Option<lsp::WorkspaceEdit>> {

View file

@ -109,7 +109,7 @@ async fn run_subcommand(flags: Flags) -> Result<i32, AnyError> {
tools::run::eval_command(flags, eval_flags).await tools::run::eval_command(flags, eval_flags).await
}), }),
DenoSubcommand::Cache(cache_flags) => spawn_subcommand(async move { DenoSubcommand::Cache(cache_flags) => spawn_subcommand(async move {
let factory = CliFactory::from_flags(flags).await?; let factory = CliFactory::from_flags(flags)?;
let module_load_preparer = factory.module_load_preparer().await?; let module_load_preparer = factory.module_load_preparer().await?;
let emitter = factory.emitter()?; let emitter = factory.emitter()?;
let graph_container = factory.graph_container(); let graph_container = factory.graph_container();
@ -119,7 +119,7 @@ async fn run_subcommand(flags: Flags) -> Result<i32, AnyError> {
emitter.cache_module_emits(&graph_container.graph()) emitter.cache_module_emits(&graph_container.graph())
}), }),
DenoSubcommand::Check(check_flags) => spawn_subcommand(async move { DenoSubcommand::Check(check_flags) => spawn_subcommand(async move {
let factory = CliFactory::from_flags(flags).await?; let factory = CliFactory::from_flags(flags)?;
let module_load_preparer = factory.module_load_preparer().await?; let module_load_preparer = factory.module_load_preparer().await?;
module_load_preparer module_load_preparer
.load_and_type_check_files(&check_flags.files) .load_and_type_check_files(&check_flags.files)
@ -137,7 +137,11 @@ async fn run_subcommand(flags: Flags) -> Result<i32, AnyError> {
) )
} }
DenoSubcommand::Init(init_flags) => { DenoSubcommand::Init(init_flags) => {
spawn_subcommand(async { tools::init::init_project(init_flags).await }) spawn_subcommand(async {
// make compiler happy since init_project is sync
tokio::task::yield_now().await;
tools::init::init_project(init_flags)
})
} }
DenoSubcommand::Info(info_flags) => { DenoSubcommand::Info(info_flags) => {
spawn_subcommand(async { tools::info::info(flags, info_flags).await }) spawn_subcommand(async { tools::info::info(flags, info_flags).await })

View file

@ -487,8 +487,7 @@ pub async fn run_benchmarks_with_watch(
let bench_flags = bench_flags.clone(); let bench_flags = bench_flags.clone();
Ok(async move { Ok(async move {
let factory = CliFactoryBuilder::new() let factory = CliFactoryBuilder::new()
.build_from_flags_for_watcher(flags, watcher_communicator.clone()) .build_from_flags_for_watcher(flags, watcher_communicator.clone())?;
.await?;
let cli_options = factory.cli_options(); let cli_options = factory.cli_options();
let bench_options = cli_options.resolve_bench_options(bench_flags)?; let bench_options = cli_options.resolve_bench_options(bench_flags)?;

View file

@ -35,9 +35,10 @@ pub async fn bundle(
move |flags, watcher_communicator, _changed_paths| { move |flags, watcher_communicator, _changed_paths| {
let bundle_flags = bundle_flags.clone(); let bundle_flags = bundle_flags.clone();
Ok(async move { Ok(async move {
let factory = CliFactoryBuilder::new() let factory = CliFactoryBuilder::new().build_from_flags_for_watcher(
.build_from_flags_for_watcher(flags, watcher_communicator.clone()) flags,
.await?; watcher_communicator.clone(),
)?;
let cli_options = factory.cli_options(); let cli_options = factory.cli_options();
let _ = watcher_communicator.watch_paths(cli_options.watch_paths()); let _ = watcher_communicator.watch_paths(cli_options.watch_paths());
bundle_action(factory, &bundle_flags).await?; bundle_action(factory, &bundle_flags).await?;
@ -48,7 +49,7 @@ pub async fn bundle(
) )
.await?; .await?;
} else { } else {
let factory = CliFactory::from_flags(flags).await?; let factory = CliFactory::from_flags(flags)?;
bundle_action(factory, &bundle_flags).await?; bundle_action(factory, &bundle_flags).await?;
} }

View file

@ -22,7 +22,7 @@ pub async fn compile(
flags: Flags, flags: Flags,
compile_flags: CompileFlags, compile_flags: CompileFlags,
) -> Result<(), AnyError> { ) -> Result<(), AnyError> {
let factory = CliFactory::from_flags(flags).await?; let factory = CliFactory::from_flags(flags)?;
let cli_options = factory.cli_options(); let cli_options = factory.cli_options();
let module_graph_creator = factory.module_graph_creator().await?; let module_graph_creator = factory.module_graph_creator().await?;
let parsed_source_cache = factory.parsed_source_cache(); let parsed_source_cache = factory.parsed_source_cache();

View file

@ -462,7 +462,7 @@ pub async fn cover_files(
return Err(generic_error("No matching coverage profiles found")); return Err(generic_error("No matching coverage profiles found"));
} }
let factory = CliFactory::from_flags(flags).await?; let factory = CliFactory::from_flags(flags)?;
let npm_resolver = factory.npm_resolver().await?; let npm_resolver = factory.npm_resolver().await?;
let file_fetcher = factory.file_fetcher()?; let file_fetcher = factory.file_fetcher()?;
let cli_options = factory.cli_options(); let cli_options = factory.cli_options();

View file

@ -17,7 +17,6 @@ use deno_config::glob::PathOrPatternSet;
use deno_core::anyhow::bail; use deno_core::anyhow::bail;
use deno_core::anyhow::Context; use deno_core::anyhow::Context;
use deno_core::error::AnyError; use deno_core::error::AnyError;
use deno_core::futures::FutureExt;
use deno_doc as doc; use deno_doc as doc;
use deno_graph::GraphKind; use deno_graph::GraphKind;
use deno_graph::ModuleAnalyzer; use deno_graph::ModuleAnalyzer;
@ -73,7 +72,7 @@ async fn generate_doc_nodes_for_builtin_types(
} }
pub async fn doc(flags: Flags, doc_flags: DocFlags) -> Result<(), AnyError> { pub async fn doc(flags: Flags, doc_flags: DocFlags) -> Result<(), AnyError> {
let factory = CliFactory::from_flags(flags).await?; let factory = CliFactory::from_flags(flags)?;
let cli_options = factory.cli_options(); let cli_options = factory.cli_options();
let module_info_cache = factory.module_info_cache()?; let module_info_cache = factory.module_info_cache()?;
let parsed_source_cache = factory.parsed_source_cache(); let parsed_source_cache = factory.parsed_source_cache();
@ -156,8 +155,6 @@ pub async fn doc(flags: Flags, doc_flags: DocFlags) -> Result<(), AnyError> {
}; };
generate_docs_directory(&doc_nodes_by_url, html_options, deno_ns) generate_docs_directory(&doc_nodes_by_url, html_options, deno_ns)
.boxed_local()
.await
} else { } else {
let modules_len = doc_nodes_by_url.len(); let modules_len = doc_nodes_by_url.len();
let doc_nodes = let doc_nodes =
@ -224,7 +221,7 @@ impl deno_doc::html::HrefResolver for DocResolver {
} }
} }
async fn generate_docs_directory( fn generate_docs_directory(
doc_nodes_by_url: &IndexMap<ModuleSpecifier, Vec<doc::DocNode>>, doc_nodes_by_url: &IndexMap<ModuleSpecifier, Vec<doc::DocNode>>,
html_options: &DocHtmlFlag, html_options: &DocHtmlFlag,
deno_ns: std::collections::HashSet<Vec<String>>, deno_ns: std::collections::HashSet<Vec<String>>,

View file

@ -68,7 +68,7 @@ pub async fn format(flags: Flags, fmt_flags: FmtFlags) -> Result<(), AnyError> {
move |flags, watcher_communicator, changed_paths| { move |flags, watcher_communicator, changed_paths| {
let fmt_flags = fmt_flags.clone(); let fmt_flags = fmt_flags.clone();
Ok(async move { Ok(async move {
let factory = CliFactory::from_flags(flags).await?; let factory = CliFactory::from_flags(flags)?;
let cli_options = factory.cli_options(); let cli_options = factory.cli_options();
let fmt_options = cli_options.resolve_fmt_options(fmt_flags)?; let fmt_options = cli_options.resolve_fmt_options(fmt_flags)?;
let files = let files =
@ -113,7 +113,7 @@ pub async fn format(flags: Flags, fmt_flags: FmtFlags) -> Result<(), AnyError> {
) )
.await?; .await?;
} else { } else {
let factory = CliFactory::from_flags(flags).await?; let factory = CliFactory::from_flags(flags)?;
let cli_options = factory.cli_options(); let cli_options = factory.cli_options();
let fmt_options = cli_options.resolve_fmt_options(fmt_flags)?; let fmt_options = cli_options.resolve_fmt_options(fmt_flags)?;
let files = let files =

View file

@ -36,7 +36,7 @@ use crate::npm::ManagedCliNpmResolver;
use crate::util::checksum; use crate::util::checksum;
pub async fn info(flags: Flags, info_flags: InfoFlags) -> Result<(), AnyError> { pub async fn info(flags: Flags, info_flags: InfoFlags) -> Result<(), AnyError> {
let factory = CliFactory::from_flags(flags).await?; let factory = CliFactory::from_flags(flags)?;
let cli_options = factory.cli_options(); let cli_options = factory.cli_options();
if let Some(specifier) = info_flags.file { if let Some(specifier) = info_flags.file {
let module_graph_builder = factory.module_graph_builder().await?; let module_graph_builder = factory.module_graph_builder().await?;

View file

@ -32,7 +32,7 @@ fn create_file(
} }
} }
pub async fn init_project(init_flags: InitFlags) -> Result<(), AnyError> { pub fn init_project(init_flags: InitFlags) -> Result<(), AnyError> {
let cwd = let cwd =
std::env::current_dir().context("Can't read current working directory.")?; std::env::current_dir().context("Can't read current working directory.")?;
let dir = if let Some(dir) = &init_flags.dir { let dir = if let Some(dir) = &init_flags.dir {

View file

@ -242,8 +242,7 @@ pub async fn install_command(
install_flags: InstallFlags, install_flags: InstallFlags,
) -> Result<(), AnyError> { ) -> Result<(), AnyError> {
// ensure the module is cached // ensure the module is cached
CliFactory::from_flags(flags.clone()) CliFactory::from_flags(flags.clone())?
.await?
.module_load_preparer() .module_load_preparer()
.await? .await?
.load_and_type_check_files(&[install_flags.module_url.clone()]) .load_and_type_check_files(&[install_flags.module_url.clone()])

View file

@ -54,7 +54,7 @@ pub async fn kernel(
logger::init(Some(log::Level::Debug)); logger::init(Some(log::Level::Debug));
} }
let factory = CliFactory::from_flags(flags).await?; let factory = CliFactory::from_flags(flags)?;
let cli_options = factory.cli_options(); let cli_options = factory.cli_options();
let main_module = let main_module =
resolve_url_or_path("./$deno$jupyter.ts", cli_options.initial_cwd()) resolve_url_or_path("./$deno$jupyter.ts", cli_options.initial_cwd())

View file

@ -74,7 +74,7 @@ pub async fn lint(flags: Flags, lint_flags: LintFlags) -> Result<(), AnyError> {
move |flags, watcher_communicator, changed_paths| { move |flags, watcher_communicator, changed_paths| {
let lint_flags = lint_flags.clone(); let lint_flags = lint_flags.clone();
Ok(async move { Ok(async move {
let factory = CliFactory::from_flags(flags).await?; let factory = CliFactory::from_flags(flags)?;
let cli_options = factory.cli_options(); let cli_options = factory.cli_options();
let lint_options = cli_options.resolve_lint_options(lint_flags)?; let lint_options = cli_options.resolve_lint_options(lint_flags)?;
let files = collect_lint_files(lint_options.files.clone()).and_then( let files = collect_lint_files(lint_options.files.clone()).and_then(
@ -110,7 +110,7 @@ pub async fn lint(flags: Flags, lint_flags: LintFlags) -> Result<(), AnyError> {
) )
.await?; .await?;
} else { } else {
let factory = CliFactory::from_flags(flags).await?; let factory = CliFactory::from_flags(flags)?;
let cli_options = factory.cli_options(); let cli_options = factory.cli_options();
let is_stdin = lint_flags.is_stdin(); let is_stdin = lint_flags.is_stdin();
let lint_options = cli_options.resolve_lint_options(lint_flags)?; let lint_options = cli_options.resolve_lint_options(lint_flags)?;

View file

@ -910,7 +910,7 @@ pub async fn publish(
flags: Flags, flags: Flags,
publish_flags: PublishFlags, publish_flags: PublishFlags,
) -> Result<(), AnyError> { ) -> Result<(), AnyError> {
let cli_factory = CliFactory::from_flags(flags).await?; let cli_factory = CliFactory::from_flags(flags)?;
let auth_method = let auth_method =
get_auth_method(publish_flags.token, publish_flags.dry_run)?; get_auth_method(publish_flags.token, publish_flags.dry_run)?;

View file

@ -26,7 +26,7 @@ use crate::jsr::JsrFetchResolver;
use crate::npm::NpmFetchResolver; use crate::npm::NpmFetchResolver;
pub async fn add(flags: Flags, add_flags: AddFlags) -> Result<(), AnyError> { pub async fn add(flags: Flags, add_flags: AddFlags) -> Result<(), AnyError> {
let cli_factory = CliFactory::from_flags(flags.clone()).await?; let cli_factory = CliFactory::from_flags(flags.clone())?;
let cli_options = cli_factory.cli_options(); let cli_options = cli_factory.cli_options();
let Some(config_file) = cli_options.maybe_config_file() else { let Some(config_file) = cli_options.maybe_config_file() else {

View file

@ -152,7 +152,7 @@ async fn read_eval_file(
} }
pub async fn run(flags: Flags, repl_flags: ReplFlags) -> Result<i32, AnyError> { pub async fn run(flags: Flags, repl_flags: ReplFlags) -> Result<i32, AnyError> {
let factory = CliFactory::from_flags(flags).await?; let factory = CliFactory::from_flags(flags)?;
let cli_options = factory.cli_options(); let cli_options = factory.cli_options();
let main_module = cli_options.resolve_main_module()?; let main_module = cli_options.resolve_main_module()?;
let permissions = PermissionsContainer::new(Permissions::from_options( let permissions = PermissionsContainer::new(Permissions::from_options(

View file

@ -200,7 +200,7 @@ impl ReplSession {
test_event_receiver: TestEventReceiver, test_event_receiver: TestEventReceiver,
) -> Result<Self, AnyError> { ) -> Result<Self, AnyError> {
let language_server = ReplLanguageServer::new_initialized().await?; let language_server = ReplLanguageServer::new_initialized().await?;
let mut session = worker.create_inspector_session().await; let mut session = worker.create_inspector_session();
worker worker
.js_runtime .js_runtime

View file

@ -39,7 +39,7 @@ To grant permissions, set them before the script argument. For example:
// TODO(bartlomieju): actually I think it will also fail if there's an import // TODO(bartlomieju): actually I think it will also fail if there's an import
// map specified and bare specifier is used on the command line // map specified and bare specifier is used on the command line
let factory = CliFactory::from_flags(flags).await?; let factory = CliFactory::from_flags(flags)?;
let deno_dir = factory.deno_dir()?; let deno_dir = factory.deno_dir()?;
let http_client = factory.http_client(); let http_client = factory.http_client();
let cli_options = factory.cli_options(); let cli_options = factory.cli_options();
@ -76,7 +76,7 @@ To grant permissions, set them before the script argument. For example:
} }
pub async fn run_from_stdin(flags: Flags) -> Result<i32, AnyError> { pub async fn run_from_stdin(flags: Flags) -> Result<i32, AnyError> {
let factory = CliFactory::from_flags(flags).await?; let factory = CliFactory::from_flags(flags)?;
let cli_options = factory.cli_options(); let cli_options = factory.cli_options();
let main_module = cli_options.resolve_main_module()?; let main_module = cli_options.resolve_main_module()?;
@ -121,8 +121,7 @@ async fn run_with_watch(
move |flags, watcher_communicator, _changed_paths| { move |flags, watcher_communicator, _changed_paths| {
Ok(async move { Ok(async move {
let factory = CliFactoryBuilder::new() let factory = CliFactoryBuilder::new()
.build_from_flags_for_watcher(flags, watcher_communicator.clone()) .build_from_flags_for_watcher(flags, watcher_communicator.clone())?;
.await?;
let cli_options = factory.cli_options(); let cli_options = factory.cli_options();
let main_module = cli_options.resolve_main_module()?; let main_module = cli_options.resolve_main_module()?;
@ -158,7 +157,7 @@ pub async fn eval_command(
flags: Flags, flags: Flags,
eval_flags: EvalFlags, eval_flags: EvalFlags,
) -> Result<i32, AnyError> { ) -> Result<i32, AnyError> {
let factory = CliFactory::from_flags(flags).await?; let factory = CliFactory::from_flags(flags)?;
let cli_options = factory.cli_options(); let cli_options = factory.cli_options();
let file_fetcher = factory.file_fetcher()?; let file_fetcher = factory.file_fetcher()?;
let main_module = cli_options.resolve_main_module()?; let main_module = cli_options.resolve_main_module()?;

View file

@ -32,7 +32,7 @@ pub async fn execute_script(
flags: Flags, flags: Flags,
task_flags: TaskFlags, task_flags: TaskFlags,
) -> Result<i32, AnyError> { ) -> Result<i32, AnyError> {
let factory = CliFactory::from_flags(flags).await?; let factory = CliFactory::from_flags(flags)?;
let cli_options = factory.cli_options(); let cli_options = factory.cli_options();
let tasks_config = cli_options.resolve_tasks_config()?; let tasks_config = cli_options.resolve_tasks_config()?;
let maybe_package_json = cli_options.maybe_package_json(); let maybe_package_json = cli_options.maybe_package_json();

View file

@ -1479,7 +1479,7 @@ pub async fn run_tests(
flags: Flags, flags: Flags,
test_flags: TestFlags, test_flags: TestFlags,
) -> Result<(), AnyError> { ) -> Result<(), AnyError> {
let factory = CliFactory::from_flags(flags).await?; let factory = CliFactory::from_flags(flags)?;
let cli_options = factory.cli_options(); let cli_options = factory.cli_options();
let test_options = cli_options.resolve_test_options(test_flags)?; let test_options = cli_options.resolve_test_options(test_flags)?;
let file_fetcher = factory.file_fetcher()?; let file_fetcher = factory.file_fetcher()?;
@ -1577,8 +1577,7 @@ pub async fn run_tests_with_watch(
let test_flags = test_flags.clone(); let test_flags = test_flags.clone();
Ok(async move { Ok(async move {
let factory = CliFactoryBuilder::new() let factory = CliFactoryBuilder::new()
.build_from_flags_for_watcher(flags, watcher_communicator.clone()) .build_from_flags_for_watcher(flags, watcher_communicator.clone())?;
.await?;
let cli_options = factory.cli_options(); let cli_options = factory.cli_options();
let test_options = cli_options.resolve_test_options(test_flags)?; let test_options = cli_options.resolve_test_options(test_flags)?;

View file

@ -376,7 +376,7 @@ pub async fn upgrade(
flags: Flags, flags: Flags,
upgrade_flags: UpgradeFlags, upgrade_flags: UpgradeFlags,
) -> Result<(), AnyError> { ) -> Result<(), AnyError> {
let factory = CliFactory::from_flags(flags).await?; let factory = CliFactory::from_flags(flags)?;
let client = factory.http_client(); let client = factory.http_client();
let current_exe_path = std::env::current_exe()?; let current_exe_path = std::env::current_exe()?;
let output_exe_path = let output_exe_path =

View file

@ -355,7 +355,7 @@ impl CliMainWorker {
return Ok(None); return Ok(None);
}; };
let session = self.worker.create_inspector_session().await; let session = self.worker.create_inspector_session();
let mut hmr_runner = setup_hmr_runner(session); let mut hmr_runner = setup_hmr_runner(session);
@ -379,7 +379,7 @@ impl CliMainWorker {
return Ok(None); return Ok(None);
}; };
let session = self.worker.create_inspector_session().await; let session = self.worker.create_inspector_session();
let mut coverage_collector = create_coverage_collector(session); let mut coverage_collector = create_coverage_collector(session);
self self
.worker .worker

View file

@ -198,104 +198,106 @@ pub async fn op_crypto_sign_key(
#[serde] args: SignArg, #[serde] args: SignArg,
#[buffer] zero_copy: JsBuffer, #[buffer] zero_copy: JsBuffer,
) -> Result<ToJsBuffer, AnyError> { ) -> Result<ToJsBuffer, AnyError> {
let data = &*zero_copy; deno_core::unsync::spawn_blocking(move || {
let algorithm = args.algorithm; let data = &*zero_copy;
let algorithm = args.algorithm;
let signature = match algorithm { let signature = match algorithm {
Algorithm::RsassaPkcs1v15 => { Algorithm::RsassaPkcs1v15 => {
use rsa::pkcs1v15::SigningKey; use rsa::pkcs1v15::SigningKey;
let private_key = RsaPrivateKey::from_pkcs1_der(&args.key.data)?; let private_key = RsaPrivateKey::from_pkcs1_der(&args.key.data)?;
match args match args
.hash .hash
.ok_or_else(|| type_error("Missing argument hash".to_string()))? .ok_or_else(|| type_error("Missing argument hash".to_string()))?
{ {
CryptoHash::Sha1 => { CryptoHash::Sha1 => {
let signing_key = SigningKey::<Sha1>::new(private_key); let signing_key = SigningKey::<Sha1>::new(private_key);
signing_key.sign(data) signing_key.sign(data)
} }
CryptoHash::Sha256 => { CryptoHash::Sha256 => {
let signing_key = SigningKey::<Sha256>::new(private_key); let signing_key = SigningKey::<Sha256>::new(private_key);
signing_key.sign(data) signing_key.sign(data)
} }
CryptoHash::Sha384 => { CryptoHash::Sha384 => {
let signing_key = SigningKey::<Sha384>::new(private_key); let signing_key = SigningKey::<Sha384>::new(private_key);
signing_key.sign(data) signing_key.sign(data)
} }
CryptoHash::Sha512 => { CryptoHash::Sha512 => {
let signing_key = SigningKey::<Sha512>::new(private_key); let signing_key = SigningKey::<Sha512>::new(private_key);
signing_key.sign(data) signing_key.sign(data)
}
} }
.to_vec()
} }
.to_vec() Algorithm::RsaPss => {
} let private_key = RsaPrivateKey::from_pkcs1_der(&args.key.data)?;
Algorithm::RsaPss => {
let private_key = RsaPrivateKey::from_pkcs1_der(&args.key.data)?;
let salt_len = args let salt_len = args.salt_length.ok_or_else(|| {
.salt_length type_error("Missing argument saltLength".to_string())
.ok_or_else(|| type_error("Missing argument saltLength".to_string()))? })? as usize;
as usize;
let mut rng = OsRng; let mut rng = OsRng;
match args match args
.hash .hash
.ok_or_else(|| type_error("Missing argument hash".to_string()))? .ok_or_else(|| type_error("Missing argument hash".to_string()))?
{ {
CryptoHash::Sha1 => { CryptoHash::Sha1 => {
let signing_key = Pss::new_with_salt::<Sha1>(salt_len); let signing_key = Pss::new_with_salt::<Sha1>(salt_len);
let hashed = Sha1::digest(data); let hashed = Sha1::digest(data);
signing_key.sign(Some(&mut rng), &private_key, &hashed)? signing_key.sign(Some(&mut rng), &private_key, &hashed)?
} }
CryptoHash::Sha256 => { CryptoHash::Sha256 => {
let signing_key = Pss::new_with_salt::<Sha256>(salt_len); let signing_key = Pss::new_with_salt::<Sha256>(salt_len);
let hashed = Sha256::digest(data); let hashed = Sha256::digest(data);
signing_key.sign(Some(&mut rng), &private_key, &hashed)? signing_key.sign(Some(&mut rng), &private_key, &hashed)?
} }
CryptoHash::Sha384 => { CryptoHash::Sha384 => {
let signing_key = Pss::new_with_salt::<Sha384>(salt_len); let signing_key = Pss::new_with_salt::<Sha384>(salt_len);
let hashed = Sha384::digest(data); let hashed = Sha384::digest(data);
signing_key.sign(Some(&mut rng), &private_key, &hashed)? signing_key.sign(Some(&mut rng), &private_key, &hashed)?
} }
CryptoHash::Sha512 => { CryptoHash::Sha512 => {
let signing_key = Pss::new_with_salt::<Sha512>(salt_len); let signing_key = Pss::new_with_salt::<Sha512>(salt_len);
let hashed = Sha512::digest(data); let hashed = Sha512::digest(data);
signing_key.sign(Some(&mut rng), &private_key, &hashed)? signing_key.sign(Some(&mut rng), &private_key, &hashed)?
}
} }
.to_vec()
} }
.to_vec() Algorithm::Ecdsa => {
} let curve: &EcdsaSigningAlgorithm =
Algorithm::Ecdsa => { args.named_curve.ok_or_else(not_supported)?.into();
let curve: &EcdsaSigningAlgorithm =
args.named_curve.ok_or_else(not_supported)?.into();
let rng = RingRand::SystemRandom::new(); let rng = RingRand::SystemRandom::new();
let key_pair = EcdsaKeyPair::from_pkcs8(curve, &args.key.data, &rng)?; let key_pair = EcdsaKeyPair::from_pkcs8(curve, &args.key.data, &rng)?;
// We only support P256-SHA256 & P384-SHA384. These are recommended signature pairs. // We only support P256-SHA256 & P384-SHA384. These are recommended signature pairs.
// https://briansmith.org/rustdoc/ring/signature/index.html#statics // https://briansmith.org/rustdoc/ring/signature/index.html#statics
if let Some(hash) = args.hash { if let Some(hash) = args.hash {
match hash { match hash {
CryptoHash::Sha256 | CryptoHash::Sha384 => (), CryptoHash::Sha256 | CryptoHash::Sha384 => (),
_ => return Err(type_error("Unsupported algorithm")), _ => return Err(type_error("Unsupported algorithm")),
} }
}; };
let signature = key_pair.sign(&rng, data)?; let signature = key_pair.sign(&rng, data)?;
// Signature data as buffer. // Signature data as buffer.
signature.as_ref().to_vec() signature.as_ref().to_vec()
} }
Algorithm::Hmac => { Algorithm::Hmac => {
let hash: HmacAlgorithm = args.hash.ok_or_else(not_supported)?.into(); let hash: HmacAlgorithm = args.hash.ok_or_else(not_supported)?.into();
let key = HmacKey::new(hash, &args.key.data); let key = HmacKey::new(hash, &args.key.data);
let signature = ring::hmac::sign(&key, data); let signature = ring::hmac::sign(&key, data);
signature.as_ref().to_vec() signature.as_ref().to_vec()
} }
_ => return Err(type_error("Unsupported algorithm".to_string())), _ => return Err(type_error("Unsupported algorithm".to_string())),
}; };
Ok(signature.into()) Ok(signature.into())
})
.await?
} }
#[derive(Deserialize)] #[derive(Deserialize)]
@ -314,106 +316,108 @@ pub async fn op_crypto_verify_key(
#[serde] args: VerifyArg, #[serde] args: VerifyArg,
#[buffer] zero_copy: JsBuffer, #[buffer] zero_copy: JsBuffer,
) -> Result<bool, AnyError> { ) -> Result<bool, AnyError> {
let data = &*zero_copy; deno_core::unsync::spawn_blocking(move || {
let algorithm = args.algorithm; let data = &*zero_copy;
let algorithm = args.algorithm;
let verification = match algorithm { let verification = match algorithm {
Algorithm::RsassaPkcs1v15 => { Algorithm::RsassaPkcs1v15 => {
use rsa::pkcs1v15::Signature; use rsa::pkcs1v15::Signature;
use rsa::pkcs1v15::VerifyingKey; use rsa::pkcs1v15::VerifyingKey;
let public_key = read_rsa_public_key(args.key)?; let public_key = read_rsa_public_key(args.key)?;
let signature: Signature = args.signature.as_ref().try_into()?; let signature: Signature = args.signature.as_ref().try_into()?;
match args match args
.hash .hash
.ok_or_else(|| type_error("Missing argument hash".to_string()))? .ok_or_else(|| type_error("Missing argument hash".to_string()))?
{ {
CryptoHash::Sha1 => { CryptoHash::Sha1 => {
let verifying_key = VerifyingKey::<Sha1>::new(public_key); let verifying_key = VerifyingKey::<Sha1>::new(public_key);
verifying_key.verify(data, &signature).is_ok() verifying_key.verify(data, &signature).is_ok()
} }
CryptoHash::Sha256 => { CryptoHash::Sha256 => {
let verifying_key = VerifyingKey::<Sha256>::new(public_key); let verifying_key = VerifyingKey::<Sha256>::new(public_key);
verifying_key.verify(data, &signature).is_ok() verifying_key.verify(data, &signature).is_ok()
} }
CryptoHash::Sha384 => { CryptoHash::Sha384 => {
let verifying_key = VerifyingKey::<Sha384>::new(public_key); let verifying_key = VerifyingKey::<Sha384>::new(public_key);
verifying_key.verify(data, &signature).is_ok() verifying_key.verify(data, &signature).is_ok()
} }
CryptoHash::Sha512 => { CryptoHash::Sha512 => {
let verifying_key = VerifyingKey::<Sha512>::new(public_key); let verifying_key = VerifyingKey::<Sha512>::new(public_key);
verifying_key.verify(data, &signature).is_ok() verifying_key.verify(data, &signature).is_ok()
}
} }
} }
} Algorithm::RsaPss => {
Algorithm::RsaPss => { let public_key = read_rsa_public_key(args.key)?;
let public_key = read_rsa_public_key(args.key)?; let signature = args.signature.as_ref();
let signature = args.signature.as_ref();
let salt_len = args let salt_len = args.salt_length.ok_or_else(|| {
.salt_length type_error("Missing argument saltLength".to_string())
.ok_or_else(|| type_error("Missing argument saltLength".to_string()))? })? as usize;
as usize;
match args match args
.hash .hash
.ok_or_else(|| type_error("Missing argument hash".to_string()))? .ok_or_else(|| type_error("Missing argument hash".to_string()))?
{ {
CryptoHash::Sha1 => { CryptoHash::Sha1 => {
let pss = Pss::new_with_salt::<Sha1>(salt_len); let pss = Pss::new_with_salt::<Sha1>(salt_len);
let hashed = Sha1::digest(data); let hashed = Sha1::digest(data);
pss.verify(&public_key, &hashed, signature).is_ok() pss.verify(&public_key, &hashed, signature).is_ok()
} }
CryptoHash::Sha256 => { CryptoHash::Sha256 => {
let pss = Pss::new_with_salt::<Sha256>(salt_len); let pss = Pss::new_with_salt::<Sha256>(salt_len);
let hashed = Sha256::digest(data); let hashed = Sha256::digest(data);
pss.verify(&public_key, &hashed, signature).is_ok() pss.verify(&public_key, &hashed, signature).is_ok()
} }
CryptoHash::Sha384 => { CryptoHash::Sha384 => {
let pss = Pss::new_with_salt::<Sha384>(salt_len); let pss = Pss::new_with_salt::<Sha384>(salt_len);
let hashed = Sha384::digest(data); let hashed = Sha384::digest(data);
pss.verify(&public_key, &hashed, signature).is_ok() pss.verify(&public_key, &hashed, signature).is_ok()
} }
CryptoHash::Sha512 => { CryptoHash::Sha512 => {
let pss = Pss::new_with_salt::<Sha512>(salt_len); let pss = Pss::new_with_salt::<Sha512>(salt_len);
let hashed = Sha512::digest(data); let hashed = Sha512::digest(data);
pss.verify(&public_key, &hashed, signature).is_ok() pss.verify(&public_key, &hashed, signature).is_ok()
}
} }
} }
} Algorithm::Hmac => {
Algorithm::Hmac => { let hash: HmacAlgorithm = args.hash.ok_or_else(not_supported)?.into();
let hash: HmacAlgorithm = args.hash.ok_or_else(not_supported)?.into(); let key = HmacKey::new(hash, &args.key.data);
let key = HmacKey::new(hash, &args.key.data); ring::hmac::verify(&key, data, &args.signature).is_ok()
ring::hmac::verify(&key, data, &args.signature).is_ok() }
} Algorithm::Ecdsa => {
Algorithm::Ecdsa => { let signing_alg: &EcdsaSigningAlgorithm =
let signing_alg: &EcdsaSigningAlgorithm = args.named_curve.ok_or_else(not_supported)?.into();
args.named_curve.ok_or_else(not_supported)?.into(); let verify_alg: &EcdsaVerificationAlgorithm =
let verify_alg: &EcdsaVerificationAlgorithm = args.named_curve.ok_or_else(not_supported)?.into();
args.named_curve.ok_or_else(not_supported)?.into();
let private_key; let private_key;
let public_key_bytes = match args.key.r#type { let public_key_bytes = match args.key.r#type {
KeyType::Private => { KeyType::Private => {
let rng = RingRand::SystemRandom::new(); let rng = RingRand::SystemRandom::new();
private_key = private_key =
EcdsaKeyPair::from_pkcs8(signing_alg, &args.key.data, &rng)?; EcdsaKeyPair::from_pkcs8(signing_alg, &args.key.data, &rng)?;
private_key.public_key().as_ref() private_key.public_key().as_ref()
} }
KeyType::Public => &*args.key.data, KeyType::Public => &*args.key.data,
_ => return Err(type_error("Invalid Key format".to_string())), _ => return Err(type_error("Invalid Key format".to_string())),
}; };
let public_key = let public_key =
ring::signature::UnparsedPublicKey::new(verify_alg, public_key_bytes); ring::signature::UnparsedPublicKey::new(verify_alg, public_key_bytes);
public_key.verify(data, &args.signature).is_ok() public_key.verify(data, &args.signature).is_ok()
} }
_ => return Err(type_error("Unsupported algorithm".to_string())), _ => return Err(type_error("Unsupported algorithm".to_string())),
}; };
Ok(verification) Ok(verification)
})
.await?
} }
#[derive(Deserialize)] #[derive(Deserialize)]
@ -437,153 +441,160 @@ pub async fn op_crypto_derive_bits(
#[serde] args: DeriveKeyArg, #[serde] args: DeriveKeyArg,
#[buffer] zero_copy: Option<JsBuffer>, #[buffer] zero_copy: Option<JsBuffer>,
) -> Result<ToJsBuffer, AnyError> { ) -> Result<ToJsBuffer, AnyError> {
let algorithm = args.algorithm; deno_core::unsync::spawn_blocking(move || {
match algorithm { let algorithm = args.algorithm;
Algorithm::Pbkdf2 => { match algorithm {
let zero_copy = zero_copy.ok_or_else(not_supported)?; Algorithm::Pbkdf2 => {
let salt = &*zero_copy; let zero_copy = zero_copy.ok_or_else(not_supported)?;
// The caller must validate these cases. let salt = &*zero_copy;
assert!(args.length > 0); // The caller must validate these cases.
assert!(args.length % 8 == 0); assert!(args.length > 0);
assert!(args.length % 8 == 0);
let algorithm = match args.hash.ok_or_else(not_supported)? { let algorithm = match args.hash.ok_or_else(not_supported)? {
CryptoHash::Sha1 => pbkdf2::PBKDF2_HMAC_SHA1, CryptoHash::Sha1 => pbkdf2::PBKDF2_HMAC_SHA1,
CryptoHash::Sha256 => pbkdf2::PBKDF2_HMAC_SHA256, CryptoHash::Sha256 => pbkdf2::PBKDF2_HMAC_SHA256,
CryptoHash::Sha384 => pbkdf2::PBKDF2_HMAC_SHA384, CryptoHash::Sha384 => pbkdf2::PBKDF2_HMAC_SHA384,
CryptoHash::Sha512 => pbkdf2::PBKDF2_HMAC_SHA512, CryptoHash::Sha512 => pbkdf2::PBKDF2_HMAC_SHA512,
}; };
// This will never panic. We have already checked length earlier. // This will never panic. We have already checked length earlier.
let iterations = let iterations =
NonZeroU32::new(args.iterations.ok_or_else(not_supported)?).unwrap(); NonZeroU32::new(args.iterations.ok_or_else(not_supported)?).unwrap();
let secret = args.key.data; let secret = args.key.data;
let mut out = vec![0; args.length / 8]; let mut out = vec![0; args.length / 8];
pbkdf2::derive(algorithm, iterations, salt, &secret, &mut out); pbkdf2::derive(algorithm, iterations, salt, &secret, &mut out);
Ok(out.into()) Ok(out.into())
} }
Algorithm::Ecdh => { Algorithm::Ecdh => {
let named_curve = args let named_curve = args.named_curve.ok_or_else(|| {
.named_curve type_error("Missing argument namedCurve".to_string())
.ok_or_else(|| type_error("Missing argument namedCurve".to_string()))?; })?;
let public_key = args let public_key = args
.public_key .public_key
.ok_or_else(|| type_error("Missing argument publicKey"))?; .ok_or_else(|| type_error("Missing argument publicKey"))?;
match named_curve { match named_curve {
CryptoNamedCurve::P256 => { CryptoNamedCurve::P256 => {
let secret_key = p256::SecretKey::from_pkcs8_der(&args.key.data) let secret_key = p256::SecretKey::from_pkcs8_der(&args.key.data)
.map_err(|_| type_error("Unexpected error decoding private key"))?; .map_err(|_| {
type_error("Unexpected error decoding private key")
})?;
let public_key = match public_key.r#type { let public_key = match public_key.r#type {
KeyType::Private => { KeyType::Private => {
p256::SecretKey::from_pkcs8_der(&public_key.data) p256::SecretKey::from_pkcs8_der(&public_key.data)
.map_err(|_| { .map_err(|_| {
type_error("Unexpected error decoding private key") type_error("Unexpected error decoding private key")
})? })?
.public_key() .public_key()
}
KeyType::Public => {
let point = p256::EncodedPoint::from_bytes(public_key.data)
.map_err(|_| {
type_error("Unexpected error decoding private key")
})?;
let pk = p256::PublicKey::from_encoded_point(&point);
// pk is a constant time Option.
if pk.is_some().into() {
pk.unwrap()
} else {
return Err(type_error(
"Unexpected error decoding private key",
));
} }
} KeyType::Public => {
_ => unreachable!(), let point = p256::EncodedPoint::from_bytes(public_key.data)
}; .map_err(|_| {
type_error("Unexpected error decoding private key")
})?;
let shared_secret = p256::elliptic_curve::ecdh::diffie_hellman( let pk = p256::PublicKey::from_encoded_point(&point);
secret_key.to_nonzero_scalar(), // pk is a constant time Option.
public_key.as_affine(), if pk.is_some().into() {
); pk.unwrap()
} else {
// raw serialized x-coordinate of the computed point return Err(type_error(
Ok(shared_secret.raw_secret_bytes().to_vec().into()) "Unexpected error decoding private key",
} ));
CryptoNamedCurve::P384 => { }
let secret_key = p384::SecretKey::from_pkcs8_der(&args.key.data)
.map_err(|_| type_error("Unexpected error decoding private key"))?;
let public_key = match public_key.r#type {
KeyType::Private => {
p384::SecretKey::from_pkcs8_der(&public_key.data)
.map_err(|_| {
type_error("Unexpected error decoding private key")
})?
.public_key()
}
KeyType::Public => {
let point = p384::EncodedPoint::from_bytes(public_key.data)
.map_err(|_| {
type_error("Unexpected error decoding private key")
})?;
let pk = p384::PublicKey::from_encoded_point(&point);
// pk is a constant time Option.
if pk.is_some().into() {
pk.unwrap()
} else {
return Err(type_error(
"Unexpected error decoding private key",
));
} }
} _ => unreachable!(),
_ => unreachable!(), };
};
let shared_secret = p384::elliptic_curve::ecdh::diffie_hellman( let shared_secret = p256::elliptic_curve::ecdh::diffie_hellman(
secret_key.to_nonzero_scalar(), secret_key.to_nonzero_scalar(),
public_key.as_affine(), public_key.as_affine(),
); );
// raw serialized x-coordinate of the computed point // raw serialized x-coordinate of the computed point
Ok(shared_secret.raw_secret_bytes().to_vec().into()) Ok(shared_secret.raw_secret_bytes().to_vec().into())
}
CryptoNamedCurve::P384 => {
let secret_key = p384::SecretKey::from_pkcs8_der(&args.key.data)
.map_err(|_| {
type_error("Unexpected error decoding private key")
})?;
let public_key = match public_key.r#type {
KeyType::Private => {
p384::SecretKey::from_pkcs8_der(&public_key.data)
.map_err(|_| {
type_error("Unexpected error decoding private key")
})?
.public_key()
}
KeyType::Public => {
let point = p384::EncodedPoint::from_bytes(public_key.data)
.map_err(|_| {
type_error("Unexpected error decoding private key")
})?;
let pk = p384::PublicKey::from_encoded_point(&point);
// pk is a constant time Option.
if pk.is_some().into() {
pk.unwrap()
} else {
return Err(type_error(
"Unexpected error decoding private key",
));
}
}
_ => unreachable!(),
};
let shared_secret = p384::elliptic_curve::ecdh::diffie_hellman(
secret_key.to_nonzero_scalar(),
public_key.as_affine(),
);
// raw serialized x-coordinate of the computed point
Ok(shared_secret.raw_secret_bytes().to_vec().into())
}
} }
} }
} Algorithm::Hkdf => {
Algorithm::Hkdf => { let zero_copy = zero_copy.ok_or_else(not_supported)?;
let zero_copy = zero_copy.ok_or_else(not_supported)?; let salt = &*zero_copy;
let salt = &*zero_copy; let algorithm = match args.hash.ok_or_else(not_supported)? {
let algorithm = match args.hash.ok_or_else(not_supported)? { CryptoHash::Sha1 => hkdf::HKDF_SHA1_FOR_LEGACY_USE_ONLY,
CryptoHash::Sha1 => hkdf::HKDF_SHA1_FOR_LEGACY_USE_ONLY, CryptoHash::Sha256 => hkdf::HKDF_SHA256,
CryptoHash::Sha256 => hkdf::HKDF_SHA256, CryptoHash::Sha384 => hkdf::HKDF_SHA384,
CryptoHash::Sha384 => hkdf::HKDF_SHA384, CryptoHash::Sha512 => hkdf::HKDF_SHA512,
CryptoHash::Sha512 => hkdf::HKDF_SHA512, };
};
let info = args let info = args
.info .info
.ok_or_else(|| type_error("Missing argument info".to_string()))?; .ok_or_else(|| type_error("Missing argument info".to_string()))?;
// IKM // IKM
let secret = args.key.data; let secret = args.key.data;
// L // L
let length = args.length / 8; let length = args.length / 8;
let salt = hkdf::Salt::new(algorithm, salt); let salt = hkdf::Salt::new(algorithm, salt);
let prk = salt.extract(&secret); let prk = salt.extract(&secret);
let info = &[&*info]; let info = &[&*info];
let okm = prk.expand(info, HkdfOutput(length)).map_err(|_e| { let okm = prk.expand(info, HkdfOutput(length)).map_err(|_e| {
custom_error( custom_error(
"DOMExceptionOperationError", "DOMExceptionOperationError",
"The length provided for HKDF is too large", "The length provided for HKDF is too large",
) )
})?; })?;
let mut r = vec![0u8; length]; let mut r = vec![0u8; length];
okm.fill(&mut r)?; okm.fill(&mut r)?;
Ok(r.into()) Ok(r.into())
}
_ => Err(type_error("Unsupported algorithm".to_string())),
} }
_ => Err(type_error("Unsupported algorithm".to_string())), })
} .await?
} }
fn read_rsa_public_key(key_data: KeyData) -> Result<RsaPublicKey, AnyError> { fn read_rsa_public_key(key_data: KeyData) -> Result<RsaPublicKey, AnyError> {

View file

@ -166,6 +166,7 @@ function listenTls({
return new TlsListener(rid, localAddr); return new TlsListener(rid, localAddr);
} }
// deno-lint-ignore require-await
async function startTls( async function startTls(
conn, conn,
{ {
@ -174,7 +175,7 @@ async function startTls(
alpnProtocols = undefined, alpnProtocols = undefined,
} = {}, } = {},
) { ) {
const { 0: rid, 1: localAddr, 2: remoteAddr } = await op_tls_start({ const { 0: rid, 1: localAddr, 2: remoteAddr } = op_tls_start({
rid: conn[internalRidSymbol], rid: conn[internalRidSymbol],
hostname, hostname,
caCerts, caCerts,

View file

@ -152,6 +152,7 @@ impl UnixStreamResource {
fn write(self: Rc<Self>, _data: &[u8]) -> AsyncResult<usize> { fn write(self: Rc<Self>, _data: &[u8]) -> AsyncResult<usize> {
unreachable!() unreachable!()
} }
#[allow(clippy::unused_async)]
pub async fn shutdown(self: Rc<Self>) -> Result<(), AnyError> { pub async fn shutdown(self: Rc<Self>) -> Result<(), AnyError> {
unreachable!() unreachable!()
} }

View file

@ -159,9 +159,9 @@ pub struct StartTlsArgs {
alpn_protocols: Option<Vec<String>>, alpn_protocols: Option<Vec<String>>,
} }
#[op2(async)] #[op2]
#[serde] #[serde]
pub async fn op_tls_start<NP>( pub fn op_tls_start<NP>(
state: Rc<RefCell<OpState>>, state: Rc<RefCell<OpState>>,
#[serde] args: StartTlsArgs, #[serde] args: StartTlsArgs,
) -> Result<(ResourceId, IpAddr, IpAddr), AnyError> ) -> Result<(ResourceId, IpAddr, IpAddr), AnyError>

View file

@ -408,6 +408,7 @@ mod impl_ {
use deno_core::RcRef; use deno_core::RcRef;
use std::rc::Rc; use std::rc::Rc;
#[allow(clippy::unused_async)]
#[cfg(unix)] #[cfg(unix)]
pub async fn pair() -> (Rc<IpcJsonStreamResource>, tokio::net::UnixStream) { pub async fn pair() -> (Rc<IpcJsonStreamResource>, tokio::net::UnixStream) {
let (a, b) = tokio::net::UnixStream::pair().unwrap(); let (a, b) = tokio::net::UnixStream::pair().unwrap();

View file

@ -43,5 +43,6 @@ where
buf[1] = subsec_nanos; buf[1] = subsec_nanos;
} }
#[allow(clippy::unused_async)]
#[op2(async(lazy), fast)] #[op2(async(lazy), fast)]
pub async fn op_defer() {} pub async fn op_defer() {}

View file

@ -324,6 +324,7 @@ class GPU {
/** /**
* @param {GPURequestAdapterOptions} options * @param {GPURequestAdapterOptions} options
*/ */
// deno-lint-ignore require-await
async requestAdapter(options = {}) { async requestAdapter(options = {}) {
webidl.assertBranded(this, GPUPrototype); webidl.assertBranded(this, GPUPrototype);
options = webidl.converters.GPURequestAdapterOptions( options = webidl.converters.GPURequestAdapterOptions(
@ -332,7 +333,7 @@ class GPU {
"Argument 1", "Argument 1",
); );
const { err, ...data } = await op_webgpu_request_adapter( const { err, ...data } = op_webgpu_request_adapter(
options.powerPreference, options.powerPreference,
options.forceFallbackAdapter, options.forceFallbackAdapter,
); );
@ -411,6 +412,7 @@ class GPUAdapter {
* @param {GPUDeviceDescriptor} descriptor * @param {GPUDeviceDescriptor} descriptor
* @returns {Promise<GPUDevice>} * @returns {Promise<GPUDevice>}
*/ */
// deno-lint-ignore require-await
async requestDevice(descriptor = {}) { async requestDevice(descriptor = {}) {
webidl.assertBranded(this, GPUAdapterPrototype); webidl.assertBranded(this, GPUAdapterPrototype);
const prefix = "Failed to execute 'requestDevice' on 'GPUAdapter'"; const prefix = "Failed to execute 'requestDevice' on 'GPUAdapter'";
@ -431,7 +433,7 @@ class GPUAdapter {
} }
} }
const { rid, features, limits } = await op_webgpu_request_device( const { rid, features, limits } = op_webgpu_request_device(
this[_adapter].rid, this[_adapter].rid,
descriptor.label, descriptor.label,
requiredFeatures, requiredFeatures,
@ -455,7 +457,7 @@ class GPUAdapter {
* @param {string[]} unmaskHints * @param {string[]} unmaskHints
* @returns {Promise<GPUAdapterInfo>} * @returns {Promise<GPUAdapterInfo>}
*/ */
async requestAdapterInfo(unmaskHints = []) { requestAdapterInfo(unmaskHints = []) {
webidl.assertBranded(this, GPUAdapterPrototype); webidl.assertBranded(this, GPUAdapterPrototype);
const prefix = "Failed to execute 'requestAdapterInfo' on 'GPUAdapter'"; const prefix = "Failed to execute 'requestAdapterInfo' on 'GPUAdapter'";
unmaskHints = webidl.converters["sequence<DOMString>"]( unmaskHints = webidl.converters["sequence<DOMString>"](
@ -469,9 +471,7 @@ class GPUAdapter {
architecture, architecture,
device, device,
description, description,
} = await op_webgpu_request_adapter_info( } = op_webgpu_request_adapter_info(this[_adapter].rid);
this[_adapter].rid,
);
const adapterInfo = webidl.createBranded(GPUAdapterInfo); const adapterInfo = webidl.createBranded(GPUAdapterInfo);
adapterInfo[_vendor] = ArrayPrototypeIncludes(unmaskHints, "vendor") adapterInfo[_vendor] = ArrayPrototypeIncludes(unmaskHints, "vendor")
@ -484,7 +484,7 @@ class GPUAdapter {
: ""; : "";
adapterInfo[_description] = adapterInfo[_description] =
ArrayPrototypeIncludes(unmaskHints, "description") ? description : ""; ArrayPrototypeIncludes(unmaskHints, "description") ? description : "";
return adapterInfo; return PromiseResolve(adapterInfo);
} }
[SymbolFor("Deno.privateCustomInspect")](inspect, inspectOptions) { [SymbolFor("Deno.privateCustomInspect")](inspect, inspectOptions) {

View file

@ -381,9 +381,9 @@ pub struct GpuAdapterDevice {
is_software: bool, is_software: bool,
} }
#[op2(async)] #[op2]
#[serde] #[serde]
pub async fn op_webgpu_request_adapter( pub fn op_webgpu_request_adapter(
state: Rc<RefCell<OpState>>, state: Rc<RefCell<OpState>>,
#[serde] power_preference: Option<wgpu_types::PowerPreference>, #[serde] power_preference: Option<wgpu_types::PowerPreference>,
force_fallback_adapter: bool, force_fallback_adapter: bool,
@ -645,9 +645,9 @@ impl From<GpuRequiredFeatures> for wgpu_types::Features {
} }
} }
#[op2(async)] #[op2]
#[serde] #[serde]
pub async fn op_webgpu_request_device( pub fn op_webgpu_request_device(
state: Rc<RefCell<OpState>>, state: Rc<RefCell<OpState>>,
#[smi] adapter_rid: ResourceId, #[smi] adapter_rid: ResourceId,
#[string] label: String, #[string] label: String,
@ -702,9 +702,9 @@ pub struct GPUAdapterInfo {
description: String, description: String,
} }
#[op2(async)] #[op2]
#[serde] #[serde]
pub async fn op_webgpu_request_adapter_info( pub fn op_webgpu_request_adapter_info(
state: Rc<RefCell<OpState>>, state: Rc<RefCell<OpState>>,
#[smi] adapter_rid: ResourceId, #[smi] adapter_rid: ResourceId,
) -> Result<GPUAdapterInfo, AnyError> { ) -> Result<GPUAdapterInfo, AnyError> {

View file

@ -662,7 +662,7 @@ impl MainWorker {
/// Create new inspector session. This function panics if Worker /// Create new inspector session. This function panics if Worker
/// was not configured to create inspector. /// was not configured to create inspector.
pub async fn create_inspector_session(&mut self) -> LocalInspectorSession { pub fn create_inspector_session(&mut self) -> LocalInspectorSession {
self.js_runtime.maybe_init_inspector(); self.js_runtime.maybe_init_inspector();
self.js_runtime.inspector().borrow().create_local_session() self.js_runtime.inspector().borrow().create_local_session()
} }

View file

@ -47,15 +47,14 @@ pub async fn get_tls_listener_stream(
let cert_file = "tls/localhost.crt"; let cert_file = "tls/localhost.crt";
let key_file = "tls/localhost.key"; let key_file = "tls/localhost.key";
let ca_cert_file = "tls/RootCA.pem"; let ca_cert_file = "tls/RootCA.pem";
let tls_config = get_tls_config(cert_file, key_file, ca_cert_file, http) let tls_config =
.await get_tls_config(cert_file, key_file, ca_cert_file, http).unwrap();
.unwrap();
let tcp = get_tcp_listener_stream(name, port).await; let tcp = get_tcp_listener_stream(name, port).await;
get_tls_listener_stream_from_tcp(tls_config, tcp) get_tls_listener_stream_from_tcp(tls_config, tcp)
} }
pub async fn get_tls_config( pub fn get_tls_config(
cert: &str, cert: &str,
key: &str, key: &str,
ca: &str, ca: &str,

View file

@ -156,6 +156,8 @@ async function clippy() {
"--", "--",
"-D", "-D",
"warnings", "warnings",
"--deny",
"clippy::unused_async",
], ],
stdout: "inherit", stdout: "inherit",
stderr: "inherit", stderr: "inherit",