Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions build/wpt_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ PORT_BINDINGS = [
### (Invokes wpt_js_test_gen, wpt_wd_test_gen and wd_test to assemble a complete test suite.)
### -----------------------------------------------------------------------------------------

def wpt_test(name, wpt_directory, config, compat_date = "", compat_flags = [], autogates = [], start_server = False, **kwargs):
def wpt_test(name, wpt_directory, config, compat_date = "", compat_flags = [], autogates = [], start_server = False, include_tentative = False, **kwargs):
"""
Main entry point.

Expand Down Expand Up @@ -51,6 +51,7 @@ def wpt_test(name, wpt_directory, config, compat_date = "", compat_flags = [], a
wpt_directory = wpt_directory,
test_config = test_config_as_js,
wpt_tsproject = wpt_tsproject,
include_tentative = include_tentative,
)

wd_test_gen_rule = "{}@_wpt_wd_test_gen".format(name)
Expand Down Expand Up @@ -144,7 +145,7 @@ def _wpt_js_test_gen_impl(ctx):
base = ctx.attr.wpt_directory[WPTModuleInfo].base

files = ctx.attr.wpt_directory.files.to_list()
test_files = [file for file in files if is_test_file(file)]
test_files = [file for file in files if is_test_file(file, ctx.attr.include_tentative)]

ctx.actions.write(
output = src,
Expand All @@ -171,6 +172,8 @@ _wpt_js_test_gen = rule(
"test_config": attr.label(allow_single_file = True),
# Dependency: The ts_project rule that compiles the tests to JS
"wpt_tsproject": attr.label(),
# Whether to include tentative test files
"include_tentative": attr.bool(default = False),
},
)

Expand All @@ -187,7 +190,7 @@ const {{ run, printResults }} = createRunner(config, '{test_name}', allTestFiles
export const zzz_results = printResults();
"""

def is_test_file(file):
def is_test_file(file, include_tentative = False):
if not file.path.endswith(".js"):
# Not JS code, not a test
return False
Expand All @@ -198,7 +201,7 @@ def is_test_file(file):
# into the main directory, and would need to manually be marked as skipAllTests
return False

if ".tentative." in file.path or "/tentative/" in file.path:
if not include_tentative and (".tentative." in file.path or "/tentative/" in file.path):
# Tentative tests are for proposed features that are not yet standardized.
# We skip these to avoid noise from unstable specifications.
return False
Expand Down
20 changes: 20 additions & 0 deletions deps/rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions deps/rust/cargo.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ PACKAGES = WORKERD_CXX_PACKAGES | {
# param_extractor depends on unbounded_depth feature
"serde_json": crate.spec(version = "1", features = ["unbounded_depth"]),
"serde": crate.spec(version = "1", features = ["derive"]),
"sha3": crate.spec(version = "0", default_features = False),
"thiserror": crate.spec(version = "2"),
# tokio is huge, let's enable only features when we actually need them.
"tokio": crate.spec(version = "1", default_features = False, features = ["net", "rt", "rt-multi-thread", "time"]),
Expand Down
12 changes: 12 additions & 0 deletions deps/rust/crates/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,18 @@ alias(
tags = ["manual"],
)

alias(
name = "sha3-0.10.8",
actual = "@crates_vendor__sha3-0.10.8//:sha3",
tags = ["manual"],
)

alias(
name = "sha3",
actual = "@crates_vendor__sha3-0.10.8//:sha3",
tags = ["manual"],
)

alias(
name = "static_assertions-1.1.0",
actual = "@crates_vendor__static_assertions-1.1.0//:static_assertions",
Expand Down
53 changes: 53 additions & 0 deletions deps/rust/crates/BUILD.keccak-0.1.6.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
###############################################################################
# @generated
# DO NOT MODIFY: This file is auto-generated by a crate_universe tool. To
# regenerate this file, run the following:
#
# bazel run @@//deps/rust:crates_vendor
###############################################################################

load("@rules_rust//rust:defs.bzl", "rust_library")

package(default_visibility = ["//visibility:public"])

rust_library(
name = "keccak",
srcs = glob(
include = ["**/*.rs"],
allow_empty = True,
),
compile_data = glob(
include = ["**"],
allow_empty = True,
exclude = [
"**/* *",
".tmp_git_root/**/*",
"BUILD",
"BUILD.bazel",
"WORKSPACE",
"WORKSPACE.bazel",
],
),
crate_root = "src/lib.rs",
edition = "2018",
rustc_flags = [
"--cap-lints=allow",
],
tags = [
"cargo-bazel",
"crate-name=keccak",
"manual",
"noclippy",
"norustfmt",
],
version = "0.1.6",
deps = select({
"@rules_rust//rust/platform:aarch64-apple-darwin": [
"@crates_vendor__cpufeatures-0.2.17//:cpufeatures", # cfg(target_arch = "aarch64")
],
"@rules_rust//rust/platform:aarch64-unknown-linux-gnu": [
"@crates_vendor__cpufeatures-0.2.17//:cpufeatures", # cfg(target_arch = "aarch64")
],
"//conditions:default": [],
}),
)
48 changes: 48 additions & 0 deletions deps/rust/crates/BUILD.sha3-0.10.8.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
###############################################################################
# @generated
# DO NOT MODIFY: This file is auto-generated by a crate_universe tool. To
# regenerate this file, run the following:
#
# bazel run @@//deps/rust:crates_vendor
###############################################################################

load("@rules_rust//rust:defs.bzl", "rust_library")

package(default_visibility = ["//visibility:public"])

rust_library(
name = "sha3",
srcs = glob(
include = ["**/*.rs"],
allow_empty = True,
),
compile_data = glob(
include = ["**"],
allow_empty = True,
exclude = [
"**/* *",
".tmp_git_root/**/*",
"BUILD",
"BUILD.bazel",
"WORKSPACE",
"WORKSPACE.bazel",
],
),
crate_root = "src/lib.rs",
edition = "2018",
rustc_flags = [
"--cap-lints=allow",
],
tags = [
"cargo-bazel",
"crate-name=sha3",
"manual",
"noclippy",
"norustfmt",
],
version = "0.10.8",
deps = [
"@crates_vendor__digest-0.10.7//:digest",
"@crates_vendor__keccak-0.1.6//:keccak",
],
)
23 changes: 23 additions & 0 deletions deps/rust/crates/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ _NORMAL_DEPENDENCIES = {
"scratch": Label("@crates_vendor//:scratch-1.0.9"),
"serde": Label("@crates_vendor//:serde-1.0.228"),
"serde_json": Label("@crates_vendor//:serde_json-1.0.149"),
"sha3": Label("@crates_vendor//:sha3-0.10.8"),
"static_assertions": Label("@crates_vendor//:static_assertions-1.1.0"),
"swc_common": Label("@crates_vendor//:swc_common-18.0.1"),
"swc_ts_fast_strip": Label("@crates_vendor//:swc_ts_fast_strip-43.0.0"),
Expand Down Expand Up @@ -410,6 +411,7 @@ _CONDITIONS = {
"cfg(any(unix, target_os = \"wasi\"))": ["@rules_rust//rust/platform:aarch64-apple-darwin", "@rules_rust//rust/platform:aarch64-unknown-linux-gnu", "@rules_rust//rust/platform:x86_64-apple-darwin", "@rules_rust//rust/platform:x86_64-unknown-linux-gnu"],
"cfg(not(all(target_arch = \"arm\", target_os = \"none\")))": ["@rules_rust//rust/platform:aarch64-apple-darwin", "@rules_rust//rust/platform:aarch64-unknown-linux-gnu", "@rules_rust//rust/platform:x86_64-apple-darwin", "@rules_rust//rust/platform:x86_64-pc-windows-msvc", "@rules_rust//rust/platform:x86_64-unknown-linux-gnu"],
"cfg(not(windows))": ["@rules_rust//rust/platform:aarch64-apple-darwin", "@rules_rust//rust/platform:aarch64-unknown-linux-gnu", "@rules_rust//rust/platform:x86_64-apple-darwin", "@rules_rust//rust/platform:x86_64-unknown-linux-gnu"],
"cfg(target_arch = \"aarch64\")": ["@rules_rust//rust/platform:aarch64-apple-darwin", "@rules_rust//rust/platform:aarch64-unknown-linux-gnu"],
"cfg(target_os = \"hermit\")": [],
"cfg(target_os = \"netbsd\")": [],
"cfg(target_os = \"solaris\")": [],
Expand Down Expand Up @@ -1390,6 +1392,16 @@ def crate_repositories():
build_file = Label("//deps/rust/crates:BUILD.js-sys-0.3.91.bazel"),
)

maybe(
http_archive,
name = "crates_vendor__keccak-0.1.6",
sha256 = "cb26cec98cce3a3d96cbb7bced3c4b16e3d13f27ec56dbd62cbc8f39cfb9d653",
type = "tar.gz",
urls = ["https://static.crates.io/crates/keccak/0.1.6/download"],
strip_prefix = "keccak-0.1.6",
build_file = Label("//deps/rust/crates:BUILD.keccak-0.1.6.bazel"),
)

maybe(
http_archive,
name = "crates_vendor__libc-0.2.183",
Expand Down Expand Up @@ -2039,6 +2051,16 @@ def crate_repositories():
build_file = Label("//deps/rust/crates:BUILD.sha1-0.10.6.bazel"),
)

maybe(
http_archive,
name = "crates_vendor__sha3-0.10.8",
sha256 = "75872d278a8f37ef87fa0ddbda7802605cb18344497949862c0d4dcb291eba60",
type = "tar.gz",
urls = ["https://static.crates.io/crates/sha3/0.10.8/download"],
strip_prefix = "sha3-0.10.8",
build_file = Label("//deps/rust/crates:BUILD.sha3-0.10.8.bazel"),
)

maybe(
http_archive,
name = "crates_vendor__shlex-1.3.0",
Expand Down Expand Up @@ -2855,6 +2877,7 @@ def crate_repositories():
struct(repo = "crates_vendor__scratch-1.0.9", is_dev_dep = False),
struct(repo = "crates_vendor__serde-1.0.228", is_dev_dep = False),
struct(repo = "crates_vendor__serde_json-1.0.149", is_dev_dep = False),
struct(repo = "crates_vendor__sha3-0.10.8", is_dev_dep = False),
struct(repo = "crates_vendor__static_assertions-1.1.0", is_dev_dep = False),
struct(repo = "crates_vendor__swc_common-18.0.1", is_dev_dep = False),
struct(repo = "crates_vendor__swc_ts_fast_strip-43.0.0", is_dev_dep = False),
Expand Down
10 changes: 10 additions & 0 deletions src/rust/sha3/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
load("//:build/wd_rust_crate.bzl", "wd_rust_crate")

wd_rust_crate(
name = "sha3",
cxx_bridge_src = "lib.rs",
visibility = ["//visibility:public"],
deps = [
"@crates_vendor//:sha3",
],
)
101 changes: 101 additions & 0 deletions src/rust/sha3/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
use sha3::Digest;
use sha3::digest::ExtendableOutput;
use sha3::digest::Update;
use sha3::digest::XofReader;
use sha3::digest::core_api::CoreWrapper;

#[cxx::bridge(namespace = "workerd::rust::sha3")]
mod ffi {
extern "Rust" {
fn sha3_256(data: &[u8]) -> Vec<u8>;
fn sha3_384(data: &[u8]) -> Vec<u8>;
fn sha3_512(data: &[u8]) -> Vec<u8>;
fn turboshake128(data: &[u8], output_len: usize, domain_separation: u8) -> Vec<u8>;
fn turboshake256(data: &[u8], output_len: usize, domain_separation: u8) -> Vec<u8>;
fn cshake128(
data: &[u8],
output_len: usize,
function_name: &[u8],
customization: &[u8],
) -> Vec<u8>;
fn cshake256(
data: &[u8],
output_len: usize,
function_name: &[u8],
customization: &[u8],
) -> Vec<u8>;
}
}

#[must_use]
pub fn sha3_256(data: &[u8]) -> Vec<u8> {
sha3::Sha3_256::digest(data).to_vec()
}

#[must_use]
pub fn sha3_384(data: &[u8]) -> Vec<u8> {
sha3::Sha3_384::digest(data).to_vec()
}

#[must_use]
pub fn sha3_512(data: &[u8]) -> Vec<u8> {
sha3::Sha3_512::digest(data).to_vec()
}

#[must_use]
pub fn turboshake128(data: &[u8], output_len: usize, domain_separation: u8) -> Vec<u8> {
debug_assert!((0x01..=0x7F).contains(&domain_separation));
let mut hasher = CoreWrapper::from_core(sha3::TurboShake128Core::new(domain_separation));
hasher.update(data);
let mut reader = hasher.finalize_xof();
let mut output = vec![0u8; output_len];
reader.read(&mut output);
output
}

#[must_use]
pub fn turboshake256(data: &[u8], output_len: usize, domain_separation: u8) -> Vec<u8> {
debug_assert!((0x01..=0x7F).contains(&domain_separation));
let mut hasher = CoreWrapper::from_core(sha3::TurboShake256Core::new(domain_separation));
hasher.update(data);
let mut reader = hasher.finalize_xof();
let mut output = vec![0u8; output_len];
reader.read(&mut output);
output
}

#[must_use]
pub fn cshake128(
data: &[u8],
output_len: usize,
function_name: &[u8],
customization: &[u8],
) -> Vec<u8> {
let mut hasher = CoreWrapper::from_core(sha3::CShake128Core::new_with_function_name(
function_name,
customization,
));
hasher.update(data);
let mut reader = hasher.finalize_xof();
let mut output = vec![0u8; output_len];
reader.read(&mut output);
output
}

#[must_use]
pub fn cshake256(
data: &[u8],
output_len: usize,
function_name: &[u8],
customization: &[u8],
) -> Vec<u8> {
let mut hasher = CoreWrapper::from_core(sha3::CShake256Core::new_with_function_name(
function_name,
customization,
));
hasher.update(data);
let mut reader = hasher.finalize_xof();
let mut output = vec![0u8; output_len];
reader.read(&mut output);
output
}
Loading
Loading