feat: lifetime elision, tooling CI, registry, and LSP locals
Ship the QUALITY_PLAN stretch from ownership through ecosystem: C.1 lifetime elision (bootstrap + selfhost), bux fmt/test/doc CI hooks, stdlib goldens, package registry (bux search/add), and LSP 0.4 position-sensitive locals with inferred let types. Full-tree format pass plus Map/Set remove double-free fix.
This commit is contained in:
+61
-61
@@ -10,72 +10,72 @@
|
||||
// =============================================================================
|
||||
module Std::Crypto {
|
||||
|
||||
import Std::Mem::{Alloc, Free};
|
||||
import Std::String::{String_Len};
|
||||
import Std::Mem::{Alloc, Free};
|
||||
import Std::String::{String_Len};
|
||||
|
||||
// Re-use the same externs from submodules (merged by compiler)
|
||||
extern func bux_sha256(data: String, len: int, out: *void);
|
||||
extern func bux_hmac_sha256(key: String, keylen: int, msg: String, msglen: int, out: *void);
|
||||
extern func bux_random_bytes(buf: *void, len: int) -> int;
|
||||
extern func bux_base64_encode(data: String, len: int) -> String;
|
||||
extern func bux_base64_decode(data: String, len: int, outlen: *int) -> String;
|
||||
extern func bux_bytes_to_hex(data: *void, len: int) -> String;
|
||||
// Re-use the same externs from submodules (merged by compiler)
|
||||
extern func bux_sha256(data: String, len: int, out: *void);
|
||||
extern func bux_hmac_sha256(key: String, keylen: int, msg: String, msglen: int, out: *void);
|
||||
extern func bux_random_bytes(buf: *void, len: int) -> int;
|
||||
extern func bux_base64_encode(data: String, len: int) -> String;
|
||||
extern func bux_base64_decode(data: String, len: int, outlen: *int) -> String;
|
||||
extern func bux_bytes_to_hex(data: *void, len: int) -> String;
|
||||
|
||||
// --- Legacy function names (delegate to new submodule functions) ---
|
||||
// --- Legacy function names (delegate to new submodule functions) ---
|
||||
|
||||
// SHA-256 → hex
|
||||
func Crypto_Sha256(data: String) -> String {
|
||||
let len: int = String_Len(data) as int;
|
||||
let hashBuf: *void = Alloc(32);
|
||||
bux_sha256(data, len, hashBuf);
|
||||
let result: String = bux_bytes_to_hex(hashBuf as *void, 32);
|
||||
Free(hashBuf);
|
||||
return result;
|
||||
}
|
||||
|
||||
// HMAC-SHA256 → hex
|
||||
func Crypto_HmacSha256(key: String, message: String) -> String {
|
||||
let keylen: int = String_Len(key) as int;
|
||||
let msglen: int = String_Len(message) as int;
|
||||
let hmacBuf: *void = Alloc(32);
|
||||
bux_hmac_sha256(key, keylen, message, msglen, hmacBuf);
|
||||
let result: String = bux_bytes_to_hex(hmacBuf as *void, 32);
|
||||
Free(hmacBuf);
|
||||
return result;
|
||||
}
|
||||
|
||||
// Random bytes → base64
|
||||
func Crypto_RandomBytes(n: int) -> String {
|
||||
if n <= 0 { return ""; }
|
||||
let buf: *void = Alloc(n as uint);
|
||||
if bux_random_bytes(buf, n) != 1 {
|
||||
Free(buf);
|
||||
return "";
|
||||
// SHA-256 → hex
|
||||
func Crypto_Sha256(data: String) -> String {
|
||||
let len: int = String_Len(data) as int;
|
||||
let hashBuf: *void = Alloc(32);
|
||||
bux_sha256(data, len, hashBuf);
|
||||
let result: String = bux_bytes_to_hex(hashBuf as *void, 32);
|
||||
Free(hashBuf);
|
||||
return result;
|
||||
}
|
||||
let result: String = bux_base64_encode(buf as String, n);
|
||||
Free(buf);
|
||||
return result;
|
||||
}
|
||||
|
||||
// Base64 encode
|
||||
func Crypto_Base64Encode(s: String) -> String {
|
||||
return bux_base64_encode(s, String_Len(s) as int);
|
||||
}
|
||||
// HMAC-SHA256 → hex
|
||||
func Crypto_HmacSha256(key: String, message: String) -> String {
|
||||
let keylen: int = String_Len(key) as int;
|
||||
let msglen: int = String_Len(message) as int;
|
||||
let hmacBuf: *void = Alloc(32);
|
||||
bux_hmac_sha256(key, keylen, message, msglen, hmacBuf);
|
||||
let result: String = bux_bytes_to_hex(hmacBuf as *void, 32);
|
||||
Free(hmacBuf);
|
||||
return result;
|
||||
}
|
||||
|
||||
// HMAC-SHA256 raw → base64
|
||||
func Crypto_HmacSha256Raw(key: String, message: String) -> String {
|
||||
let keylen: int = String_Len(key) as int;
|
||||
let msglen: int = String_Len(message) as int;
|
||||
let hmacBuf: *void = Alloc(32);
|
||||
bux_hmac_sha256(key, keylen, message, msglen, hmacBuf);
|
||||
let result: String = bux_base64_encode(hmacBuf as String, 32);
|
||||
Free(hmacBuf);
|
||||
return result;
|
||||
}
|
||||
// Random bytes → base64
|
||||
func Crypto_RandomBytes(n: int) -> String {
|
||||
if n <= 0 { return ""; }
|
||||
let buf: *void = Alloc(n as uint);
|
||||
if bux_random_bytes(buf, n) != 1 {
|
||||
Free(buf);
|
||||
return "";
|
||||
}
|
||||
let result: String = bux_base64_encode(buf as String, n);
|
||||
Free(buf);
|
||||
return result;
|
||||
}
|
||||
|
||||
// Base64 decode
|
||||
func Crypto_Base64Decode(s: String) -> String {
|
||||
let outlen: int = 0;
|
||||
return bux_base64_decode(s, String_Len(s) as int, &outlen);
|
||||
}
|
||||
// Base64 encode
|
||||
func Crypto_Base64Encode(s: String) -> String {
|
||||
return bux_base64_encode(s, String_Len(s) as int);
|
||||
}
|
||||
|
||||
// HMAC-SHA256 raw → base64
|
||||
func Crypto_HmacSha256Raw(key: String, message: String) -> String {
|
||||
let keylen: int = String_Len(key) as int;
|
||||
let msglen: int = String_Len(message) as int;
|
||||
let hmacBuf: *void = Alloc(32);
|
||||
bux_hmac_sha256(key, keylen, message, msglen, hmacBuf);
|
||||
let result: String = bux_base64_encode(hmacBuf as String, 32);
|
||||
Free(hmacBuf);
|
||||
return result;
|
||||
}
|
||||
|
||||
// Base64 decode
|
||||
func Crypto_Base64Decode(s: String) -> String {
|
||||
let outlen: int = 0;
|
||||
return bux_base64_decode(s, String_Len(s) as int, &outlen);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user