Commit a47bb89
Richer stdlib: sha256/sha512, base64, datetime via chrono
Eighth piece of the Python ergonomics catch-up. Three small but
high-leverage stdlib additions:
HASHING (via sha2 crate):
sha256(text) -> 64-char hex string
sha512(text) -> 128-char hex string
Deterministic, NIST-standard. Common use cases (content
addressing, integrity check, password hashing scaffolding)
can now be done without an embedded-Python detour.
BASE64 (via base64 crate, STANDARD engine):
base64_encode(text) -> string
base64_decode(string) -> text
Round-trip identity. The decoder requires valid UTF-8 output;
binary blobs that aren't UTF-8 raise an error rather than
return garbage. Future work: bytes type for non-textual data.
DATETIME (via chrono):
now_iso() -> ISO 8601 timestamp string
now_unix() -> seconds since epoch (i64)
format_time(unix_seconds, fmt) -> formatted string
parse_time(string, fmt) -> unix_seconds
chrono::strftime-style format specifiers (%Y, %m, %d, %H, %M, %S).
Tests (examples/tests/test_stdlib.omc — 12 tests, all pass):
- sha256: empty string + 'hello' against canonical hex digests
- sha256/sha512 length invariants (64 / 128 hex chars)
- sha256 determinism + different inputs differ
- base64 round-trip + known encode/decode pair + empty string
- now_unix reasonable range (post-2023, pre-year-2603 sanity)
- now_iso format starts with YYYY-MM-DD (regex)
- format_time(0, ...) is 1970-01-01 (Unix epoch)
- parse_time → format_time round-trip
What this unlocks:
- Content-addressed substrate identifiers (sha256 of OMC source
→ stable build hashes)
- HTTP basic-auth header construction (base64_encode of user:pass)
- Time-series substrate analysis with proper datetime parsing
- Logging / instrumentation with formatted timestamps
What's NOT yet in stdlib:
- URL encoding (url_encode/url_decode)
- Bytes type (everything strings)
- MD5 (legacy; can add via md-5 crate when needed)
- File globbing (glob_match)
- Timezone-aware datetime ops
Cargo.toml: added sha2, base64, chrono (chrono with std + clock
features only — no default for serde to keep transient deps light).
Regression: 240 OMC tests + 12 new stdlib = 252 OMC tests pass.
All previous suites green.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>1 parent f57beb1 commit a47bb89
5 files changed
Lines changed: 375 additions & 0 deletions
File tree
- examples/tests
- omnimcode-core
- src
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
0 commit comments