From 53a99cd3c039cbea754a9ae433c2fdfcadbe477f Mon Sep 17 00:00:00 2001 From: Dave Grantham Date: Mon, 13 Jul 2026 13:17:47 -0600 Subject: [PATCH 1/2] update from bettersign Signed-off-by: Dave Grantham --- CHANGELOG.md | 8 + Cargo.lock | 701 +++++++++++++++++------------------------ Cargo.toml | 16 +- benches/multibase.rs | 42 +-- src/base.rs | 6 + src/encoded.rs | 16 +- src/error.rs | 9 +- src/impls.rs | 123 +++++++- src/lib.rs | 18 +- tests/lib.rs | 64 ++-- tests/properties.rs | 4 +- tests/security.rs | 4 +- tests/thread_safety.rs | 20 +- 13 files changed, 518 insertions(+), 513 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fd8d1ce..36e8793 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.0.0] - 2026-07-13 + +### Changed +- Synced from bettersign workspace (bs-multibase 0.7.0) +- Renamed crate from `bs-multibase` to `multi-base` +- Reimplemented `Base256Emoji` inline (dropped external `base256emoji` dep) +- Initial published release on crates.io as `multi-base` + ## [Unreleased] ### Added diff --git a/Cargo.lock b/Cargo.lock index 449333e..62fcbe2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,74 +4,33 @@ version = 4 [[package]] name = "aho-corasick" -version = "1.1.3" +version = "1.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +checksum = "ddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301" dependencies = [ "memchr", ] [[package]] -name = "anes" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299" - -[[package]] -name = "anstream" -version = "0.6.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "301af1932e46185686725e0fad2f8f2aa7da69dd70bf6ecc44d6b703844a3933" -dependencies = [ - "anstyle", - "anstyle-parse", - "anstyle-query", - "anstyle-wincon", - "colorchoice", - "is_terminal_polyfill", - "utf8parse", -] - -[[package]] -name = "anstyle" -version = "1.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "862ed96ca487e809f1c8e5a8447f6ee2cf102f846893800b20cebdf541fc6bbd" - -[[package]] -name = "anstyle-parse" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e7644824f0aa2c7b9384579234ef10eb7efb6a0deb83f9630a49594dd9c15c2" -dependencies = [ - "utf8parse", -] - -[[package]] -name = "anstyle-query" -version = "1.1.3" +name = "alloca" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8bdeb6047d8983be085bab0ba1472e6dc604e7041dbf6fcd5e71523014fae9" +checksum = "e5a7d05ea6aea7e9e64d25b9156ba2fee3fdd659e34e41063cd2fc7cd020d7f4" dependencies = [ - "windows-sys", + "cc", ] [[package]] -name = "anstyle-wincon" -version = "3.0.9" +name = "anes" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "403f75924867bb1033c59fbf0797484329750cfbe3c4325cd33127941fabc882" -dependencies = [ - "anstyle", - "once_cell_polyfill", - "windows-sys", -] +checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299" [[package]] -name = "anyhow" -version = "1.0.98" +name = "anstyle" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e16d2d3311acee920a9eb8d33b8cbc1787ce4a264e85f964c2404b969bdcd487" +checksum = "940b3a0ca603d1eade50a4846a2afffd5ef57a9feac2c0e2ec2e14f9ead76000" [[package]] name = "autocfg" @@ -85,16 +44,6 @@ version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4cbbc9d0964165b47557570cce6c952866c2678457aca742aafc9fb771d30270" -[[package]] -name = "base256emoji" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e9430d9a245a77c92176e649af6e275f20839a48389859d1661e9a128d077c" -dependencies = [ - "const-str", - "match-lookup", -] - [[package]] name = "bit-set" version = "0.8.0" @@ -112,15 +61,15 @@ checksum = "5e764a1d40d510daf35e07be9eb06e75770908c27d411ee6c92109c9840eaaf7" [[package]] name = "bitflags" -version = "2.9.1" +version = "2.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b8e56985ec62d17e9c1001dc89c88ecd7dc08e47eba5ec7c29c7b5eeecde967" +checksum = "b4388bee8683e3d04af747c73422af53102d2bd24d9eadb6cbc100baef4b43f8" [[package]] name = "bumpalo" -version = "3.19.0" +version = "3.20.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46c5e41b57b8bba42a04676d81cb89e9ee8e859a1a66f80a5a72e1cb76b34d43" +checksum = "72f5acc6cb2ba439de613abc23857ec3d78374d8ed5ac84e9d11336e87da8649" [[package]] name = "cast" @@ -128,11 +77,21 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" +[[package]] +name = "cc" +version = "1.2.67" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e17dd265a7d0f31ef544e1b20e03add05d3b45b491b633b10d67145d2acc1a38" +dependencies = [ + "find-msvc-tools", + "shlex", +] + [[package]] name = "cfg-if" -version = "1.0.1" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9555578bc9e57714c812a1f84e4fc5b4d21fcb063490c624de019f7464c91268" +checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" [[package]] name = "ciborium" @@ -163,62 +122,36 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.41" +version = "4.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be92d32e80243a54711e5d7ce823c35c41c9d929dc4ab58e1276f625841aadf9" +checksum = "1ddb117e43bbf7dacf0a4190fef4d345b9bad68dfc649cb349e7d17d28428e51" dependencies = [ "clap_builder", - "clap_derive", ] [[package]] name = "clap_builder" -version = "4.5.41" +version = "4.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "707eab41e9622f9139419d573eca0900137718000c517d47da73045f54331c3d" +checksum = "714a53001bf66416adb0e2ef5ac857140e7dc3a0c48fb28b2f10762fc4b5069f" dependencies = [ - "anstream", "anstyle", "clap_lex", - "strsim", -] - -[[package]] -name = "clap_derive" -version = "4.5.41" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef4f52386a59ca4c860f7393bcf8abd8dfd91ecccc0f774635ff68e92eeef491" -dependencies = [ - "heck", - "proc-macro2", - "quote", - "syn 2.0.104", ] [[package]] name = "clap_lex" -version = "0.7.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b94f61472cee1439c0b966b47e3aca9ae07e45d070759512cd390ea2bebc6675" - -[[package]] -name = "colorchoice" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75" - -[[package]] -name = "const-str" -version = "0.4.3" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f421161cb492475f1661ddc9815a745a1c894592070661180fdec3d4872e9c3" +checksum = "c8d4a3bb8b1e0c1050499d1815f5ab16d04f0959b233085fb31653fbfc9d98f9" [[package]] name = "criterion" -version = "0.7.0" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1c047a62b0cc3e145fa84415a3191f628e980b194c2755aa12300a4e6cbd928" +checksum = "950046b2aa2492f9a536f5f4f9a3de7b9e2476e575e05bd6c333371add4d98f3" dependencies = [ + "alloca", "anes", "cast", "ciborium", @@ -227,6 +160,7 @@ dependencies = [ "itertools", "num-traits", "oorandom", + "page_size", "plotters", "rayon", "regex", @@ -238,9 +172,9 @@ dependencies = [ [[package]] name = "criterion-plot" -version = "0.6.0" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b1bcc0dc7dfae599d84ad0b1a55f80cde8af3725da8313b528da95ef783e338" +checksum = "d8d80a2f4f5b554395e47b5d8305bc3d27813bacb73493eb1001e8f76dae29ea" dependencies = [ "cast", "itertools", @@ -279,15 +213,15 @@ checksum = "460fbee9c2c2f33933d720630a6a0bac33ba7053db5344fac858d4b8952d77d5" [[package]] name = "data-encoding" -version = "2.9.0" +version = "2.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a2330da5de22e8a3cb63252ce2abb30116bf5265e89c0e01bc17015ce30a476" +checksum = "a4ae5f15dda3c708c0ade84bfee31ccab44a3da4f88015ed22f63732abe300c8" [[package]] name = "data-encoding-macro" -version = "0.1.18" +version = "0.1.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47ce6c96ea0102f01122a185683611bd5ac8d99e62bc59dd12e6bda344ee673d" +checksum = "3259c913752a86488b501ed8680446a5ed2d5aeac6e596cb23ba3800768ea32c" dependencies = [ "data-encoding", "data-encoding-macro-internal", @@ -295,12 +229,12 @@ dependencies = [ [[package]] name = "data-encoding-macro-internal" -version = "0.1.16" +version = "0.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d162beedaa69905488a8da94f5ac3edb4dd4788b732fadb7bd120b2625c1976" +checksum = "ccc2776f0c61eca1ca32528f85548abd1a4be8fb53d1b21c013e4f18da1e7090" dependencies = [ "data-encoding", - "syn 2.0.104", + "syn 1.0.109", ] [[package]] @@ -309,29 +243,6 @@ version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" -[[package]] -name = "env_filter" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "186e05a59d4c50738528153b83b0b0194d3a29507dfec16eccd4b342903397d0" -dependencies = [ - "log", - "regex", -] - -[[package]] -name = "env_logger" -version = "0.11.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13c863f0904021b108aa8b2f55046443e6b1ebde8fd4a15c399893aae4fa069f" -dependencies = [ - "anstream", - "anstyle", - "env_filter", - "jiff", - "log", -] - [[package]] name = "errno" version = "0.3.14" @@ -348,45 +259,86 @@ version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" +[[package]] +name = "find-msvc-tools" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582" + [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "futures-core" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e3450815272ef58cec6d564423f6e755e25379b217b0bc688e295ba24df6b1d" + +[[package]] +name = "futures-task" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "037711b3d59c33004d3856fbdc83b99d4ff37a24768fa1be9ce3538a1cde4393" + +[[package]] +name = "futures-util" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "389ca41296e6190b48053de0321d02a77f32f8a5d2461dd38762c0593805c6d6" +dependencies = [ + "futures-core", + "futures-task", + "pin-project-lite", + "slab", +] + [[package]] name = "getrandom" -version = "0.3.3" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26145e563e54f2cadc477553f1ec5ee650b00862f0a58bcd12cbdc5f0ea2d2f4" +checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0" dependencies = [ "cfg-if", "libc", - "r-efi", "wasi", ] [[package]] -name = "half" -version = "2.6.0" +name = "getrandom" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "459196ed295495a68f7d7fe1d84f6c4b7ff0e21fe3017b2f283c6fac3ad803c9" +checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd" dependencies = [ "cfg-if", - "crunchy", + "libc", + "r-efi 5.3.0", + "wasip2", ] [[package]] -name = "heck" -version = "0.5.0" +name = "getrandom" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" +checksum = "300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099" +dependencies = [ + "cfg-if", + "libc", + "r-efi 6.0.0", +] [[package]] -name = "is_terminal_polyfill" -version = "1.70.1" +name = "half" +version = "2.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" +checksum = "6ea2d84b969582b4b1864a92dc5d27cd2b77b622a8d79306834f1be5ba20d84b" +dependencies = [ + "cfg-if", + "crunchy", + "zerocopy", +] [[package]] name = "itertools" @@ -399,110 +351,52 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" - -[[package]] -name = "jiff" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be1f93b8b1eb69c77f24bbb0afdf66f54b632ee39af40ca21c4365a1d7347e49" -dependencies = [ - "jiff-static", - "log", - "portable-atomic", - "portable-atomic-util", - "serde", -] - -[[package]] -name = "jiff-static" -version = "0.2.15" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03343451ff899767262ec32146f6d559dd759fdadf42ff0e227c7c48f72594b4" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.104", -] +checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" [[package]] name = "js-sys" -version = "0.3.77" +version = "0.3.103" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1cfaf33c695fc6e08064efbc1f72ec937429614f25eef83af942d0e227c3a28f" +checksum = "53b44bfcdb3f8d5837a46dae1ca9660a837176eee74a28b229bc626816589102" dependencies = [ - "once_cell", + "cfg-if", + "futures-util", "wasm-bindgen", ] -[[package]] -name = "lazy_static" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" - [[package]] name = "libc" -version = "0.2.174" +version = "0.2.186" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1171693293099992e19cddea4e8b849964e9846f4acee11b3948bcc337be8776" +checksum = "68ab91017fe16c622486840e4c83c9a37afeff978bd239b5293d61ece587de66" [[package]] name = "linux-raw-sys" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df1d3c3b53da64cf5760482273a98e575c651a67eec7f77df96b5b642de8f039" - -[[package]] -name = "log" -version = "0.4.27" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94" - -[[package]] -name = "match-lookup" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1265724d8cb29dbbc2b0f06fffb8bf1a8c0cf73a78eede9ba73a4a66c52a981e" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] +checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53" [[package]] name = "memchr" -version = "2.7.5" +version = "2.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32a282da65faaf38286cf3be983213fcf1d2e2a58700e808f83f4ea9a4804bc0" +checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98" [[package]] -name = "multibase" +name = "multi-base" version = "1.0.0" dependencies = [ "base-x", - "base256emoji", "criterion", "data-encoding", "data-encoding-macro", "proptest", - "rand", + "rand 0.8.7", "thiserror", ] -[[package]] -name = "multibase-cli" -version = "0.1.0" -dependencies = [ - "anyhow", - "clap", - "env_logger", - "log", - "multibase", -] - [[package]] name = "num-traits" version = "0.2.19" @@ -518,18 +412,28 @@ version = "1.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" -[[package]] -name = "once_cell_polyfill" -version = "1.70.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4895175b425cb1f87721b59f0f286c2092bd4af812243672510e1ac53e2e0ad" - [[package]] name = "oorandom" version = "11.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d6790f58c7ff633d8771f42965289203411a5e5c68388703c06e14f24770b41e" +[[package]] +name = "page_size" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30d5b2194ed13191c1999ae0704b7839fb18384fa22e49b57eeaa97d79ce40da" +dependencies = [ + "libc", + "winapi", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" + [[package]] name = "plotters" version = "0.3.7" @@ -558,21 +462,6 @@ dependencies = [ "plotters-backend", ] -[[package]] -name = "portable-atomic" -version = "1.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f84267b20a16ea918e43c6a88433c2d54fa145c92a811b5b047ccbe153674483" - -[[package]] -name = "portable-atomic-util" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8a2f0d8d040d7848a709caf78912debcc3f33ee4b3cac47d73d1e1069e83507" -dependencies = [ - "portable-atomic", -] - [[package]] name = "ppv-lite86" version = "0.2.21" @@ -584,26 +473,25 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.95" +version = "1.0.106" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778" +checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934" dependencies = [ "unicode-ident", ] [[package]] name = "proptest" -version = "1.8.0" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2bb0be07becd10686a0bb407298fb425360a5c44a663774406340c59a22de4ce" +checksum = "4b45fcc2344c680f5025fe57779faef368840d0bd1f42f216291f0dc4ace4744" dependencies = [ "bit-set", "bit-vec", "bitflags", - "lazy_static", "num-traits", - "rand", - "rand_chacha", + "rand 0.9.4", + "rand_chacha 0.9.0", "rand_xorshift", "regex-syntax", "rusty-fork", @@ -619,9 +507,9 @@ checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" [[package]] name = "quote" -version = "1.0.40" +version = "1.0.46" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" +checksum = "dfbc457d0c7a0759a614551b11a6409e5951f6c7537be1f1b7682b9ae9230368" dependencies = [ "proc-macro2", ] @@ -632,14 +520,41 @@ version = "5.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" +[[package]] +name = "r-efi" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" + +[[package]] +name = "rand" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22f6172bdec972074665ed81ed53b71da00bfc44b65a753cfde883ec4c702a1a" +dependencies = [ + "libc", + "rand_chacha 0.3.1", + "rand_core 0.6.4", +] + [[package]] name = "rand" -version = "0.9.1" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fbfd9d094a40bf3ae768db9361049ace4c0e04a4fd6b359518bd7b73a73dd97" +checksum = "44c5af06bb1b7d3216d91932aed5265164bf384dc89cd6ba05cf59a35f5f76ea" dependencies = [ - "rand_chacha", - "rand_core", + "rand_chacha 0.9.0", + "rand_core 0.9.3", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core 0.6.4", ] [[package]] @@ -649,7 +564,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" dependencies = [ "ppv-lite86", - "rand_core", + "rand_core 0.9.3", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom 0.2.17", ] [[package]] @@ -658,7 +582,7 @@ version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38" dependencies = [ - "getrandom", + "getrandom 0.3.4", ] [[package]] @@ -667,14 +591,14 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "513962919efc330f829edb2535844d1b912b0fbe2ca165d613e4e8788bb05a5a" dependencies = [ - "rand_core", + "rand_core 0.9.3", ] [[package]] name = "rayon" -version = "1.10.0" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa" +checksum = "fb39b166781f92d482534ef4b4b1b2568f42613b53e5b6c160e24cfbfa30926d" dependencies = [ "either", "rayon-core", @@ -682,9 +606,9 @@ dependencies = [ [[package]] name = "rayon-core" -version = "1.12.1" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2" +checksum = "22e18b0f0062d30d4230b2e85ff77fdfe4326feb054b9783a3460d8435c8ab91" dependencies = [ "crossbeam-deque", "crossbeam-utils", @@ -692,9 +616,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.11.1" +version = "1.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" +checksum = "f1292b7759ae1cb9ec195452d1390a074f0cd8541ab7a5a8c31cd6db45d4a6ba" dependencies = [ "aho-corasick", "memchr", @@ -704,9 +628,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.9" +version = "0.4.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" +checksum = "1f388202e4b80542a0921078cc23b6333bcf1409c1e3f86404cae4766a6131db" dependencies = [ "aho-corasick", "memchr", @@ -715,15 +639,15 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.8.5" +version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" +checksum = "d6f6ff9a378485b298a5286656da665ba74413d36db0979633275d2e708145d4" [[package]] name = "rustix" -version = "1.1.2" +version = "1.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd15f8a2c5551a84d56efdc1cd049089e409ac19a3072d5037a17fd70719ff3e" +checksum = "b6fe4565b9518b83ef4f91bb47ce29620ca828bd32cb7e408f0062e9930ba190" dependencies = [ "bitflags", "errno", @@ -734,9 +658,9 @@ dependencies = [ [[package]] name = "rustversion" -version = "1.0.21" +version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a0d197bd2c9dc6e53b84da9556a69ba4cdfab8619eb41a8bd1cc2027a0f6b1d" +checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f" [[package]] name = "rusty-fork" @@ -750,12 +674,6 @@ dependencies = [ "wait-timeout", ] -[[package]] -name = "ryu" -version = "1.0.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" - [[package]] name = "same-file" version = "1.0.6" @@ -767,41 +685,58 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.219" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.228" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6" +checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.219" +version = "1.0.228" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00" +checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.118", ] [[package]] name = "serde_json" -version = "1.0.140" +version = "1.0.150" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373" +checksum = "e8014e44b4736ed0538adeecded0fce2a272f22dc9578a7eb6b2d9993c74cfb9" dependencies = [ "itoa", "memchr", - "ryu", "serde", + "serde_core", + "zmij", ] [[package]] -name = "strsim" -version = "0.11.1" +name = "shlex" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba" + +[[package]] +name = "slab" +version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" +checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" [[package]] name = "syn" @@ -816,9 +751,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.104" +version = "2.0.118" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17b6f705963418cdb9927482fa304bc562ece2fdd4f616084c50b7023b435a40" +checksum = "1b9ae57f904213ebb649ce6895b8a66c66f0203b9319718f69a5612a065b1422" dependencies = [ "proc-macro2", "quote", @@ -827,12 +762,12 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.23.0" +version = "3.27.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d31c77bdf42a745371d260a26ca7163f1e0924b64afa0b688e61b5a9fa02f16" +checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd" dependencies = [ "fastrand", - "getrandom", + "getrandom 0.4.3", "once_cell", "rustix", "windows-sys", @@ -840,22 +775,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "2.0.17" +version = "2.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f63587ca0f12b72a0600bcba1d40081f830876000bb46dd2337a3051618f4fc8" +checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "2.0.17" +version = "2.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ff15c8ecd7de3849db632e14d18d2571fa09dfc5ed93479bc4485c7a517c913" +checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.118", ] [[package]] @@ -876,15 +811,9 @@ checksum = "eaea85b334db583fe3274d12b4cd1880032beab409c0d774be044d4480ab9a94" [[package]] name = "unicode-ident" -version = "1.0.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" - -[[package]] -name = "utf8parse" -version = "0.2.2" +version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" +checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" [[package]] name = "wait-timeout" @@ -907,44 +836,37 @@ dependencies = [ [[package]] name = "wasi" -version = "0.14.2+wasi-0.2.4" +version = "0.11.1+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" + +[[package]] +name = "wasip2" +version = "1.0.4+wasi-0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9683f9a5a998d873c0d21fcbe3c083009670149a8fab228644b8bd36b2c48cb3" +checksum = "b67efb37e106e55ce722a510d6b5f9c17f083e5fc79afc2badeb12cc313d9487" dependencies = [ - "wit-bindgen-rt", + "wit-bindgen", ] [[package]] name = "wasm-bindgen" -version = "0.2.100" +version = "0.2.126" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1edc8929d7499fc4e8f0be2262a241556cfc54a0bea223790e71446f2aab1ef5" +checksum = "4b067c0c11094aef6b7a801c1e34a26affafdf3d051dba08456b868789aaf9a4" dependencies = [ "cfg-if", "once_cell", "rustversion", "wasm-bindgen-macro", -] - -[[package]] -name = "wasm-bindgen-backend" -version = "0.2.100" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f0a0651a5c2bc21487bde11ee802ccaf4c51935d0d3d42a6101f98161700bc6" -dependencies = [ - "bumpalo", - "log", - "proc-macro2", - "quote", - "syn 2.0.104", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-macro" -version = "0.2.100" +version = "0.2.126" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fe63fc6d09ed3792bd0897b314f53de8e16568c2b3f7982f468c0bf9bd0b407" +checksum = "167ce5e579f6bcf889c4f7175a8a5a585de84e8ff93976ce393efa5f2837aab1" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -952,143 +874,110 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.100" +version = "0.2.126" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de" +checksum = "f3997c7839262f4ef12cf90b818d6340c18e80f263f1a94bf157d0ec4420380e" dependencies = [ + "bumpalo", "proc-macro2", "quote", - "syn 2.0.104", - "wasm-bindgen-backend", + "syn 2.0.118", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.100" +version = "0.2.126" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a05d73b933a847d6cccdda8f838a22ff101ad9bf93e33684f39c1f5f0eece3d" +checksum = "dc1b4cb0cc549fcf58d7dfc081778139b3d283a081644e833e84682ad71cea24" dependencies = [ "unicode-ident", ] [[package]] name = "web-sys" -version = "0.3.77" +version = "0.3.103" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33b6dd2ef9186f1f2072e409e99cd22a975331a6b3591b12c764e0e55c60d5d2" +checksum = "8622dcb61c0bcc9fffa6938bed81210af2da9a7e4a1a834b2e37a59b6dfb6141" dependencies = [ "js-sys", "wasm-bindgen", ] [[package]] -name = "winapi-util" -version = "0.1.9" +name = "winapi" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" dependencies = [ - "windows-sys", + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", ] [[package]] -name = "windows-sys" -version = "0.59.0" +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" -dependencies = [ - "windows-targets", -] +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] -name = "windows-targets" -version = "0.52.6" +name = "winapi-util" +version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows-sys", ] [[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.6" +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] -name = "windows_x86_64_gnu" -version = "0.52.6" +name = "windows-link" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" [[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.6" +name = "windows-sys" +version = "0.61.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" +checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" +dependencies = [ + "windows-link", +] [[package]] -name = "windows_x86_64_msvc" -version = "0.52.6" +name = "wit-bindgen" +version = "0.57.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" - -[[package]] -name = "wit-bindgen-rt" -version = "0.39.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f42320e61fe2cfd34354ecb597f86f413484a798ba44a8ca1165c58d42da6c1" -dependencies = [ - "bitflags", -] +checksum = "1ebf944e87a7c253233ad6766e082e3cd714b5d03812acc24c318f549614536e" [[package]] name = "zerocopy" -version = "0.8.26" +version = "0.8.54" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1039dd0d3c310cf05de012d8a39ff557cb0d23087fd44cad61df08fc31907a2f" +checksum = "b7cbbc0a705a0fd05cc3676525980d2bf5a9bc4adac6d6475209a7887cf59d19" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.8.26" +version = "0.8.54" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ecf5b4cc5364572d7f4c329661bcc82724222973f2cab6f050a4e5c22f75181" +checksum = "e2e817b7b52d0c7358d3246da9d69935ebb18116b2b102b4230dac079b4862f5" dependencies = [ "proc-macro2", "quote", - "syn 2.0.104", + "syn 2.0.118", ] + +[[package]] +name = "zmij" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa" diff --git a/Cargo.toml b/Cargo.toml index 4a17feb..c1643f6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,14 +1,14 @@ [package] -name = "multibase" +name = "multi-base" version = "1.0.0" authors = ["Friedel Ziegelmayer ", "Dave Grantham "] edition = "2021" license = "MIT" readme = "README.md" description = "multibase in rust" -homepage = "https://github.com/multiformats/rust-multibase" -repository = "https://github.com/multiformats/rust-multibase" +repository = "https://github.com/cryptidtech/multi-base.git" keywords = ["ipld", "ipfs", "multihash", "cid", "no_std"] +categories = ["encoding"] [features] default = ["std"] @@ -16,20 +16,16 @@ std = ["data-encoding/std"] [dependencies] base-x = { version = "0.2.7", default-features = false } -base256emoji = "1.0.2" data-encoding = { version = "2.3.1", default-features = false, features = ["alloc"] } data-encoding-macro = "0.1.9" thiserror = { version = "2.0", default-features = false } [dev-dependencies] -criterion = "0.7" -rand = "0.9" +criterion = { version = "0.8", features = ["html_reports"] } proptest = "1.4" +rand = "0.8" [[bench]] name = "multibase" harness = false - -[workspace] -members = ["cli"] -exclude = ["fuzz"] +path = "benches/multibase.rs" \ No newline at end of file diff --git a/benches/multibase.rs b/benches/multibase.rs index 8c2c536..2b4ed71 100644 --- a/benches/multibase.rs +++ b/benches/multibase.rs @@ -3,12 +3,12 @@ use std::hint::black_box; use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion}; use rand::Rng; -use multibase::{decode, decode_into, encode, encode_into, encode_to_validated, Base}; +use multi_base::{decode, decode_into, encode, encode_into, encode_to_validated, Base}; fn bench_encode(c: &mut Criterion) { - let mut rng = rand::rng(); - let data_large: Vec = (0..1024).map(|_| rng.random()).collect(); - let data_small: Vec = (0..32).map(|_| rng.random()).collect(); + let mut rng = rand::thread_rng(); + let data_large: Vec = (0..1024).map(|_| rng.gen()).collect(); + let data_small: Vec = (0..32).map(|_| rng.gen()).collect(); let mut group = c.benchmark_group("encode"); @@ -50,8 +50,8 @@ fn bench_encode(c: &mut Criterion) { } fn bench_decode(c: &mut Criterion) { - let mut rng = rand::rng(); - let data: Vec = (0..1024).map(|_| rng.random::() as usize).collect(); + let mut rng = rand::thread_rng(); + let data: Vec = (0..1024).map(|_| rng.gen::() as usize).collect(); let base32 = b"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"; let base58 = b"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"; @@ -94,8 +94,8 @@ fn bench_decode(c: &mut Criterion) { // Benchmark zero-copy encode_into API fn bench_encode_into(c: &mut Criterion) { - let mut rng = rand::rng(); - let data: Vec = (0..1024).map(|_| rng.random()).collect(); + let mut rng = rand::thread_rng(); + let data: Vec = (0..1024).map(|_| rng.gen()).collect(); let mut group = c.benchmark_group("encode_into"); @@ -118,8 +118,8 @@ fn bench_encode_into(c: &mut Criterion) { // Benchmark zero-copy decode_into API fn bench_decode_into(c: &mut Criterion) { - let mut rng = rand::rng(); - let data: Vec = (0..1024).map(|_| rng.random()).collect(); + let mut rng = rand::thread_rng(); + let data: Vec = (0..1024).map(|_| rng.gen()).collect(); let encoded_base16 = encode(Base::Base16Lower, &data); let encoded_base32 = encode(Base::Base32Lower, &data); @@ -156,8 +156,8 @@ fn bench_decode_into(c: &mut Criterion) { // Benchmark roundtrip operations fn bench_roundtrip(c: &mut Criterion) { - let mut rng = rand::rng(); - let data: Vec = (0..256).map(|_| rng.random()).collect(); + let mut rng = rand::thread_rng(); + let data: Vec = (0..256).map(|_| rng.gen()).collect(); let mut group = c.benchmark_group("roundtrip"); @@ -185,13 +185,13 @@ fn bench_roundtrip(c: &mut Criterion) { // Benchmark various data sizes fn bench_data_sizes(c: &mut Criterion) { - let mut rng = rand::rng(); + let mut rng = rand::thread_rng(); let sizes = vec![0, 1, 16, 64, 256, 1024, 4096]; let mut group = c.benchmark_group("data_sizes"); for size in sizes { - let data: Vec = (0..size).map(|_| rng.random()).collect(); + let data: Vec = (0..size).map(|_| rng.gen()).collect(); group.bench_with_input(BenchmarkId::new("base64_encode", size), &data, |b, data| { b.iter(|| { @@ -205,8 +205,8 @@ fn bench_data_sizes(c: &mut Criterion) { // Benchmark all base types fn bench_all_bases(c: &mut Criterion) { - let mut rng = rand::rng(); - let data: Vec = (0..128).map(|_| rng.random()).collect(); + let mut rng = rand::thread_rng(); + let data: Vec = (0..128).map(|_| rng.gen()).collect(); let bases = vec![ Base::Base2, @@ -242,8 +242,8 @@ fn bench_all_bases(c: &mut Criterion) { // Benchmark EncodedString operations fn bench_encoded_string(c: &mut Criterion) { - let mut rng = rand::rng(); - let data: Vec = (0..256).map(|_| rng.random()).collect(); + let mut rng = rand::thread_rng(); + let data: Vec = (0..256).map(|_| rng.gen()).collect(); let mut group = c.benchmark_group("encoded_string"); @@ -258,7 +258,7 @@ fn bench_encoded_string(c: &mut Criterion) { let encoded_str = encode(Base::Base64, &data); group.bench_function("parse", |b| { b.iter(|| { - let _ = black_box(multibase::parse_encoded(black_box(&encoded_str)).unwrap()); + let _ = black_box(multi_base::parse_encoded(black_box(&encoded_str)).unwrap()); }) }); @@ -296,8 +296,8 @@ fn bench_base_from_code(c: &mut Criterion) { // Benchmark comparison: encode vs encode_into fn bench_encode_comparison(c: &mut Criterion) { - let mut rng = rand::rng(); - let data: Vec = (0..1024).map(|_| rng.random()).collect(); + let mut rng = rand::thread_rng(); + let data: Vec = (0..1024).map(|_| rng.gen()).collect(); let mut group = c.benchmark_group("encode_comparison"); diff --git a/src/base.rs b/src/base.rs index 282c7ab..5397234 100644 --- a/src/base.rs +++ b/src/base.rs @@ -118,6 +118,12 @@ macro_rules! build_base_enum { $( Self::$base => $crate::impls::$base::decode(input, strict), )* } } + + pub(crate) fn decode_into>(&self, input: I, strict: bool, buffer: &mut Vec) -> $crate::error::Result<()> { + match self { + $( Self::$base => $crate::impls::$base::decode_into(input, strict, buffer), )* + } + } } } } diff --git a/src/encoded.rs b/src/encoded.rs index 2bf76a9..b89b003 100644 --- a/src/encoded.rs +++ b/src/encoded.rs @@ -15,7 +15,7 @@ //! # Examples //! //! ``` -//! use multibase::{EncodedString, Base}; +//! use multi_base::{EncodedString, Base}; //! //! // Parse and validate a multibase string //! let encoded = EncodedString::new("zCn8eVZg").unwrap(); @@ -45,7 +45,7 @@ use crate::{Base, Error, Result}; /// Use [`EncodedString::new`] or parse from a string using [`core::str::FromStr`]: /// /// ``` -/// use multibase::EncodedString; +/// use multi_base::EncodedString; /// use std::str::FromStr; /// /// // Using new() @@ -82,7 +82,7 @@ impl EncodedString { /// # Examples /// /// ``` - /// use multibase::{EncodedString, Base}; + /// use multi_base::{EncodedString, Base}; /// /// // Valid multibase string /// let encoded = EncodedString::new("zCn8eVZg").unwrap(); @@ -115,7 +115,7 @@ impl EncodedString { /// # Examples /// /// ``` - /// use multibase::{EncodedString, Base}; + /// use multi_base::{EncodedString, Base}; /// /// let encoded = EncodedString::new("zCn8eVZg").unwrap(); /// assert_eq!(encoded.base(), Base::Base58Btc); @@ -132,7 +132,7 @@ impl EncodedString { /// # Examples /// /// ``` - /// use multibase::EncodedString; + /// use multi_base::EncodedString; /// /// let encoded = EncodedString::new("zCn8eVZg").unwrap(); /// assert_eq!(encoded.as_str(), "zCn8eVZg"); @@ -150,7 +150,7 @@ impl EncodedString { /// # Examples /// /// ``` - /// use multibase::EncodedString; + /// use multi_base::EncodedString; /// /// let encoded = EncodedString::new("zCn8eVZg").unwrap(); /// let decoded = encoded.decode().unwrap(); @@ -173,7 +173,7 @@ impl EncodedString { /// # Examples /// /// ``` - /// use multibase::EncodedString; + /// use multi_base::EncodedString; /// /// // Case-insensitive decoding for some bases /// let encoded = EncodedString::new("FaB").unwrap(); // Base16Upper with mixed case @@ -194,7 +194,7 @@ impl EncodedString { /// # Examples /// /// ``` - /// use multibase::EncodedString; + /// use multi_base::EncodedString; /// /// let encoded = EncodedString::new("zCn8eVZg").unwrap(); /// let inner = encoded.into_inner(); diff --git a/src/error.rs b/src/error.rs index 91569a1..00047ed 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,7 +1,7 @@ // SPDX-License-Identifier: MIT #[cfg(not(feature = "std"))] -use alloc::{format, string::String}; +use alloc::format; /// Type alias to use this library's [`Error`] type in a `Result`. pub type Result = core::result::Result; @@ -56,6 +56,7 @@ pub enum Error { /// The error message from data-encoding. #[cfg(feature = "std")] message: std::string::String, + /// The error message from data-encoding (no_std). #[cfg(not(feature = "std"))] message: alloc::string::String, }, @@ -112,12 +113,6 @@ impl From for Error { } } -impl From for Error { - fn from(_: base256emoji::DecodeError) -> Self { - Error::Base256EmojiDecode - } -} - impl From for Error { fn from(err: data_encoding::DecodeError) -> Self { #[cfg(feature = "std")] diff --git a/src/impls.rs b/src/impls.rs index f6ec847..62e07e1 100644 --- a/src/impls.rs +++ b/src/impls.rs @@ -2,10 +2,10 @@ use crate::encoding; use crate::error::Result; -use base256emoji::{Base, Emoji}; - #[cfg(not(feature = "std"))] use alloc::{string::String, vec::Vec}; +#[cfg(feature = "std")] +use std::{collections::HashMap, sync::OnceLock}; /// Generates BaseCodec implementations for data-encoding-based encodings. /// @@ -173,6 +173,14 @@ pub(crate) trait BaseCodec { /// Decode with the given string. fn decode>(input: I, strict: bool) -> Result>; + + /// Decode into an existing buffer. + fn decode_into>(input: I, strict: bool, buffer: &mut Vec) -> Result<()> { + let decoded = Self::decode(input, strict)?; + buffer.clear(); + buffer.extend_from_slice(&decoded); + Ok(()) + } } /// Identity, 8-bit binary (encoder and decoder keeps data unmodified). @@ -200,19 +208,126 @@ impl BaseCodec for Identity { fn decode>(input: I, _strict: bool) -> Result> { Ok(input.as_ref().as_bytes().to_vec()) } + + fn decode_into>(input: I, _strict: bool, buffer: &mut Vec) -> Result<()> { + buffer.clear(); + buffer.extend_from_slice(input.as_ref().as_bytes()); + Ok(()) + } } /// Base256Emoji (alphabet: ๐Ÿš€๐Ÿชโ˜„๐Ÿ›ฐ๐ŸŒŒ๐ŸŒ‘๐ŸŒ’๐ŸŒ“๐ŸŒ”๐ŸŒ•๐ŸŒ–๐ŸŒ—๐ŸŒ˜๐ŸŒ๐ŸŒ๐ŸŒŽ๐Ÿ‰โ˜€๐Ÿ’ป๐Ÿ–ฅ๐Ÿ’พ๐Ÿ’ฟ๐Ÿ˜‚โค๐Ÿ˜๐Ÿคฃ๐Ÿ˜Š๐Ÿ™๐Ÿ’•๐Ÿ˜ญ๐Ÿ˜˜๐Ÿ‘๐Ÿ˜…๐Ÿ‘๐Ÿ˜๐Ÿ”ฅ๐Ÿฅฐ๐Ÿ’”๐Ÿ’–๐Ÿ’™๐Ÿ˜ข๐Ÿค”๐Ÿ˜†๐Ÿ™„๐Ÿ’ช๐Ÿ˜‰โ˜บ๐Ÿ‘Œ๐Ÿค—๐Ÿ’œ๐Ÿ˜”๐Ÿ˜Ž๐Ÿ˜‡๐ŸŒน๐Ÿคฆ๐ŸŽ‰๐Ÿ’žโœŒโœจ๐Ÿคท๐Ÿ˜ฑ๐Ÿ˜Œ๐ŸŒธ๐Ÿ™Œ๐Ÿ˜‹๐Ÿ’—๐Ÿ’š๐Ÿ˜๐Ÿ’›๐Ÿ™‚๐Ÿ’“๐Ÿคฉ๐Ÿ˜„๐Ÿ˜€๐Ÿ–ค๐Ÿ˜ƒ๐Ÿ’ฏ๐Ÿ™ˆ๐Ÿ‘‡๐ŸŽถ๐Ÿ˜’๐Ÿคญโฃ๐Ÿ˜œ๐Ÿ’‹๐Ÿ‘€๐Ÿ˜ช๐Ÿ˜‘๐Ÿ’ฅ๐Ÿ™‹๐Ÿ˜ž๐Ÿ˜ฉ๐Ÿ˜ก๐Ÿคช๐Ÿ‘Š๐Ÿฅณ๐Ÿ˜ฅ๐Ÿคค๐Ÿ‘‰๐Ÿ’ƒ๐Ÿ˜ณโœ‹๐Ÿ˜š๐Ÿ˜๐Ÿ˜ด๐ŸŒŸ๐Ÿ˜ฌ๐Ÿ™ƒ๐Ÿ€๐ŸŒท๐Ÿ˜ป๐Ÿ˜“โญโœ…๐Ÿฅบ๐ŸŒˆ๐Ÿ˜ˆ๐Ÿค˜๐Ÿ’ฆโœ”๐Ÿ˜ฃ๐Ÿƒ๐Ÿ’โ˜น๐ŸŽŠ๐Ÿ’˜๐Ÿ˜ โ˜๐Ÿ˜•๐ŸŒบ๐ŸŽ‚๐ŸŒป๐Ÿ˜๐Ÿ–•๐Ÿ’๐Ÿ™Š๐Ÿ˜น๐Ÿ—ฃ๐Ÿ’ซ๐Ÿ’€๐Ÿ‘‘๐ŸŽต๐Ÿคž๐Ÿ˜›๐Ÿ”ด๐Ÿ˜ค๐ŸŒผ๐Ÿ˜ซโšฝ๐Ÿค™โ˜•๐Ÿ†๐Ÿคซ๐Ÿ‘ˆ๐Ÿ˜ฎ๐Ÿ™†๐Ÿป๐Ÿƒ๐Ÿถ๐Ÿ’๐Ÿ˜ฒ๐ŸŒฟ๐Ÿงก๐ŸŽโšก๐ŸŒž๐ŸŽˆโŒโœŠ๐Ÿ‘‹๐Ÿ˜ฐ๐Ÿคจ๐Ÿ˜ถ๐Ÿค๐Ÿšถ๐Ÿ’ฐ๐Ÿ“๐Ÿ’ข๐ŸคŸ๐Ÿ™๐Ÿšจ๐Ÿ’จ๐Ÿคฌโœˆ๐ŸŽ€๐Ÿบ๐Ÿค“๐Ÿ˜™๐Ÿ’Ÿ๐ŸŒฑ๐Ÿ˜–๐Ÿ‘ถ๐Ÿฅดโ–ถโžกโ“๐Ÿ’Ž๐Ÿ’ธโฌ‡๐Ÿ˜จ๐ŸŒš๐Ÿฆ‹๐Ÿ˜ท๐Ÿ•บโš ๐Ÿ™…๐Ÿ˜Ÿ๐Ÿ˜ต๐Ÿ‘Ž๐Ÿคฒ๐Ÿค ๐Ÿคง๐Ÿ“Œ๐Ÿ”ต๐Ÿ’…๐Ÿง๐Ÿพ๐Ÿ’๐Ÿ˜—๐Ÿค‘๐ŸŒŠ๐Ÿคฏ๐Ÿทโ˜Ž๐Ÿ’ง๐Ÿ˜ฏ๐Ÿ’†๐Ÿ‘†๐ŸŽค๐Ÿ™‡๐Ÿ‘โ„๐ŸŒด๐Ÿ’ฃ๐Ÿธ๐Ÿ’Œ๐Ÿ“๐Ÿฅ€๐Ÿคข๐Ÿ‘…๐Ÿ’ก๐Ÿ’ฉ๐Ÿ‘๐Ÿ“ธ๐Ÿ‘ป๐Ÿค๐Ÿคฎ๐ŸŽผ๐Ÿฅต๐Ÿšฉ๐ŸŽ๐ŸŠ๐Ÿ‘ผ๐Ÿ’๐Ÿ“ฃ๐Ÿฅ‚) #[derive(PartialEq, Eq, Clone, Copy, Debug)] pub(crate) struct Base256Emoji; +const EMOJI_ALPHABET: &str = "๐Ÿš€๐Ÿชโ˜„๐Ÿ›ฐ๐ŸŒŒ๐ŸŒ‘๐ŸŒ’๐ŸŒ“๐ŸŒ”๐ŸŒ•๐ŸŒ–๐ŸŒ—๐ŸŒ˜๐ŸŒ๐ŸŒ๐ŸŒŽ๐Ÿ‰โ˜€๐Ÿ’ป๐Ÿ–ฅ๐Ÿ’พ๐Ÿ’ฟ๐Ÿ˜‚โค๐Ÿ˜๐Ÿคฃ๐Ÿ˜Š๐Ÿ™๐Ÿ’•๐Ÿ˜ญ๐Ÿ˜˜๐Ÿ‘๐Ÿ˜…๐Ÿ‘๐Ÿ˜๐Ÿ”ฅ๐Ÿฅฐ๐Ÿ’”๐Ÿ’–๐Ÿ’™๐Ÿ˜ข๐Ÿค”๐Ÿ˜†๐Ÿ™„๐Ÿ’ช๐Ÿ˜‰โ˜บ๐Ÿ‘Œ๐Ÿค—๐Ÿ’œ๐Ÿ˜”๐Ÿ˜Ž๐Ÿ˜‡๐ŸŒน๐Ÿคฆ๐ŸŽ‰๐Ÿ’žโœŒโœจ๐Ÿคท๐Ÿ˜ฑ๐Ÿ˜Œ๐ŸŒธ๐Ÿ™Œ๐Ÿ˜‹๐Ÿ’—๐Ÿ’š๐Ÿ˜๐Ÿ’›๐Ÿ™‚๐Ÿ’“๐Ÿคฉ๐Ÿ˜„๐Ÿ˜€๐Ÿ–ค๐Ÿ˜ƒ๐Ÿ’ฏ๐Ÿ™ˆ๐Ÿ‘‡๐ŸŽถ๐Ÿ˜’๐Ÿคญโฃ๐Ÿ˜œ๐Ÿ’‹๐Ÿ‘€๐Ÿ˜ช๐Ÿ˜‘๐Ÿ’ฅ๐Ÿ™‹๐Ÿ˜ž๐Ÿ˜ฉ๐Ÿ˜ก๐Ÿคช๐Ÿ‘Š๐Ÿฅณ๐Ÿ˜ฅ๐Ÿคค๐Ÿ‘‰๐Ÿ’ƒ๐Ÿ˜ณโœ‹๐Ÿ˜š๐Ÿ˜๐Ÿ˜ด๐ŸŒŸ๐Ÿ˜ฌ๐Ÿ™ƒ๐Ÿ€๐ŸŒท๐Ÿ˜ป๐Ÿ˜“โญโœ…๐Ÿฅบ๐ŸŒˆ๐Ÿ˜ˆ๐Ÿค˜๐Ÿ’ฆโœ”๐Ÿ˜ฃ๐Ÿƒ๐Ÿ’โ˜น๐ŸŽŠ๐Ÿ’˜๐Ÿ˜ โ˜๐Ÿ˜•๐ŸŒบ๐ŸŽ‚๐ŸŒป๐Ÿ˜๐Ÿ–•๐Ÿ’๐Ÿ™Š๐Ÿ˜น๐Ÿ—ฃ๐Ÿ’ซ๐Ÿ’€๐Ÿ‘‘๐ŸŽต๐Ÿคž๐Ÿ˜›๐Ÿ”ด๐Ÿ˜ค๐ŸŒผ๐Ÿ˜ซโšฝ๐Ÿค™โ˜•๐Ÿ†๐Ÿคซ๐Ÿ‘ˆ๐Ÿ˜ฎ๐Ÿ™†๐Ÿป๐Ÿƒ๐Ÿถ๐Ÿ’๐Ÿ˜ฒ๐ŸŒฟ๐Ÿงก๐ŸŽโšก๐ŸŒž๐ŸŽˆโŒโœŠ๐Ÿ‘‹๐Ÿ˜ฐ๐Ÿคจ๐Ÿ˜ถ๐Ÿค๐Ÿšถ๐Ÿ’ฐ๐Ÿ“๐Ÿ’ข๐ŸคŸ๐Ÿ™๐Ÿšจ๐Ÿ’จ๐Ÿคฌโœˆ๐ŸŽ€๐Ÿบ๐Ÿค“๐Ÿ˜™๐Ÿ’Ÿ๐ŸŒฑ๐Ÿ˜–๐Ÿ‘ถ๐Ÿฅดโ–ถโžกโ“๐Ÿ’Ž๐Ÿ’ธโฌ‡๐Ÿ˜จ๐ŸŒš๐Ÿฆ‹๐Ÿ˜ท๐Ÿ•บโš ๐Ÿ™…๐Ÿ˜Ÿ๐Ÿ˜ต๐Ÿ‘Ž๐Ÿคฒ๐Ÿค ๐Ÿคง๐Ÿ“Œ๐Ÿ”ต๐Ÿ’…๐Ÿง๐Ÿพ๐Ÿ’๐Ÿ˜—๐Ÿค‘๐ŸŒŠ๐Ÿคฏ๐Ÿทโ˜Ž๐Ÿ’ง๐Ÿ˜ฏ๐Ÿ’†๐Ÿ‘†๐ŸŽค๐Ÿ™‡๐Ÿ‘โ„๐ŸŒด๐Ÿ’ฃ๐Ÿธ๐Ÿ’Œ๐Ÿ“๐Ÿฅ€๐Ÿคข๐Ÿ‘…๐Ÿ’ก๐Ÿ’ฉ๐Ÿ‘๐Ÿ“ธ๐Ÿ‘ป๐Ÿค๐Ÿคฎ๐ŸŽผ๐Ÿฅต๐Ÿšฉ๐ŸŽ๐ŸŠ๐Ÿ‘ผ๐Ÿ’๐Ÿ“ฃ๐Ÿฅ‚"; + +#[cfg(feature = "std")] +fn emoji_chars() -> &'static [char] { + static CHARS: OnceLock> = OnceLock::new(); + CHARS + .get_or_init(|| EMOJI_ALPHABET.chars().collect()) + .as_slice() +} + +#[cfg(feature = "std")] +fn emoji_decode_map() -> &'static HashMap { + static MAP: OnceLock> = OnceLock::new(); + MAP.get_or_init(|| { + EMOJI_ALPHABET + .chars() + .enumerate() + .map(|(index, c)| (c, index as u8)) + .collect() + }) +} + impl BaseCodec for Base256Emoji { fn encode>(input: I) -> String { - Emoji::encode(input.as_ref()) + #[cfg(feature = "std")] + { + let chars = emoji_chars(); + input.as_ref().iter().map(|&b| chars[b as usize]).collect() + } + + #[cfg(not(feature = "std"))] + { + let chars: Vec = EMOJI_ALPHABET.chars().collect(); + input.as_ref().iter().map(|&b| chars[b as usize]).collect() + } } fn decode>(input: I, _strict: bool) -> Result> { - Emoji::decode(input.as_ref()).map_err(|e| e.into()) + #[cfg(feature = "std")] + { + let map = emoji_decode_map(); + input + .as_ref() + .chars() + .map(|c| { + map.get(&c) + .copied() + .ok_or(crate::error::Error::Base256EmojiDecode) + }) + .collect() + } + + #[cfg(not(feature = "std"))] + { + input + .as_ref() + .chars() + .map(|c| { + EMOJI_ALPHABET + .chars() + .position(|a| a == c) + .map(|i| i as u8) + .ok_or(crate::error::Error::Base256EmojiDecode) + }) + .collect() + } + } + + fn decode_into>(input: I, _strict: bool, buffer: &mut Vec) -> Result<()> { + #[cfg(feature = "std")] + { + let map = emoji_decode_map(); + let input = input.as_ref(); + let len = input.chars().count(); + for c in input.chars() { + if !map.contains_key(&c) { + return Err(crate::error::Error::Base256EmojiDecode); + } + } + + buffer.clear(); + buffer.reserve(len); + buffer.extend(input.chars().map(|c| map[&c])); + Ok(()) + } + + #[cfg(not(feature = "std"))] + { + let input = input.as_ref(); + let len = input.chars().count(); + for c in input.chars() { + if !EMOJI_ALPHABET.chars().any(|a| a == c) { + return Err(crate::error::Error::Base256EmojiDecode); + } + } + + buffer.clear(); + buffer.reserve(len); + for c in input.chars() { + let byte = EMOJI_ALPHABET + .chars() + .position(|a| a == c) + .map(|i| i as u8) + .expect("emoji was already validated"); + buffer.push(byte); + } + Ok(()) + } } } diff --git a/src/lib.rs b/src/lib.rs index be2bdaf..e6b13a2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -28,7 +28,7 @@ pub use self::error::{Error, Result}; /// # Examples /// /// ``` -/// use multibase::{Base, decode}; +/// use multi_base::{Base, decode}; /// /// assert_eq!( /// decode("zCn8eVZg", true).unwrap(), @@ -48,7 +48,7 @@ pub fn decode>(input: T, strict: bool) -> Result<(Base, Vec)> /// # Examples /// /// ``` -/// use multibase::{Base, encode}; +/// use multi_base::{Base, encode}; /// /// assert_eq!(encode(Base::Base58Btc, b"hello"), "zCn8eVZg"); /// ``` @@ -82,7 +82,7 @@ pub fn encode>(base: Base, input: T) -> String { /// # Examples /// /// ``` -/// use multibase::{Base, encode_into}; +/// use multi_base::{Base, encode_into}; /// /// let mut buffer = String::new(); /// @@ -122,7 +122,7 @@ pub fn encode_into>(base: Base, input: T, buffer: &mut String) { /// # Examples /// /// ``` -/// use multibase::{Base, decode_into}; +/// use multi_base::{Base, decode_into}; /// /// let mut buffer = Vec::new(); /// @@ -152,11 +152,7 @@ pub fn decode_into>(input: T, strict: bool, buffer: &mut Vec) let input = input.as_ref(); let code = input.chars().next().ok_or(Error::EmptyInput)?; let base = Base::from_code(code)?; - let decoded = base.decode(&input[code.len_utf8()..], strict)?; - - // Clear and fill buffer with decoded data - buffer.clear(); - buffer.extend_from_slice(&decoded); + base.decode_into(&input[code.len_utf8()..], strict, buffer)?; Ok(base) } @@ -168,7 +164,7 @@ pub fn decode_into>(input: T, strict: bool, buffer: &mut Vec) /// # Examples /// /// ``` -/// use multibase::{Base, encode_to_validated}; +/// use multi_base::{Base, encode_to_validated}; /// /// let encoded = encode_to_validated(Base::Base58Btc, b"hello"); /// assert_eq!(encoded.base(), Base::Base58Btc); @@ -198,7 +194,7 @@ pub fn encode_to_validated>(base: Base, input: T) -> EncodedStrin /// # Examples /// /// ``` -/// use multibase::{Base, parse_encoded}; +/// use multi_base::{Base, parse_encoded}; /// /// let encoded = parse_encoded("zCn8eVZg").unwrap(); /// assert_eq!(encoded.base(), Base::Base58Btc); diff --git a/tests/lib.rs b/tests/lib.rs index 4d93606..29337fe 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -1,4 +1,4 @@ -use multibase::{decode, decode_into, encode, Base, Base::*}; +use multi_base::{decode, decode_into, encode, Base, Base::*}; fn encode_decode_assert(input: &[u8], test_cases: Vec<(Base, &str)>) { for (base, output) in test_cases { @@ -200,7 +200,7 @@ fn identity_roundtrip_valid_utf8() { /// Test that decoding an empty string returns EmptyInput error. #[test] fn decode_empty_string_error() { - use multibase::Error; + use multi_base::Error; let result = decode("", true); assert!(result.is_err()); @@ -214,7 +214,7 @@ fn decode_empty_string_error() { /// Test that unknown base codes return UnknownBase error. #[test] fn decode_unknown_base_error() { - use multibase::Error; + use multi_base::Error; let test_cases = vec![ "xInvalidBase", // 'x' is not a valid base code @@ -242,7 +242,7 @@ fn decode_unknown_base_error() { /// Test that Base::from_code returns proper error for invalid codes. #[test] fn base_from_code_error() { - use multibase::Error; + use multi_base::Error; let invalid_codes = vec!['x', '!', '@', '#', '$', '%']; @@ -292,7 +292,7 @@ fn decode_malformed_data_errors() { /// Test that error types implement expected traits. #[test] fn error_traits() { - use multibase::Error; + use multi_base::Error; let error = Error::EmptyInput; @@ -360,7 +360,7 @@ fn identity_binary_data_lossy() { /// Test encode_into with buffer reuse. #[test] fn test_encode_into_buffer_reuse() { - use multibase::encode_into; + use multi_base::encode_into; let mut buffer = String::new(); @@ -380,7 +380,7 @@ fn test_encode_into_buffer_reuse() { /// Test encode_into with all base types. #[test] fn test_encode_into_all_bases() { - use multibase::encode_into; + use multi_base::encode_into; let input = b"test data"; let mut buffer = String::new(); @@ -410,7 +410,7 @@ fn test_encode_into_all_bases() { /// Test decode_into with buffer reuse. #[test] fn test_decode_into_buffer_reuse() { - use multibase::decode_into; + use multi_base::decode_into; let mut buffer = Vec::new(); @@ -433,7 +433,7 @@ fn test_decode_into_buffer_reuse() { /// Test that encode_into produces same results as encode. #[test] fn test_encode_into_matches_encode() { - use multibase::encode_into; + use multi_base::encode_into; let test_data = vec![ b"".as_slice(), @@ -498,7 +498,7 @@ fn test_decode_into_matches_decode() { /// Test decode_into error handling. #[test] fn test_decode_into_errors() { - use multibase::{decode_into, Error}; + use multi_base::{decode_into, Error}; let mut buffer = Vec::new(); @@ -516,7 +516,7 @@ fn test_decode_into_errors() { /// Test encode_into with empty input. #[test] fn test_encode_into_empty() { - use multibase::encode_into; + use multi_base::encode_into; let mut buffer = String::new(); encode_into(Base64, b"", &mut buffer); @@ -526,7 +526,7 @@ fn test_encode_into_empty() { /// Test decode_into with empty data (just code). #[test] fn test_decode_into_empty_data() { - use multibase::decode_into; + use multi_base::decode_into; let mut buffer = Vec::new(); let base = decode_into("m", true, &mut buffer).unwrap(); @@ -537,7 +537,7 @@ fn test_decode_into_empty_data() { /// Test encode_into doesn't grow buffer unnecessarily. #[test] fn test_encode_into_buffer_capacity() { - use multibase::encode_into; + use multi_base::encode_into; let mut buffer = String::with_capacity(1000); let initial_capacity = buffer.capacity(); @@ -552,7 +552,7 @@ fn test_encode_into_buffer_capacity() { /// Test decode_into buffer reuse in loop (performance test). #[test] fn test_decode_into_loop_performance() { - use multibase::decode_into; + use multi_base::decode_into; let inputs = vec!["zCn8eVZg", "md29ybGQ", "f72757374", "BPFSXGIDNMFXGSIBB"]; @@ -572,7 +572,7 @@ fn test_decode_into_loop_performance() { /// Test EncodedString basic usage. #[test] fn test_encoded_string_basic() { - use multibase::EncodedString; + use multi_base::EncodedString; let encoded = EncodedString::new("zCn8eVZg").unwrap(); assert_eq!(encoded.base(), Base58Btc); @@ -585,7 +585,7 @@ fn test_encoded_string_basic() { /// Test EncodedString FromStr implementation. #[test] fn test_encoded_string_from_str() { - use multibase::EncodedString; + use multi_base::EncodedString; use std::str::FromStr; let encoded = EncodedString::from_str("md29ybGQ").unwrap(); @@ -598,7 +598,7 @@ fn test_encoded_string_from_str() { /// Test EncodedString TryFrom implementations. #[test] fn test_encoded_string_try_from() { - use multibase::EncodedString; + use multi_base::EncodedString; use std::convert::TryFrom; // From String @@ -613,7 +613,7 @@ fn test_encoded_string_try_from() { /// Test EncodedString error handling. #[test] fn test_encoded_string_errors() { - use multibase::{EncodedString, Error}; + use multi_base::{EncodedString, Error}; // Empty string let result = EncodedString::new(""); @@ -629,7 +629,7 @@ fn test_encoded_string_errors() { /// Test EncodedString validation only checks prefix. #[test] fn test_encoded_string_validates_prefix_only() { - use multibase::EncodedString; + use multi_base::EncodedString; // This has a valid base code but invalid data // Construction should succeed, but decode should fail @@ -644,7 +644,7 @@ fn test_encoded_string_validates_prefix_only() { /// Test encode_to_validated convenience function. #[test] fn test_encode_to_validated() { - use multibase::encode_to_validated; + use multi_base::encode_to_validated; let encoded = encode_to_validated(Base58Btc, b"hello"); assert_eq!(encoded.base(), Base58Btc); @@ -657,7 +657,7 @@ fn test_encode_to_validated() { /// Test parse_encoded convenience function. #[test] fn test_parse_encoded() { - use multibase::parse_encoded; + use multi_base::parse_encoded; let encoded = parse_encoded("zCn8eVZg").unwrap(); assert_eq!(encoded.base(), Base58Btc); @@ -669,7 +669,7 @@ fn test_parse_encoded() { /// Test EncodedString with all base types. #[test] fn test_encoded_string_all_bases() { - use multibase::{encode_to_validated, EncodedString}; + use multi_base::{encode_to_validated, EncodedString}; let data = b"test"; let bases = vec![Base16Lower, Base32Lower, Base58Btc, Base64]; @@ -692,7 +692,7 @@ fn test_encoded_string_all_bases() { /// Test EncodedString Display trait. #[test] fn test_encoded_string_display() { - use multibase::EncodedString; + use multi_base::EncodedString; let encoded = EncodedString::new("zCn8eVZg").unwrap(); assert_eq!(format!("{}", encoded), "zCn8eVZg"); @@ -701,7 +701,7 @@ fn test_encoded_string_display() { /// Test EncodedString into_inner. #[test] fn test_encoded_string_into_inner() { - use multibase::EncodedString; + use multi_base::EncodedString; let encoded = EncodedString::new("zCn8eVZg").unwrap(); let inner = encoded.into_inner(); @@ -711,7 +711,7 @@ fn test_encoded_string_into_inner() { /// Test EncodedString clone and equality. #[test] fn test_encoded_string_clone_eq() { - use multibase::EncodedString; + use multi_base::EncodedString; let encoded1 = EncodedString::new("zCn8eVZg").unwrap(); let encoded2 = encoded1.clone(); @@ -724,7 +724,7 @@ fn test_encoded_string_clone_eq() { /// Test EncodedString decode_with_strictness. #[test] fn test_encoded_string_strictness() { - use multibase::EncodedString; + use multi_base::EncodedString; // Mixed case Base16Upper (should work in permissive mode) let encoded = EncodedString::new("FaB").unwrap(); @@ -1054,7 +1054,7 @@ fn test_strict_vs_permissive_mode() { /// Test error messages contain useful information. #[test] fn test_error_messages_are_descriptive() { - use multibase::Error; + use multi_base::Error; // UnknownBase error should contain the invalid code let result = decode("xInvalid", true); @@ -1083,7 +1083,7 @@ fn test_error_messages_are_descriptive() { /// Test that all error types are properly constructed. #[test] fn test_all_error_variants() { - use multibase::Error; + use multi_base::Error; // EmptyInput let err = Error::EmptyInput; @@ -1209,7 +1209,7 @@ fn test_concurrent_decoding() { /// Test concurrent encoding with buffer reuse (encode_into). #[test] fn test_concurrent_encode_into() { - use multibase::encode_into; + use multi_base::encode_into; use std::thread; let test_data = vec![ @@ -1242,7 +1242,7 @@ fn test_concurrent_encode_into() { /// Test concurrent decoding with buffer reuse (decode_into). #[test] fn test_concurrent_decode_into() { - use multibase::decode_into; + use multi_base::decode_into; use std::thread; let test_cases = vec![ @@ -1308,7 +1308,7 @@ fn test_many_concurrent_operations() { /// Test that EncodedString is Send and Sync. #[test] fn test_encoded_string_is_send_sync() { - use multibase::EncodedString; + use multi_base::EncodedString; use std::thread; let encoded = EncodedString::new("zCn8eVZg").unwrap(); @@ -1325,7 +1325,7 @@ fn test_encoded_string_is_send_sync() { /// Test that EncodedString can be shared across threads via Arc. #[test] fn test_encoded_string_shared_across_threads() { - use multibase::EncodedString; + use multi_base::EncodedString; use std::sync::Arc; use std::thread; diff --git a/tests/properties.rs b/tests/properties.rs index fb89271..4514147 100644 --- a/tests/properties.rs +++ b/tests/properties.rs @@ -3,7 +3,7 @@ // These tests verify invariants that should hold for all inputs, // using randomly generated test data. -use multibase::{decode, decode_into, encode, encode_into, Base}; +use multi_base::{decode, decode_into, encode, encode_into, Base}; use proptest::prelude::*; // Configure proptest to run fewer cases for faster tests @@ -211,7 +211,7 @@ proptest! { /// Property: EncodedString validation and decoding consistency #[test] fn prop_encoded_string_consistency(data: Vec, base_idx: usize) { - use multibase::{encode_to_validated, parse_encoded}; + use multi_base::{encode_to_validated, parse_encoded}; let bases = all_bases(); if bases.is_empty() { diff --git a/tests/security.rs b/tests/security.rs index 71e5303..093d223 100644 --- a/tests/security.rs +++ b/tests/security.rs @@ -5,7 +5,7 @@ //! These tests verify that the library handles potentially malicious or //! adversarial inputs safely without panicking or exhibiting undefined behavior. -use multibase::{decode, decode_into, encode, encode_into, Base}; +use multi_base::{decode, decode_into, encode, encode_into, Base}; /// Tests that very large inputs don't cause panics or undefined behavior. #[test] @@ -288,7 +288,7 @@ fn test_all_error_paths() { /// Tests that EncodedString validation is secure. #[test] fn test_encoded_string_security() { - use multibase::EncodedString; + use multi_base::EncodedString; // Valid string let valid = EncodedString::new("zCn8eVZg").unwrap(); diff --git a/tests/thread_safety.rs b/tests/thread_safety.rs index 0bcfb15..549a2ac 100644 --- a/tests/thread_safety.rs +++ b/tests/thread_safety.rs @@ -6,7 +6,7 @@ //! public types are properly Send and Sync, and that concurrent operations //! are safe and correct. -use multibase::{Base, EncodedString, Error}; +use multi_base::{Base, EncodedString, Error}; /// Compile-time assertion that a type implements Send. fn assert_send() {} @@ -173,7 +173,7 @@ fn concurrent_encoding_correctness() { for _ in 0..10 { let data = Arc::clone(&test_data); let handle = thread::spawn(move || { - let encoded = multibase::encode(Base::Base64, &*data); + let encoded = multi_base::encode(Base::Base64, &*data); assert!(encoded.starts_with('m')); encoded }); @@ -200,7 +200,7 @@ fn concurrent_decoding_correctness() { for _ in 0..10 { let enc = Arc::clone(&encoded); let handle = thread::spawn(move || { - let (base, decoded) = multibase::decode(&*enc, true).unwrap(); + let (base, decoded) = multi_base::decode(&*enc, true).unwrap(); assert_eq!(base, Base::Base58Btc); decoded }); @@ -252,7 +252,7 @@ fn concurrent_encode_into_thread_local_buffers() { // Each thread has its own buffer let mut buffer = String::new(); for _ in 0..100 { - multibase::encode_into(Base::Base64, &*data, &mut buffer); + multi_base::encode_into(Base::Base64, &*data, &mut buffer); assert!(buffer.starts_with('m')); } i @@ -280,7 +280,7 @@ fn concurrent_decode_into_thread_local_buffers() { // Each thread has its own buffer let mut buffer = Vec::new(); for _ in 0..100 { - let base = multibase::decode_into(&*enc, true, &mut buffer).unwrap(); + let base = multi_base::decode_into(&*enc, true, &mut buffer).unwrap(); assert_eq!(base, Base::Base64); assert_eq!(buffer, b"world"); } @@ -315,8 +315,8 @@ fn concurrent_multi_base_operations() { for base in bases { let handle = thread::spawn(move || { let data = b"concurrent test data"; - let encoded = multibase::encode(base, data); - let (decoded_base, decoded) = multibase::decode(&encoded, true).unwrap(); + let encoded = multi_base::encode(base, data); + let (decoded_base, decoded) = multi_base::decode(&encoded, true).unwrap(); assert_eq!(decoded_base, base); assert_eq!(&decoded[..], data); }); @@ -398,7 +398,7 @@ fn concurrent_error_handling() { for input in invalid_inputs { let handle = thread::spawn(move || { - let result = multibase::decode(input, true); + let result = multi_base::decode(input, true); assert!(result.is_err()); }); handles.push(handle); @@ -425,8 +425,8 @@ fn stress_test_concurrent_operations() { let handle = thread::spawn(move || { for i in 0..100 { let data = format!("data{}", i); - let encoded = multibase::encode(Base::Base64, data.as_bytes()); - let (base, decoded) = multibase::decode(&encoded, true).unwrap(); + let encoded = multi_base::encode(Base::Base64, data.as_bytes()); + let (base, decoded) = multi_base::decode(&encoded, true).unwrap(); assert_eq!(base, Base::Base64); assert_eq!(decoded, data.as_bytes()); c.fetch_add(1, Ordering::SeqCst); From f0e0e47ef715a367b3538da0c10ab8a68216d7a7 Mon Sep 17 00:00:00 2001 From: Dave Grantham Date: Mon, 13 Jul 2026 14:05:14 -0600 Subject: [PATCH 2/2] update Cargo.lock Signed-off-by: Dave Grantham --- Cargo.lock | 73 +++++++++++++++++++++++------------------------------- 1 file changed, 31 insertions(+), 42 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 62fcbe2..c200e37 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -34,9 +34,9 @@ checksum = "940b3a0ca603d1eade50a4846a2afffd5ef57a9feac2c0e2ec2e14f9ead76000" [[package]] name = "autocfg" -version = "1.5.0" +version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" +checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53" [[package]] name = "base-x" @@ -182,9 +182,9 @@ dependencies = [ [[package]] name = "crossbeam-deque" -version = "0.8.6" +version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9dd111b7b7f7d55b72c0a6ae361660ee5853c9af73f70c3c2ef6858b950e2e51" +checksum = "5181e0de7b61eb03a81e347d6dd8797bae9da5146707b51077e2d71a54ec0ceb" dependencies = [ "crossbeam-epoch", "crossbeam-utils", @@ -192,18 +192,18 @@ dependencies = [ [[package]] name = "crossbeam-epoch" -version = "0.9.18" +version = "0.9.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" +checksum = "2d6914041f254d6e9176c01941b21115dcfb7089e55135a35411081bd106ef3f" dependencies = [ "crossbeam-utils", ] [[package]] name = "crossbeam-utils" -version = "0.8.21" +version = "0.8.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" +checksum = "61803da095bee82a81bb1a452ecc25d3b2f1416d1897eb86430c6159ef717c17" [[package]] name = "crunchy" @@ -234,14 +234,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ccc2776f0c61eca1ca32528f85548abd1a4be8fb53d1b21c013e4f18da1e7090" dependencies = [ "data-encoding", - "syn 1.0.109", + "syn", ] [[package]] name = "either" -version = "1.15.0" +version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" +checksum = "91622ff5e7162018101f2fea40d6ebf4a78bbe5a49736a2020649edf9693679e" [[package]] name = "errno" @@ -255,9 +255,9 @@ dependencies = [ [[package]] name = "fastrand" -version = "2.3.0" +version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" +checksum = "9f1f227452a390804cdb637b74a86990f2a7d7ba4b7d5693aac9b4dd6defd8d6" [[package]] name = "find-msvc-tools" @@ -408,9 +408,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.21.3" +version = "1.21.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" +checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" [[package]] name = "oorandom" @@ -490,7 +490,7 @@ dependencies = [ "bit-vec", "bitflags", "num-traits", - "rand 0.9.4", + "rand 0.9.5", "rand_chacha 0.9.0", "rand_xorshift", "regex-syntax", @@ -539,12 +539,12 @@ dependencies = [ [[package]] name = "rand" -version = "0.9.4" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44c5af06bb1b7d3216d91932aed5265164bf384dc89cd6ba05cf59a35f5f76ea" +checksum = "b9ef1d0d795eb7d84685bca4f72f3649f064e6641543d3a8c415898726a57b41" dependencies = [ "rand_chacha 0.9.0", - "rand_core 0.9.3", + "rand_core 0.9.5", ] [[package]] @@ -564,7 +564,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" dependencies = [ "ppv-lite86", - "rand_core 0.9.3", + "rand_core 0.9.5", ] [[package]] @@ -578,9 +578,9 @@ dependencies = [ [[package]] name = "rand_core" -version = "0.9.3" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38" +checksum = "76afc826de14238e6e8c374ddcc1fa19e374fd8dd986b0d2af0d02377261d83c" dependencies = [ "getrandom 0.3.4", ] @@ -591,7 +591,7 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "513962919efc330f829edb2535844d1b912b0fbe2ca165d613e4e8788bb05a5a" dependencies = [ - "rand_core 0.9.3", + "rand_core 0.9.5", ] [[package]] @@ -616,9 +616,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.12.4" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1292b7759ae1cb9ec195452d1390a074f0cd8541ab7a5a8c31cd6db45d4a6ba" +checksum = "2a0e75113e14dc5acb068cd0786884f214f1312650a3d36d269f5c4f3cdee8a2" dependencies = [ "aho-corasick", "memchr", @@ -710,7 +710,7 @@ checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" dependencies = [ "proc-macro2", "quote", - "syn 2.0.118", + "syn", ] [[package]] @@ -738,17 +738,6 @@ version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" -[[package]] -name = "syn" -version = "1.0.109" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - [[package]] name = "syn" version = "2.0.118" @@ -790,7 +779,7 @@ checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5" dependencies = [ "proc-macro2", "quote", - "syn 2.0.118", + "syn", ] [[package]] @@ -881,7 +870,7 @@ dependencies = [ "bumpalo", "proc-macro2", "quote", - "syn 2.0.118", + "syn", "wasm-bindgen-shared", ] @@ -973,11 +962,11 @@ checksum = "e2e817b7b52d0c7358d3246da9d69935ebb18116b2b102b4230dac079b4862f5" dependencies = [ "proc-macro2", "quote", - "syn 2.0.118", + "syn", ] [[package]] name = "zmij" -version = "1.0.21" +version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa" +checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b"