Skip to content

Commit

Permalink
refactor: crypto and base64 module encoding parameter (#1622)
Browse files Browse the repository at this point in the history
Signed-off-by: peefy <[email protected]>
  • Loading branch information
Peefy authored Sep 3, 2024
1 parent bf8505d commit 4151909
Show file tree
Hide file tree
Showing 20 changed files with 271 additions and 161 deletions.
2 changes: 1 addition & 1 deletion compiler_base/3rdparty/rustc_span/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ tracing = "0.1"
sha1 = { package = "sha-1", version = "0.10.0" }
sha2 = "0.10.1"
md5 = { package = "md-5", version = "0.10.0" }
blake3 = "1.5.4"
blake3 = "1.5.4"
8 changes: 3 additions & 5 deletions compiler_base/3rdparty/rustc_span/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ use std::path::{Path, PathBuf};
use std::rc::Rc;
use std::str::FromStr;

use md5::Digest;
use blake3;
use blake3::Hash as Blake3;
use md5::Digest;
use md5::Md5;
use sha1::Sha1;
use sha2::Sha256;
Expand Down Expand Up @@ -647,10 +648,7 @@ impl SourceFileHash {
value.copy_from_slice(&Sha256::digest(data));
}
SourceFileHashAlgorithm::Blake3 => {
let mut hasher = Blake3::new();
hasher.update(data);
let result = hasher.finalize();
value.copy_from_slice(result.as_bytes());
value.copy_from_slice(blake3::hash(data).as_bytes());
}
}
hash
Expand Down
65 changes: 65 additions & 0 deletions kclvm/Cargo.lock

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

6 changes: 3 additions & 3 deletions kclvm/api/src/service/service_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,9 @@ impl KclvmServiceImpl {
/// assert_eq!(result.type_errors.len(), 0);
/// assert_eq!(result.symbols.len(), 12);
/// assert_eq!(result.scopes.len(), 3);
/// assert_eq!(result.node_symbol_map.len(), 181);
/// assert_eq!(result.symbol_node_map.len(), 181);
/// assert_eq!(result.fully_qualified_name_map.len(), 191);
/// assert_eq!(result.node_symbol_map.len(), 182);
/// assert_eq!(result.symbol_node_map.len(), 182);
/// assert_eq!(result.fully_qualified_name_map.len(), 192);
/// assert_eq!(result.pkg_scope_map.len(), 3);
/// ```
#[inline]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,6 @@ expression: "format!(\"{:#?}\", p.symbols.values())"
},
),
attrs: [
SymbolRef {
id: Index {
index: 140,
generation: 0,
},
kind: Function,
},
SymbolRef {
id: Index {
index: 141,
Expand Down Expand Up @@ -291,6 +284,13 @@ expression: "format!(\"{:#?}\", p.symbols.values())"
},
kind: Function,
},
SymbolRef {
id: Index {
index: 169,
generation: 0,
},
kind: Function,
},
],
is_global: false,
},
Expand Down
42 changes: 21 additions & 21 deletions kclvm/loader/src/snapshots/kclvm_loader__tests__builtin_call_1.snap
Original file line number Diff line number Diff line change
Expand Up @@ -240,13 +240,6 @@ expression: "format!(\"{:#?}\", p.symbols.values())"
},
),
attrs: [
SymbolRef {
id: Index {
index: 140,
generation: 0,
},
kind: Function,
},
SymbolRef {
id: Index {
index: 141,
Expand Down Expand Up @@ -443,6 +436,13 @@ expression: "format!(\"{:#?}\", p.symbols.values())"
},
kind: Function,
},
SymbolRef {
id: Index {
index: 169,
generation: 0,
},
kind: Function,
},
],
is_global: false,
},
Expand Down Expand Up @@ -482,13 +482,6 @@ expression: "format!(\"{:#?}\", p.symbols.values())"
},
),
attrs: [
SymbolRef {
id: Index {
index: 140,
generation: 0,
},
kind: Function,
},
SymbolRef {
id: Index {
index: 141,
Expand Down Expand Up @@ -685,6 +678,13 @@ expression: "format!(\"{:#?}\", p.symbols.values())"
},
kind: Function,
},
SymbolRef {
id: Index {
index: 169,
generation: 0,
},
kind: Function,
},
],
is_global: false,
},
Expand Down Expand Up @@ -724,13 +724,6 @@ expression: "format!(\"{:#?}\", p.symbols.values())"
},
),
attrs: [
SymbolRef {
id: Index {
index: 140,
generation: 0,
},
kind: Function,
},
SymbolRef {
id: Index {
index: 141,
Expand Down Expand Up @@ -927,6 +920,13 @@ expression: "format!(\"{:#?}\", p.symbols.values())"
},
kind: Function,
},
SymbolRef {
id: Index {
index: 169,
generation: 0,
},
kind: Function,
},
],
is_global: false,
},
Expand Down
42 changes: 21 additions & 21 deletions kclvm/loader/src/snapshots/kclvm_loader__tests__builtin_call_2.snap
Original file line number Diff line number Diff line change
Expand Up @@ -562,13 +562,6 @@ expression: "format!(\"{:#?}\", p.symbols.values())"
},
),
attrs: [
SymbolRef {
id: Index {
index: 140,
generation: 0,
},
kind: Function,
},
SymbolRef {
id: Index {
index: 141,
Expand Down Expand Up @@ -765,6 +758,13 @@ expression: "format!(\"{:#?}\", p.symbols.values())"
},
kind: Function,
},
SymbolRef {
id: Index {
index: 169,
generation: 0,
},
kind: Function,
},
],
is_global: false,
},
Expand Down Expand Up @@ -804,13 +804,6 @@ expression: "format!(\"{:#?}\", p.symbols.values())"
},
),
attrs: [
SymbolRef {
id: Index {
index: 140,
generation: 0,
},
kind: Function,
},
SymbolRef {
id: Index {
index: 141,
Expand Down Expand Up @@ -1007,6 +1000,13 @@ expression: "format!(\"{:#?}\", p.symbols.values())"
},
kind: Function,
},
SymbolRef {
id: Index {
index: 169,
generation: 0,
},
kind: Function,
},
],
is_global: false,
},
Expand Down Expand Up @@ -1046,13 +1046,6 @@ expression: "format!(\"{:#?}\", p.symbols.values())"
},
),
attrs: [
SymbolRef {
id: Index {
index: 140,
generation: 0,
},
kind: Function,
},
SymbolRef {
id: Index {
index: 141,
Expand Down Expand Up @@ -1249,6 +1242,13 @@ expression: "format!(\"{:#?}\", p.symbols.values())"
},
kind: Function,
},
SymbolRef {
id: Index {
index: 169,
generation: 0,
},
kind: Function,
},
],
is_global: false,
},
Expand Down
3 changes: 2 additions & 1 deletion kclvm/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ regex = "1.5.5"
md5 = "0.7.0"
sha2 = "0.9.8"
sha1 = "0.6.0"
blake3 = "1.5.4"
chrono = "0.4.19"
ahash = "0.7.2"
indexmap = "1.0"
Expand All @@ -33,6 +32,8 @@ uuid = { version = "1.7.0", features = ["serde", "v4"] }
handlebars = "5.1.2"
walkdir = "2.5.0"
anyhow = "1"
blake3 = "1.5.4"
encoding = "0.2.33"

[[bin]]
name = "gen-api-spec"
Expand Down
Binary file modified kclvm/runtime/src/_kclvm.bc
Binary file not shown.
20 changes: 10 additions & 10 deletions kclvm/runtime/src/_kclvm.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ typedef struct kclvm_value_t kclvm_value_t;

void kclvm_assert(kclvm_context_t* ctx, kclvm_value_ref_t* value, kclvm_value_ref_t* msg);

kclvm_value_ref_t* kclvm_base64_decode(kclvm_context_t* ctx, kclvm_value_ref_t* args, kclvm_value_ref_t* _kwargs);
kclvm_value_ref_t* kclvm_base64_decode(kclvm_context_t* ctx, kclvm_value_ref_t* args, kclvm_value_ref_t* kwargs);

kclvm_value_ref_t* kclvm_base64_encode(kclvm_context_t* ctx, kclvm_value_ref_t* args, kclvm_value_ref_t* _kwargs);
kclvm_value_ref_t* kclvm_base64_encode(kclvm_context_t* ctx, kclvm_value_ref_t* args, kclvm_value_ref_t* kwargs);

kclvm_value_ref_t* kclvm_builtin_abs(kclvm_context_t* ctx, kclvm_value_ref_t* args, kclvm_value_ref_t* kwargs);

Expand Down Expand Up @@ -225,21 +225,21 @@ void kclvm_context_set_strict_range_check(kclvm_context_t* p, kclvm_bool_t v);

kclvm_value_ref_t* kclvm_convert_collection_value(kclvm_context_t* ctx, kclvm_value_ref_t* value, kclvm_char_t* tpe, kclvm_value_ref_t* is_in_schema);

kclvm_value_ref_t* kclvm_crypto_filesha256(kclvm_context_t* ctx, kclvm_value_ref_t* args, kclvm_value_ref_t* _kwargs);
kclvm_value_ref_t* kclvm_crypto_blake3(kclvm_context_t* ctx, kclvm_value_ref_t* args, kclvm_value_ref_t* kwargs);

kclvm_value_ref_t* kclvm_crypto_md5(kclvm_context_t* ctx, kclvm_value_ref_t* args, kclvm_value_ref_t* _kwargs);
kclvm_value_ref_t* kclvm_crypto_filesha256(kclvm_context_t* ctx, kclvm_value_ref_t* args, kclvm_value_ref_t* kwargs);

kclvm_value_ref_t* kclvm_crypto_sha1(kclvm_context_t* ctx, kclvm_value_ref_t* args, kclvm_value_ref_t* _kwargs);
kclvm_value_ref_t* kclvm_crypto_md5(kclvm_context_t* ctx, kclvm_value_ref_t* args, kclvm_value_ref_t* kwargs);

kclvm_value_ref_t* kclvm_crypto_sha224(kclvm_context_t* ctx, kclvm_value_ref_t* args, kclvm_value_ref_t* _kwargs);
kclvm_value_ref_t* kclvm_crypto_sha1(kclvm_context_t* ctx, kclvm_value_ref_t* args, kclvm_value_ref_t* kwargs);

kclvm_value_ref_t* kclvm_crypto_sha256(kclvm_context_t* ctx, kclvm_value_ref_t* args, kclvm_value_ref_t* _kwargs);
kclvm_value_ref_t* kclvm_crypto_sha224(kclvm_context_t* ctx, kclvm_value_ref_t* args, kclvm_value_ref_t* kwargs);

kclvm_value_ref_t* kclvm_crypto_sha384(kclvm_context_t* ctx, kclvm_value_ref_t* args, kclvm_value_ref_t* _kwargs);
kclvm_value_ref_t* kclvm_crypto_sha256(kclvm_context_t* ctx, kclvm_value_ref_t* args, kclvm_value_ref_t* kwargs);

kclvm_value_ref_t* kclvm_crypto_sha512(kclvm_context_t* ctx, kclvm_value_ref_t* args, kclvm_value_ref_t* _kwargs);
kclvm_value_ref_t* kclvm_crypto_sha384(kclvm_context_t* ctx, kclvm_value_ref_t* args, kclvm_value_ref_t* kwargs);

kclvm_value_ref_t* kclvm_crypto_blake3(kclvm_context_t* ctx, kclvm_value_ref_t* args, kclvm_value_ref_t* _kwargs);
kclvm_value_ref_t* kclvm_crypto_sha512(kclvm_context_t* ctx, kclvm_value_ref_t* args, kclvm_value_ref_t* kwargs);

kclvm_value_ref_t* kclvm_crypto_uuid(kclvm_context_t* ctx, kclvm_value_ref_t* _args, kclvm_value_ref_t* _kwargs);

Expand Down
Loading

0 comments on commit 4151909

Please sign in to comment.