-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[v4.0] feat: implement hashing content in Rust (#5155)
- Loading branch information
Showing
416 changed files
with
504 additions
and
491 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,2 @@ | ||
// eslint-disable-next-line import/no-unresolved | ||
import { parse } from '../../wasm/bindings_wasm.js'; | ||
|
||
export default { | ||
parse | ||
}; | ||
export { parse, xxhash_base64_url as xxhashBase64Url } from '../../wasm/bindings_wasm.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,5 @@ members = [ | |
"bindings_napi", | ||
"bindings_wasm", | ||
"parse_ast", | ||
"xxhash" | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,14 @@ | ||
use js_sys::Uint8Array; | ||
use parse_ast::parse_ast; | ||
use wasm_bindgen::prelude::*; | ||
use xxhash; | ||
|
||
#[wasm_bindgen] | ||
pub fn parse(code: String, allow_return_outside_function: bool) -> Vec<u8> { | ||
parse_ast(code, allow_return_outside_function) | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub fn xxhash_base64_url(input: Uint8Array) -> String { | ||
xxhash::xxhash_base64_url(&input.to_vec()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[package] | ||
name = "xxhash" | ||
version = "0.0.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
base64 = '0.21.4' | ||
xxhash-rust = { version = "0.8.7", features = ["xxh3"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
use base64::{engine::general_purpose, Engine as _}; | ||
use xxhash_rust::xxh3::xxh3_128; | ||
|
||
pub fn xxhash_base64_url(input: &[u8]) -> String { | ||
let hash = xxh3_128(input).to_le_bytes(); | ||
general_purpose::URL_SAFE_NO_PAD.encode(&hash) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,17 @@ | ||
import { createHash as cryptoCreateHash, type Hash } from 'node:crypto'; | ||
import { xxhashBase64Url } from '../../native'; | ||
|
||
export const createHash = (): Hash => cryptoCreateHash('sha256'); | ||
let textEncoder: TextEncoder; | ||
export function getXxhash(input: string | Uint8Array) { | ||
let buffer: Uint8Array; | ||
if (typeof input === 'string') { | ||
if (typeof Buffer === 'undefined') { | ||
textEncoder ??= new TextEncoder(); | ||
buffer = textEncoder.encode(input); | ||
} else { | ||
buffer = Buffer.from(input); | ||
} | ||
} else { | ||
buffer = input; | ||
} | ||
return xxhashBase64Url(buffer); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.