bs58-0.2.2/.authorized_keys010064400037200003720000000075141334714656200137470ustar0000000000000000# Keys that are allowed to sign release tags -----BEGIN PGP PUBLIC KEY BLOCK----- mQINBFYIUngBEACUWHt0ka0JdbgH9kFeC/gZYyZylDSdnw1UVucYfGB5ymqMQmiF T84xHxAPUa//JBoqsZH0Ra8ULDcihx6nUPGoptBygvd3OuCA9np/U2Cp87gskqBy tHbIGm9Bw6Xs7aarm5G87JjF5WCQU8Y/nJSW3s6RJm9klnkC4Gu6IYRworhAzVYy BDzrPve1gMPOm1Otd5obo1KkkCWdhyi4hjXr44V7tWnAOZl7MqNwT0kFv4FqnQUs 3Tzv6Dk1hpIBz70viCZypCGkyB2dCNSeuXjAYRHvSJY879qYW8eunQzQcFxlItZz s8lsn2iC0eR7EJ+DUXqJzoEq74xo8mJHDpVDwas87ohPf9s1iqgOhUoqAxnYVPv8 jokd5lV9iky3a2L5tUGO4HMkZRHrD7tfLR+cEe2pcLvEx+DSi1NfK6QByKYNdxaJ OzcmZdjzyPlKvs0OHUBzjitRQUr1Fv2CyfSsrSq/bDlNYtVUhMSaim9G80jfUNFA 4aguYBZ4mmwEBIYIGKDl9TfQXT9Nn8xgiCNiagSkZn8TC/Zn4uDKlKiauzkrQ0GM odgBlp06AQkI3EG64ABxDYRhRYF4dC7NhpcBjocp+ceTKDAqqXHkiku/ot6gp+Mj vI6cGALNBTaCaLJg9m5iyauVrKrrmysjrV5lYI9N2sBeLctTR9i0sncubQARAQAB tBxXaW0gTG9vbWFuIDx3aW1AbmVtbzE1Ny5jb20+iQJCBBMBCAAsAhsDBwsJCAcD AgEGFQgCCQoLBBYCAwECHgECF4ACGQEFAlpXzTQFCQYx/7wACgkQFxGNu+WD91BX Sw/+JqtH2cwLZiLbUdMX6vVVMuiUxbPJlmto50pNC/aX44z3yF0fRm+excj2Z3ZC AQSWJw3kS4YMMOPaTWAX8MTgWfCZgizk8HrJ5G76Sjx4RD5IaGD8ehVZIPUU9w9o +FlinIREcabFKQZJEuVhYl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8Uo sUyDpb7lB8FqP4ZsNCgf5sv8snUBMtOCeu6l2mfun1QqU/+LUx4I6ixZ3rJCUuun 0ouOVhCycnqM+3ePd/hID0wzF1BFQohcOZEk8wRhOvV2+xRDr3dane8uSoKQQD7W thT4QmTKleiPMSnhCQawMkhR4PAP9rZbNP1PnX/ITSzvbhxFuspEUrMguh9n3jbZ UWZrtxpZmeTlY+dm6JlOrsqplSJAyxQUIM4EjdmHCy1qNJwVjr5V8/Y0kP0ssN1t G+YiObF8pZihF2ePeC9CvU3UC97+wgEYI+MY5McbaO+JizJAIoqou/IJQlREAszw LWCm5bAnajc3J0/aOSapWVv15YwJcNK6Fz+Yz21YJccKLJ66B9QibONW4DO3pHPw /ed400I4xL39nKAyfI3AEPnX6iv0nevsqCsPgdrGy5CdTjhvgaoocVN6D5H1YqOx 5D5hlOoRZHChHVopUIYwvy0w7GUUsAYYrC2N5BTkWmaHO4mZMfHG6Zb8sI72v2CC hkV/My5A4oqLa1VOqRopT9HjipHCBq4pD1H22ODdiKc+VBgARMIUsqnGRfq8ynKV F6Couv8V5zS5/BSsjg== =bW82 -----END PGP PUBLIC KEY BLOCK----- bs58-0.2.2/.gitignore010064400037200003720000000000311334714656200125100ustar0000000000000000target Cargo.lock .idea/bs58-0.2.2/.travis.yml010064400037200003720000000033441334714656200126430ustar0000000000000000language: rust sudo: false cache: cargo rust: - stable - beta - nightly os: - linux - osx stages: - name: test - name: deploy if: tag IS present env: global: - secure: "Igv1q1syhpuriXobvwdf3sVN+c8v0t4lhIkNBmgpEprs+rWHZoDAQCSaPQ4dsf5tpk0Eq6CLTlChK6WClfCDnMiVmthC6gnTYp8OJTw1WzDX+pJjbZEPWVAMZskbrL1Yt80VusyCRQZVBA91bz+qnITvokXgWI9/JhblGBk1n6v2YX9QONje+CxDs4ivLWfASXdglBT+K//qNVXOz78KiSrGCakWzpAtIbOurWgeJJT3fuUmHmsJPrXAO5PGrmKyx9u3nUZJGyU2iaqdE9khtJlvJcoKP9SBFczjiSdeKzKoxvyQRS4VXdt5Emb9E2U4Lej6F53EMyB5YD+4PqoZGAHW4gE1D++yMbY3LHzMjVfYKUB3IvlRrbOczXFetphuUP9soFPSUM9UfeoOQMReKOMnR64VtCgo2u3DBrtihfdzni+Lu7qORiOBfxroWlJcP8VDMiw04g0q18ljB62qKhalANAy/P43MJudr+0i3mnPO5ZXO2UBcqWrS/QUinNMSF9RIoGL+7CFbhngFJlg4ia4RKSXhe9BiusasC9oHdp3H442npjekvjrye0BR47aXKlK2C1LSLFxTZTZzT7H9WTcmbpy+5b7e6V7LRhPZ6EIez2fPAQIrZ5au0QTWRPc43ju9JIvfBszfS9ic2VJRIlcd2EGImda2RIpESdtvH4=" script: - cargo test - cargo test --all-features matrix: include: - rust: 1.13.0 os: linux script: - cargo test - rust: 1.13.0 os: osx script: - cargo test - name: clippy rust: nightly-2018-09-08 install: - rustup component add clippy-preview script: - cargo clippy --all-targets -- -D warnings - touch src/lib.rs - cargo clippy --all-targets --all-features -- -D warnings - name: publish to crates.io stage: deploy rust: stable script: - grep 'version = "'"$TRAVIS_TAG"'"' Cargo.toml || echo 'Tag does not match version in Cargo.toml' - gpg --import .authorized_keys - git tag --verify "$TRAVIS_TAG" before_deploy: - cargo package deploy: provider: script script: cargo publish --verbose --token "$CRATES_IO_TOKEN" skip_cleanup: true on: all_branches: true bs58-0.2.2/Cargo.toml.orig010064400037200003720000000007061334714656200134200ustar0000000000000000[package] name = "bs58" version = "0.2.2" authors = ["Wim Looman "] description = "Another Base58 codec implementation." repository = "https://github.com/mycorrhiza/bs58-rs" readme = "README.md" keywords = ["base58"] license = "MIT/Apache-2.0" [features] default = [] check = ["sha2"] [dependencies] sha2 = { version = "0.7.1", optional = true } [dev_dependencies] base58 = "0.1.0" rust-base58 = "0.0.4" assert_matches = "1.3.0" bs58-0.2.2/Cargo.toml0000644000000020040000000000000076470ustar00# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g. crates.io) dependencies # # If you believe there's an error in this file please file an # issue against the rust-lang/cargo repository. If you're # editing this file be aware that the upstream Cargo.toml # will likely look very different (and much more reasonable) [package] name = "bs58" version = "0.2.2" authors = ["Wim Looman "] description = "Another Base58 codec implementation." readme = "README.md" keywords = ["base58"] license = "MIT/Apache-2.0" repository = "https://github.com/mycorrhiza/bs58-rs" [dependencies.sha2] version = "0.7.1" optional = true [dev-dependencies.assert_matches] version = "1.3.0" [dev-dependencies.base58] version = "0.1.0" [dev-dependencies.rust-base58] version = "0.0.4" [features] check = ["sha2"] default = [] bs58-0.2.2/LICENSE-APACHE010064400037200003720000000251371334714656200124620ustar0000000000000000 Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. bs58-0.2.2/LICENSE-MIT010064400037200003720000000020721334714656200121630ustar0000000000000000MIT License Copyright (c) 2016 The roaring-rs developers. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. bs58-0.2.2/README.md010064400037200003720000000051121334714656200120040ustar0000000000000000# bs58 [![travis-badge][]][travis] [![cargo-badge][]][cargo] [![license-badge][]][license] [![rust-version-badge][]][rust-version] Another Rust [Base58][] codec implementation. Compared to [`base58`][] this is significantly faster at decoding (about 2.4x as fast when decoding 32 bytes), almost the same speed for encoding (about 3% slower when encoding 32 bytes), doesn't have the 128 byte limitation and supports a configurable alphabet. Compared to [`rust-base58`][] this is massively faster (over ten times as fast when decoding 32 bytes, almost 40 times as fast when encoding 32 bytes), has no external dependencies and supports a configurable alphabet. ## Minimum Version `bs58` is currently targeted to compile back to Rust 1.13. This is guaranteed to continue working until a non-(cargo)semver compatible update. Optional features are excluded from this policy, they rely on dependencies that do not have such a stable minimum version policy. ## Developing This project uses [clippy][] and denies warnings in CI builds. To ensure your changes will be accepted please check them with `cargo clippy` (available via `rustup component add clippy-preview` on nightly rust) before submitting a pull request (along with `cargo test` as usual). The nightly date used in CI (and as a consequence, clippy version) is pinned in the `.travis.yml` to avoid breaking on new warning additions, feel free to update to a new version anytime as part of a pull request. ## License Licensed under either of * Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) at your option. ### Contribution Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you shall be dual licensed as above, without any additional terms or conditions. [travis-badge]: https://img.shields.io/travis/mycorrhiza/bs58-rs/master.svg?style=flat-square [travis]: https://travis-ci.org/mycorrhiza/bs58-rs [cargo-badge]: https://img.shields.io/crates/v/bs58.svg?style=flat-square [cargo]: https://crates.io/crates/bs58 [license-badge]: https://img.shields.io/badge/license-MIT/Apache--2.0-lightgray.svg?style=flat-square [license]: #license [rust-version-badge]: https://img.shields.io/badge/rust-1.13+-blue.svg?style=flat-square [rust-version]: #minimum-version [Base58]: https://en.wikipedia.org/wiki/Base58 [`base58`]: https://github.com/debris/base58 [`rust-base58`]: https://github.com/nham/rust-base58 [clippy]: https://github.com/rust-lang-nursery/rust-clippy bs58-0.2.2/benches/bench.rs010064400037200003720000000142411334714656200135640ustar0000000000000000#![feature(test)] extern crate test; extern crate base58; extern crate bs58; extern crate rust_base58; macro_rules! bench_from { ($krate:ident, $value:expr) => { #[bench] #[allow(deprecated)] fn $krate(b: &mut ::test::Bencher) { use $krate::FromBase58; let temp = $value; if temp.from_base58().is_err() { b.iter(|| ()); } else { b.iter(|| temp.from_base58().unwrap()); } } }; } macro_rules! bench_to { ($krate:ident, $value:expr) => { #[bench] #[allow(deprecated)] fn $krate(b: &mut ::test::Bencher) { use $krate::ToBase58; let temp = $value; b.iter(|| temp.to_base58()); } }; } macro_rules! case { ($name:ident ($decoded_length:expr) $decoded:expr => $encoded:expr) => { mod $name { mod decode { bench_from!(base58, $encoded); bench_from!(bs58, $encoded); bench_from!(rust_base58, $encoded); #[bench] fn bs58_notrait(b: &mut ::test::Bencher) { b.iter(|| ::bs58::decode($encoded).into_vec().unwrap()); } #[bench] fn bs58_noalloc_slice(b: &mut ::test::Bencher) { let mut output = [0; $decoded_length]; b.iter(|| ::bs58::decode($encoded).into(&mut output[..]).unwrap()); } #[bench] fn bs58_noalloc_array(b: &mut ::test::Bencher) { let mut output = [0; $decoded_length]; b.iter(|| ::bs58::decode($encoded).into(&mut output).unwrap()); } } mod encode { bench_to!(base58, $decoded); bench_to!(bs58, $decoded); bench_to!(rust_base58, $decoded); #[bench] fn bs58_notrait(b: &mut ::test::Bencher) { b.iter(|| ::bs58::encode($decoded).into_string()); } #[bench] fn bs58_noalloc(b: &mut ::test::Bencher) { let mut output = String::with_capacity($encoded.len()); b.iter(|| ::bs58::encode($decoded).into(&mut output)); } } } }; ($name:ident {$decoded_length:expr} $decoded:expr => $encoded:expr) => { mod $name { mod decode { bench_from!(base58, $encoded); bench_from!(bs58, $encoded); bench_from!(rust_base58, $encoded); #[bench] fn bs58_notrait(b: &mut ::test::Bencher) { b.iter(|| ::bs58::decode($encoded).into_vec().unwrap()); } #[bench] fn bs58_noalloc_slice(b: &mut ::test::Bencher) { let mut output = [0; $decoded_length]; b.iter(|| ::bs58::decode($encoded).into(&mut output[..]).unwrap()); } } mod encode { bench_to!(base58, $decoded); bench_to!(bs58, $decoded); bench_to!(rust_base58, $decoded); } } }; } case! { a_empty (0) vec![] => "" } case! { b_1_byte (1) vec![0x61] => "2g" } case! { c_5_bytes (5) vec![0x51, 0x6b, 0x6f, 0xcd, 0x0f] => "ABnLTmg" } case! { d_10_bytes (10) vec![0xec, 0xac, 0x89, 0xca, 0xd9, 0x39, 0x23, 0xc0, 0x23, 0x21] => "EJDM8drfXA6uyA" } case! { e_10_bytes_zero (10) vec![0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] => "1111111111" } case! { f_10_bytes_max (10) vec![0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff] => "FPBt6CHo3fovdL" } case! { g_32_bytes (32) vec![ 0x18, 0xf3, 0x06, 0xdf, 0xe6, 0x99, 0xd2, 0x08, 0x5c, 0x89, 0x7b, 0x43, 0xa4, 0xc5, 0x4f, 0xc4, 0x7d, 0x2b, 0xb7, 0x55, 0x67, 0x5b, 0xe8, 0xa7, 0x49, 0x83, 0x68, 0x83, 0x00, 0x65, 0xd6, 0xe7 ] => "2gPihUTjt3FJqf1VpidgrY5cZ6PuyMccGVwQHRfjMPZG" } case! { h_256_bytes {256} vec![ 0x65, 0x5f, 0x65, 0x20, 0xc4, 0xd8, 0xa5, 0x86, 0xce, 0x80, 0x1a, 0x4e, 0x60, 0x73, 0x91, 0x40, 0x10, 0x8f, 0xd5, 0xdc, 0x5b, 0x3e, 0x8e, 0x08, 0x47, 0x98, 0x82, 0xc6, 0x29, 0xee, 0x49, 0x8d, 0xb6, 0x41, 0xa1, 0xc6, 0xa9, 0xd3, 0x63, 0xcb, 0xe2, 0x4e, 0x3f, 0x90, 0x78, 0x04, 0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0x09, 0x37, 0xf1, 0x17, 0x2d, 0xb8, 0xa8, 0xaa, 0x5a, 0x61, 0xf1, 0xbe, 0x08, 0x40, 0x47, 0xa8, 0x16, 0xf9, 0xb0, 0x0f, 0x6d, 0x34, 0x62, 0x29, 0x2b, 0xb3 ] => "\ 5gkXES6JSFLhJ3pkwQsV3MT3TBjsW5vQnAW8CwPLS1oDsJgjq8dchz994yCJHD1C16k3Pk\ Gp8o61dMfXy1vVwXcD147ix2BXD87xcXGnzB4mxaUEvgqDonZz8xQE9XL44XvLQshJw7kp\ 54MkSPbVkxvzKdxiYHkgAjLfmx5wdyDNjPu2DUYmxRrTtjDw5QVMaqAp3fLrQ6GnXuhZmB\ Jdj8rTprjADLM5tox6tHgyj2bm37ECxKevEapzy4nDGmZrzMubp9s58TsV1wk3LUQsRF49\ L9NzDatxVUetHTjQennpEHEuMTU9D8GM6De44J7Sk5fnJGh614ZtmrYyFcCE3X5mdTwaxA\ " } bs58-0.2.2/examples/decode.rs010064400037200003720000000007531334714656200141420ustar0000000000000000#![allow(unknown_lints)] // For clippy #![allow(renamed_and_removed_lints)] // clippy namespaced lint compat #![allow(explicit_write)] // 1.13 compat extern crate bs58; use std::io::{ self, Read, Write }; fn main() { let mut input = String::new(); io::stdin().read_to_string(&mut input).unwrap(); match bs58::decode(input.trim()).into_vec() { Ok(vec) => io::stdout().write_all(&*vec).unwrap(), Err(err) => writeln!(io::stderr(), "{}", err).unwrap(), }; } bs58-0.2.2/examples/encode.rs010064400037200003720000000003171334714656200141500ustar0000000000000000extern crate bs58; use std::io::{ self, Read }; fn main() { let mut input = Vec::::new(); io::stdin().read_to_end(&mut input).unwrap(); println!("{}", bs58::encode(input).into_string()); } bs58-0.2.2/src/alphabet.rs010064400037200003720000000023121334714656200134410ustar0000000000000000//! Commonly used Base58 alphabets. #[allow(doc_markdown)] // clippy is a little over-aggressive here /// Bitcoin's alphabet as defined in their Base58Check encoding. /// /// See https://en.bitcoin.it/wiki/Base58Check_encoding#Base58_symbol_chart. pub const BITCOIN: &'static [u8; 58] = b"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"; /// Monero's alphabet as defined in this forum post. /// /// See https://forum.getmonero.org/4/academic-and-technical/221/creating-a-standard-for-physical-coins pub const MONERO: &'static [u8; 58] = b"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"; /// Ripple's alphabet as defined in their wiki. /// /// See https://wiki.ripple.com/Encodings pub const RIPPLE: &'static [u8; 58] = b"rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz"; /// Flickr's alphabet for creating short urls from photo ids. /// /// See https://www.flickr.com/groups/api/discuss/72157616713786392/ pub const FLICKR: &'static [u8; 58] = b"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"; /// The default alphabet used if none is given. Currently is the /// [`BITCOIN`](constant.BITCOIN.html) alphabet. pub const DEFAULT: &'static [u8; 58] = BITCOIN; bs58-0.2.2/src/decode.rs010064400037200003720000000231411334714656200131070ustar0000000000000000//! Functions for decoding Base58 encoded strings. pub use error::DecodeError; /// A builder for setting up the alphabet and output of a base58 decode. /// /// See the documentation for [`bs58::decode`](../fn.decode.html) for a more /// high level view of how to use this. #[allow(missing_debug_implementations)] pub struct DecodeBuilder<'a, I: AsRef<[u8]>> { input: I, alpha: &'a [u8; 58], check: bool, expected_ver: Option } impl<'a, I: AsRef<[u8]>> DecodeBuilder<'a, I> { /// Setup decoder for the given string using the given alphabet. /// Preferably use [`bs58::decode`](../fn.decode.html) instead of this /// directly. pub fn new(input: I, alpha: &'a [u8; 58]) -> DecodeBuilder<'a, I> { DecodeBuilder { input: input, alpha: alpha, check: false, expected_ver: None } } /// Change the alphabet that will be used for decoding. /// /// # Examples /// /// ```rust /// assert_eq!( /// vec![0x60, 0x65, 0xe7, 0x9b, 0xba, 0x2f, 0x78], /// bs58::decode("he11owor1d") /// .with_alphabet(bs58::alphabet::RIPPLE) /// .into_vec().unwrap()); /// ``` #[allow(needless_lifetimes)] // They're specified for nicer documentation pub fn with_alphabet<'b>(self, alpha: &'b [u8; 58]) -> DecodeBuilder<'b, I> { DecodeBuilder { input: self.input, alpha: alpha, check: self.check, expected_ver: self.expected_ver } } /// Expect and check checksum using the [Base58Check][] algorithm when /// decoding. /// /// Optional parameter for version byte. If provided, the version byte will /// be used in verification. /// /// [Base58Check]: https://en.bitcoin.it/wiki/Base58Check_encoding /// /// # Features /// /// Requires the `check` feature flag to be active. /// /// # Examples /// /// ```rust /// assert_eq!( /// vec![0x2d, 0x31], /// bs58::decode("PWEu9GGN") /// .with_check(None) /// .into_vec().unwrap()); /// ``` #[cfg(feature = "check")] pub fn with_check(mut self, expected_ver: Option) -> DecodeBuilder<'a, I> { self.check = true; self.expected_ver = expected_ver; self } /// Decode into a new vector of bytes. /// /// See the documentation for [`bs58::decode`](../fn.decode.html) for an /// explanation of the errors that may occur. /// /// # Examples /// /// ```rust /// assert_eq!( /// vec![0x04, 0x30, 0x5e, 0x2b, 0x24, 0x73, 0xf0, 0x58], /// bs58::decode("he11owor1d").into_vec().unwrap()); /// ``` /// pub fn into_vec(self) -> Result, DecodeError> { let mut output = vec![0; (self.input.as_ref().len() / 8 + 1) * 6]; self.into(&mut output).map(|len| { output.truncate(len); output }) } /// Decode into the given buffer. /// /// Returns the length written into the buffer, the rest of the bytes in /// the buffer will be untouched. /// /// See the documentation for [`bs58::decode`](../fn.decode.html) for an /// explanation of the errors that may occur. /// /// # Examples /// /// ```rust /// let mut output = [0xFF; 10]; /// assert_eq!(8, bs58::decode("he11owor1d").into(&mut output).unwrap()); /// assert_eq!( /// [0x04, 0x30, 0x5e, 0x2b, 0x24, 0x73, 0xf0, 0x58, 0xFF, 0xFF], /// output); /// ``` pub fn into>(self, mut output: O) -> Result { if self.check { #[cfg(feature = "check")] { decode_check_into( self.input.as_ref(), output.as_mut(), self.alpha, self.expected_ver, ) } #[cfg(not(feature = "check"))] { unreachable!("This function requires 'check' feature") } } else { decode_into(self.input.as_ref(), output.as_mut(), self.alpha) } } } /// Decode given string into given byte slice using the given alphabet. /// /// Returns the length written into the byte slice, the rest of the bytes in /// the slice will be left untouched. /// /// This is the low-level implementation that the `DecodeBuilder` uses to /// perform the decoding, it's very likely that the signature will change if /// the major version changes. /// /// # Examples /// /// ```rust /// let input = "he11owor1d"; /// let mut output = [0; 8]; /// bs58::decode::decode_into(input.as_ref(), &mut output, bs58::alphabet::DEFAULT); /// assert_eq!([0x04, 0x30, 0x5e, 0x2b, 0x24, 0x73, 0xf0, 0x58], output); /// ``` pub fn decode_into(input: &[u8], output: &mut [u8], alpha: &[u8; 58]) -> Result { let mut index = 0; let zero = alpha[0]; let alpha = { let mut rev = [0xFF; 128]; for (i, &c) in alpha.iter().enumerate() { rev[c as usize] = i as u8; } rev }; for (i, c) in input.iter().enumerate() { if *c > 127 { return Err(DecodeError::NonAsciiCharacter { index: i }); } let mut val = unsafe { *alpha.get_unchecked(*c as usize) as usize }; if val == 0xFF { return Err(DecodeError::InvalidCharacter { character: *c as char, index: i }); } else { for byte in &mut output[..index] { val += (*byte as usize) * 58; *byte = (val & 0xFF) as u8; val >>= 8; } while val > 0 { let byte = output.get_mut(index).ok_or(DecodeError::BufferTooSmall)?; *byte = (val & 0xFF) as u8; index += 1; val >>= 8 } } } for c in input { if *c == zero { let byte = output.get_mut(index).ok_or(DecodeError::BufferTooSmall)?; *byte = 0; index += 1; } else { break; } } output[..index].reverse(); Ok(index) } /// Decode given input slice into given output slice using the given alphabet. Expects /// and validates checksum bytes in input. /// /// Option for version byte. If given, it is used to verify input. /// /// Returns the length written into the byte slice, the rest of the bytes in /// the slice will be left untouched. /// /// This is the low-level implementation that the `DecodeBuilder` uses to /// perform the decoding, it's very likely that the signature will change if /// the major version changes. /// /// # Features /// /// Requires the `check` feature flag to be active. /// /// # Examples /// /// ```rust /// let input = "PWEu9GGN"; /// let mut output = [0; 6]; /// let l = bs58::decode::decode_check_into(input.as_ref(), &mut output, bs58::alphabet::DEFAULT, None); /// assert_eq!([0x2d, 0x31], output[..l.unwrap()]); /// ``` #[cfg(feature = "check")] pub fn decode_check_into(input: &[u8], output: &mut [u8], alpha: &[u8; 58], expected_ver: Option) -> Result { use sha2::{Sha256, Digest}; use CHECKSUM_LEN; let decoded_len = decode_into(input, output, alpha)?; if decoded_len < CHECKSUM_LEN { return Err(DecodeError::NoChecksum) } let checksum_index = decoded_len - CHECKSUM_LEN; let expected_checksum = &output[checksum_index..decoded_len]; let first_hash = Sha256::digest(&output[0..checksum_index]); let second_hash = Sha256::digest(&first_hash); let (checksum, _) = second_hash.split_at(CHECKSUM_LEN); if checksum == expected_checksum { if let Some(ver) = expected_ver { if output[0] == ver { Ok(checksum_index) } else { Err(DecodeError::InvalidVersion{ver: output[0], expected_ver: ver}) } } else { Ok(checksum_index) } } else { let mut a: [u8; CHECKSUM_LEN] = Default::default(); a.copy_from_slice(&checksum[..]); let mut b: [u8; CHECKSUM_LEN] = Default::default(); b.copy_from_slice(&expected_checksum[..]); Err(DecodeError::InvalidChecksum{checksum:a, expected_checksum:b}) } } // Subset of test cases from https://github.com/cryptocoinjs/base-x/blob/master/test/fixtures.json #[cfg(test)] mod tests { use decode; use decode::DecodeError; #[test] fn tests() { for &(val, s) in super::super::TEST_CASES.iter() { assert_eq!(val.to_vec(), decode(s).into_vec().unwrap()); } } #[test] fn test_small_buffer_err() { let mut output = [0; 2]; assert_eq!(decode("a3gV").into(&mut output), Err(DecodeError::BufferTooSmall)); } #[test] fn test_invalid_char() { let sample = "123456789abcd!efghij"; assert_eq!( decode(sample).into_vec().unwrap_err(), DecodeError::InvalidCharacter { character: '!', index: 13 }); } } #[cfg(test)] #[cfg(feature = "check")] mod test_check{ use decode; use decode::DecodeError; #[test] fn test_check(){ for &(val, s) in super::super::CHECK_TEST_CASES.iter() { assert_eq!(val.to_vec(), decode(s).with_check(None).into_vec().unwrap()); } for &(val, s) in super::super::CHECK_TEST_CASES[1..].iter() { assert_eq!(val.to_vec(), decode(s).with_check(Some(val[0])).into_vec().unwrap()); } } #[test] fn test_check_ver_failed() { let d = decode("K5zqBMZZTzUbAZQgrt4") .with_check(Some(0x01)) .into_vec(); assert!(d.is_err()); assert_matches!(d.unwrap_err(), DecodeError::InvalidVersion { .. }); } } bs58-0.2.2/src/encode.rs010064400037200003720000000153231334714656200131240ustar0000000000000000//! Functions for encoding into Base58 encoded strings. use CHECKSUM_LEN; /// A builder for setting up the alphabet and output of a base58 encode. #[allow(missing_debug_implementations)] pub struct EncodeBuilder<'a, I: AsRef<[u8]>> { input: I, alpha: &'a [u8; 58], check: bool, } impl<'a, I: AsRef<[u8]>> EncodeBuilder<'a, I> { /// Setup encoder for the given string using the given alphabet. /// Preferably use [`bs58::encode`](../fn.encode.html) instead of this /// directly. pub fn new(input: I, alpha: &'a [u8; 58]) -> EncodeBuilder<'a, I> { EncodeBuilder { input: input, alpha: alpha, check: false} } /// Change the alphabet that will be used for encoding. /// /// # Examples /// /// ```rust /// let input = [0x60, 0x65, 0xe7, 0x9b, 0xba, 0x2f, 0x78]; /// assert_eq!( /// "he11owor1d", /// bs58::encode(input) /// .with_alphabet(bs58::alphabet::RIPPLE) /// .into_string()); /// ``` #[allow(needless_lifetimes)] // They're specified for nicer documentation pub fn with_alphabet<'b>(self, alpha: &'b [u8; 58]) -> EncodeBuilder<'b, I> { EncodeBuilder { input: self.input, alpha: alpha, check: self.check} } /// Include checksum calculated using the [Base58Check][] algorithm when /// encoding. /// /// [Base58Check]: https://en.bitcoin.it/wiki/Base58Check_encoding /// /// # Features /// /// Requires the `check` feature flag to be active. /// /// # Examples /// /// ```rust /// let input = [0x60, 0x65, 0xe7, 0x9b, 0xba, 0x2f, 0x78]; /// assert_eq!( /// "QuT57JNzzWTu7mW", /// bs58::encode(input) /// .with_check() /// .into_string()); /// ``` #[cfg(feature = "check")] pub fn with_check(mut self) -> EncodeBuilder<'a, I> { self.check = true; self } /// Encode into a new owned string. /// /// # Examples /// /// ```rust /// let input = [0x04, 0x30, 0x5e, 0x2b, 0x24, 0x73, 0xf0, 0x58]; /// assert_eq!("he11owor1d", bs58::encode(input).into_string()); /// ``` pub fn into_string(self) -> String { let checksum_capacity = if self.check { CHECKSUM_LEN } else { 0 }; let mut output = String::with_capacity(((self.input.as_ref().len()+checksum_capacity) / 5 + 1) * 8); self.into(&mut output); output } /// Encode into the given string, any existing data will be cleared. /// /// If the given string does not have enough capacity for the encoded /// version of the data it will be reallocated as necessary. /// /// # Examples /// /// ```rust /// let input = [0x04, 0x30, 0x5e, 0x2b, 0x24, 0x73, 0xf0, 0x58]; /// let mut output = "goodbye world".to_owned(); /// bs58::encode(input).into(&mut output); /// assert_eq!("he11owor1d", output); /// ``` pub fn into(self, output: &mut String) { if self.check { #[cfg(feature = "check")] { encode_check_into(self.input.as_ref(), output, self.alpha) } #[cfg(not(feature = "check"))] { unreachable!("This function requires 'check' feature") } } else { encode_into(self.input.as_ref(), output, self.alpha) } } } /// Encode given bytes into given string using the given alphabet, any existing /// data will be cleared. /// /// This is the low-level implementation that the `EncodeBuilder` uses to /// perform the encoding, it's very likely that the signature will change if /// the major version changes. /// /// # Examples /// /// ```rust /// let input = [0x04, 0x30, 0x5e, 0x2b, 0x24, 0x73, 0xf0, 0x58]; /// let mut output = "goodbye world".to_owned(); /// bs58::encode::encode_into(&input[..], &mut output, bs58::alphabet::DEFAULT); /// assert_eq!("he11owor1d", output) /// ``` pub fn encode_into(input: &[u8], output: &mut String, alpha: &[u8; 58]){ _encode_into(input, output, alpha) } fn _encode_into<'a, I>(input: I, output: &mut String, alpha: &[u8; 58]) where I: Clone + IntoIterator { assert!(alpha.iter().all(|&c| c < 128)); output.clear(); let output = unsafe { // Writing directly to the bytes of this string is safe as above we have // verified that we are only going to be writing ASCII bytes, which is a // valid subset of UTF-8. // // We will also be temporarily pushing values in the range [0, 58) // before we transform these into the alphabet. These are also valid // UTF-8 bytes. output.as_mut_vec() }; for &val in input.clone() { let mut carry = val as usize; for byte in &mut output[..] { carry += (*byte as usize) << 8; *byte = (carry % 58) as u8; carry /= 58; } while carry > 0 { output.push((carry % 58) as u8); carry /= 58; } } for &val in input { if val == 0 { output.push(0); } else { break; } } for val in &mut output[..] { *val = alpha[*val as usize]; } output.reverse(); } /// Encode given bytes with checksum into given string using the given /// alphabet, any existing data will be cleared. /// /// This is the low-level implementation that the `EncodeBuilder` uses to /// perform the encoding with checksum, it's very likely that the signature /// will change if the major version changes. /// /// # Features /// /// Requires the `check` feature flag to be active. /// /// # Examples /// /// ```rust /// let input = [0x04, 0x30, 0x5e, 0x2b, 0x24, 0x73, 0xf0, 0x58]; /// let mut output = "goodbye world".to_owned(); /// bs58::encode::encode_check_into(&input[..], &mut output, bs58::alphabet::DEFAULT); /// assert_eq!("5avNxiWJRYjnKSJs", output) /// ``` #[cfg(feature = "check")] pub fn encode_check_into(input: &[u8], output: &mut String, alpha: &[u8; 58]) { use sha2::{Sha256, Digest}; let first_hash = Sha256::digest(input); let second_hash = Sha256::digest(&first_hash); let checksum = &second_hash[0..CHECKSUM_LEN]; _encode_into(input.iter().chain(checksum.iter()), output, alpha) } // Subset of test cases from https://github.com/cryptocoinjs/base-x/blob/master/test/fixtures.json #[cfg(test)] mod tests { use encode; #[test] fn tests() { for &(val, s) in super::super::TEST_CASES.iter() { assert_eq!(s, encode(val).into_string()) } } } #[cfg(test)] #[cfg(feature = "check")] mod test_check { use encode; #[test] fn tests() { for &(val, s) in super::super::CHECK_TEST_CASES.iter() { assert_eq!(s, encode(val).with_check().into_string()) } } } bs58-0.2.2/src/error.rs010064400037200003720000000077031334714656200130230ustar0000000000000000use std::error::Error; use std::fmt; #[cfg(feature = "check")] use CHECKSUM_LEN; /// Errors that could occur when decoding a Base58 encoded string. #[derive(Copy, Clone, Debug, Eq, PartialEq)] pub enum DecodeError { /// The output buffer was too small to contain the entire input. BufferTooSmall, /// The input contained a character that was not part of the current Base58 /// alphabet. InvalidCharacter { /// The unexpected character. character: char, /// The (byte) index in the input string the character was at. index: usize, }, /// The input contained a multi-byte (or non-utf8) character which is /// unsupported by this Base58 decoder. NonAsciiCharacter { /// The (byte) index in the input string the start of the character was /// at. index: usize, }, #[cfg(feature = "check")] /// The checksum did not match the payload bytes InvalidChecksum { ///The given checksum checksum: [u8; CHECKSUM_LEN], ///The checksum calculated for the payload expected_checksum: [u8; CHECKSUM_LEN] }, #[cfg(feature = "check")] /// The checksum did not match the payload bytes InvalidVersion { ///The given checksum ver: u8, ///The checksum calculated for the payload expected_ver: u8 }, #[cfg(feature = "check")] ///Not enough bytes to have both a checksum and a payload (less than to CHECKSUM_LEN) NoChecksum, #[doc(hidden)] __NonExhaustive, } impl Error for DecodeError { fn description(&self) -> &str { match *self { DecodeError::BufferTooSmall => "buffer provided to decode base58 encoded string into was too small", DecodeError::NonAsciiCharacter { .. } => "base58 encoded string contained a non-ascii character", DecodeError::InvalidCharacter { .. } => "base58 encoded string contained an invalid character", #[cfg(feature = "check")] DecodeError::InvalidChecksum { .. } => "base58 decode check did not match payload checksum with expected checksum", #[cfg(feature = "check")] DecodeError::InvalidVersion { .. } => "base58 decode check did not match payload version with expected version", #[cfg(feature = "check")] DecodeError::NoChecksum { .. } => "base58 encoded string does not contained enough bytes to have a checksum", DecodeError::__NonExhaustive => unreachable!(), } } } impl fmt::Display for DecodeError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { DecodeError::BufferTooSmall => write!(f, "buffer provided to decode base58 encoded string into was too small"), DecodeError::InvalidCharacter { character, index } => write!(f, "provided string contained invalid character {:?} at byte {}", character, index), DecodeError::NonAsciiCharacter { index } => write!(f, "provided string contained non-ascii character starting at byte {}", index), #[cfg(feature = "check")] DecodeError::InvalidChecksum { checksum, expected_checksum } => write!(f, "invalid checksum, calculated checksum: '{:?}', expected checksum: {:?}", checksum, expected_checksum), #[cfg(feature = "check")] DecodeError::InvalidVersion { ver, expected_ver } => write!(f, "invalid version, payload version: '{:?}', expected version: {:?}", ver, expected_ver), #[cfg(feature = "check")] DecodeError::NoChecksum => write!(f, "provided string is too small to contain a checksum"), DecodeError::__NonExhaustive => unreachable!(), } } } bs58-0.2.2/src/lib.rs010064400037200003720000000175241334714656200124420ustar0000000000000000#![warn(missing_copy_implementations)] #![warn(missing_debug_implementations)] #![warn(missing_docs)] #![warn(trivial_casts)] #![warn(trivial_numeric_casts)] #![warn(unused_extern_crates)] #![warn(unused_import_braces)] #![warn(unused_results)] #![warn(variant_size_differences)] #![allow(unknown_lints)] // For clippy #![allow(renamed_and_removed_lints)] // clippy namespaced lint compat #![allow(const_static_lifetime)] // 1.13 compat #![allow(redundant_field_names)] // 1.13 compat //! Another [Base58][] codec implementation. //! //! Compared to [`base58`][] this is significantly faster at decoding (about //! 2.4x as fast when decoding 32 bytes), almost the same speed for encoding //! (about 3% slower when encoding 32 bytes) and doesn't have the 128 byte //! limitation. //! //! Compared to [`rust-base58`][] this is massively faster (over ten times as //! fast when decoding 32 bytes, almost 40 times as fast when encoding 32 //! bytes) and has no external dependencies. //! //! Compared to both this supports a configurable alphabet and user provided //! buffers for zero-allocation {en,de}coding. //! //! [Base58]: https://en.wikipedia.org/wiki/Base58 //! [`base58`]: https://github.com/debris/base58 //! [`rust-base58`]: https://github.com/nham/rust-base58 //! //! # Optional Features //! //! ## `check` (off-by-default) //! //! Integrated support for [Base58Check][], this allows automatically //! calculating the checksum during encoding and verifying during decoding. //! //! [Base58Check]: https://en.bitcoin.it/wiki/Base58Check_encoding //! //! # Examples //! //! ## Basic example //! //! ```rust //! let decoded = bs58::decode("he11owor1d").into_vec().unwrap(); //! let encoded = bs58::encode(decoded).into_string(); //! assert_eq!("he11owor1d", encoded); //! ``` //! //! ## Changing the alphabet //! //! ```rust //! let decoded = bs58::decode("he11owor1d") //! .with_alphabet(bs58::alphabet::RIPPLE) //! .into_vec() //! .unwrap(); //! let encoded = bs58::encode(decoded) //! .with_alphabet(bs58::alphabet::FLICKR) //! .into_string(); //! assert_eq!("4DSSNaN1SC", encoded); //! ``` //! //! ## Decoding into an existing buffer //! //! ```rust //! let (mut decoded, mut encoded) = ([0xFF; 8], String::with_capacity(10)); //! bs58::decode("he11owor1d").into(&mut decoded).unwrap(); //! bs58::encode(decoded).into(&mut encoded); //! assert_eq!("he11owor1d", encoded); //! ``` //! #[cfg(feature = "check")] extern crate sha2; pub mod alphabet; pub mod decode; pub mod encode; mod error; mod traits; const CHECKSUM_LEN: usize = 4; #[allow(deprecated)] pub use traits::{ FromBase58, ToBase58 }; /// Setup decoder for the given string using the [default alphabet][]. /// /// [default alphabet]: alphabet/constant.DEFAULT.html /// /// # Examples /// /// ## Basic example /// /// ```rust /// assert_eq!( /// vec![0x04, 0x30, 0x5e, 0x2b, 0x24, 0x73, 0xf0, 0x58], /// bs58::decode("he11owor1d").into_vec().unwrap()); /// ``` /// /// ## Changing the alphabet /// /// ```rust /// assert_eq!( /// vec![0x60, 0x65, 0xe7, 0x9b, 0xba, 0x2f, 0x78], /// bs58::decode("he11owor1d") /// .with_alphabet(bs58::alphabet::RIPPLE) /// .into_vec().unwrap()); /// ``` /// /// ## Decoding into an existing buffer /// /// ```rust /// let mut output = [0xFF; 10]; /// assert_eq!(8, bs58::decode("he11owor1d").into(&mut output).unwrap()); /// assert_eq!( /// [0x04, 0x30, 0x5e, 0x2b, 0x24, 0x73, 0xf0, 0x58, 0xFF, 0xFF], /// output); /// ``` /// /// ## Errors /// /// ### Invalid Character /// /// ```rust /// assert_eq!( /// bs58::decode::DecodeError::InvalidCharacter { character: 'l', index: 2 }, /// bs58::decode("hello world").into_vec().unwrap_err()); /// ``` /// /// ### Non-ASCII Character /// /// ```rust /// assert_eq!( /// bs58::decode::DecodeError::NonAsciiCharacter { index: 5 }, /// bs58::decode("he11o🇳🇿").into_vec().unwrap_err()); /// ``` /// /// ### Too Small Buffer /// /// This error can only occur when reading into a provided buffer, when using /// `.into_vec` a vector large enough is guaranteed to be used. /// /// ```rust /// let mut output = [0; 7]; /// assert_eq!( /// bs58::decode::DecodeError::BufferTooSmall, /// bs58::decode("he11owor1d").into(&mut output).unwrap_err()); /// ``` pub fn decode>(input: I) -> decode::DecodeBuilder<'static, I> { decode::DecodeBuilder::new(input, alphabet::DEFAULT) } /// Setup encoder for the given bytes using the [default alphabet][]. /// /// [default alphabet]: alphabet/constant.DEFAULT.html /// /// # Examples /// /// ## Basic example /// /// ```rust /// let input = [0x04, 0x30, 0x5e, 0x2b, 0x24, 0x73, 0xf0, 0x58]; /// assert_eq!("he11owor1d", bs58::encode(input).into_string()); /// ``` /// /// ## Changing the alphabet /// /// ```rust /// let input = [0x60, 0x65, 0xe7, 0x9b, 0xba, 0x2f, 0x78]; /// assert_eq!( /// "he11owor1d", /// bs58::encode(input) /// .with_alphabet(bs58::alphabet::RIPPLE) /// .into_string()); /// ``` /// /// ## Encoding into an existing string /// /// ```rust /// let input = [0x04, 0x30, 0x5e, 0x2b, 0x24, 0x73, 0xf0, 0x58]; /// let mut output = "goodbye world".to_owned(); /// bs58::encode(input).into(&mut output); /// assert_eq!("he11owor1d", output); /// ``` pub fn encode>(input: I) -> encode::EncodeBuilder<'static, I> { encode::EncodeBuilder::new(input, alphabet::DEFAULT) } #[cfg(test)] #[cfg(feature = "check")] #[macro_use] extern crate assert_matches; #[cfg(test)] const TEST_CASES: &'static [(&'static [u8], &'static str)] = &[ (&[], ""), (&[0x61], "2g"), (&[0x62, 0x62, 0x62], "a3gV"), (&[0x63, 0x63, 0x63], "aPEr"), (&[0x57, 0x2e, 0x47, 0x94], "3EFU7m"), (&[0x10, 0xc8, 0x51, 0x1e], "Rt5zm"), (&[0x51, 0x6b, 0x6f, 0xcd, 0x0f], "ABnLTmg"), (&[0xbf, 0x4f, 0x89, 0x00, 0x1e, 0x67, 0x02, 0x74, 0xdd], "3SEo3LWLoPntC"), (&[0xec, 0xac, 0x89, 0xca, 0xd9, 0x39, 0x23, 0xc0, 0x23, 0x21], "EJDM8drfXA6uyA"), (&[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], "1111111111"), (&[0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff], "FPBt6CHo3fovdL"), (&[0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff], "NKioeUVktgzXLJ1B3t"), (&[0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff], "YcVfxkQb6JRzqk5kF2tNLv"), (&[0x73, 0x69, 0x6d, 0x70, 0x6c, 0x79, 0x20, 0x61, 0x20, 0x6c, 0x6f, 0x6e, 0x67, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67], "2cFupjhnEsSn59qHXstmK2ffpLv2"), (&[0x00, 0xeb, 0x15, 0x23, 0x1d, 0xfc, 0xeb, 0x60, 0x92, 0x58, 0x86, 0xb6, 0x7d, 0x06, 0x52, 0x99, 0x92, 0x59, 0x15, 0xae, 0xb1, 0x72, 0xc0, 0x66, 0x47], "1NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L"), (&[0x00, 0x3c, 0x17, 0x6e, 0x65, 0x9b, 0xea, 0x0f, 0x29, 0xa3, 0xe9, 0xbf, 0x78, 0x80, 0xc1, 0x12, 0xb1, 0xb3, 0x1b, 0x4d, 0xc8, 0x26, 0x26, 0x81, 0x87], "16UjcYNBG9GTK4uq2f7yYEbuifqCzoLMGS"), (&[0x80, 0x11, 0x84, 0xcd, 0x2c, 0xdd, 0x64, 0x0c, 0xa4, 0x2c, 0xfc, 0x3a, 0x09, 0x1c, 0x51, 0xd5, 0x49, 0xb2, 0xf0, 0x16, 0xd4, 0x54, 0xb2, 0x77, 0x40, 0x19, 0xc2, 0xb2, 0xd2, 0xe0, 0x85, 0x29, 0xfd, 0x20, 0x6e, 0xc9, 0x7e], "5Hx15HFGyep2CfPxsJKe2fXJsCVn5DEiyoeGGF6JZjGbTRnqfiD"), ]; #[cfg(test)] #[cfg(feature = "check")] const CHECK_TEST_CASES: &'static [(&'static [u8], &'static str)] = &[ (&[], "3QJmnh"), (&[0x31], "6bdbJ1U"), (&[0x39], "7VsrQCP"), (&[0x2d, 0x31], "PWEu9GGN"), (&[0x31, 0x31], "RVnPfpC2"), (&[0x31, 0x32, 0x33, 0x34, 0x35, 0x39, 0x38, 0x37, 0x36, 0x30], "K5zqBMZZTzUbAZQgrt4"), (&[0x00, 0x9b, 0x41, 0x54, 0xbb, 0xf2, 0x03, 0xe4, 0x13, 0x0c, 0x4b, 0x86, 0x25, 0x93, 0x18, 0xa4, 0x98, 0x75, 0xdd, 0x04, 0x56], "1F9v11cupBVMpz3CrVfCppv9Rw2xEtU1c6"), (&[0x53, 0x25, 0xb1, 0xe2, 0x3b, 0x5b, 0x24, 0xf3, 0x47, 0xed, 0x19, 0xde, 0x61, 0x23, 0x8a, 0xf1, 0x4b, 0xc4, 0x71, 0xca, 0xa1, 0xa7, 0x7a, 0xa5, 0x5d, 0xb2, 0xa7, 0xaf, 0x7d, 0xaa, 0x93, 0xaa], "dctKSXBbv2My3TGGUgTFjkxu1A9JM3Sscd5FydY4dkxnfwA7q"), ]; bs58-0.2.2/src/traits.rs010064400037200003720000000045641334714656200132020ustar0000000000000000use { encode, decode }; use error::DecodeError; /// A trait for Base58 encoding bytes to an owned string. #[allow(deprecated)] #[deprecated( since = "0.2.0", note = "Use `bs58::encode` and associated functions instead" )] #[doc(hidden)] pub trait ToBase58 { /// Base58 encode `self` to an owned string using the [default alphabet][]. /// /// [default alphabet]: alphabet/constant.DEFAULT.html fn to_base58(&self) -> String; /// Base58 encode `self` to an owned string using the given alphabet. fn to_base58_with_alphabet(&self, alpha: &[u8; 58]) -> String; } /// A trait for decoding Base58 encoded values to a vector of bytes. #[allow(deprecated)] #[deprecated( since = "0.2.0", note = "Use `bs58::decode` and associated functions instead" )] #[doc(hidden)] pub trait FromBase58 { /// Decode `self` to a vector of bytes using the [default alphabet][]. /// /// [default alphabet]: alphabet/constant.DEFAULT.html fn from_base58(&self) -> Result, DecodeError>; /// Decode `self` to a vector of bytes using the given alphabet. fn from_base58_with_alphabet(&self, alpha: &[u8; 58]) -> Result, DecodeError>; } #[allow(deprecated)] impl FromBase58 for str { #[allow(deprecated)] fn from_base58(&self) -> Result, DecodeError> { decode(self).into_vec() } #[allow(deprecated)] fn from_base58_with_alphabet(&self, alpha: &[u8; 58]) -> Result, DecodeError> { decode(self).with_alphabet(alpha).into_vec() } } #[allow(deprecated)] impl ToBase58 for [u8] { #[allow(deprecated)] fn to_base58(&self) -> String { encode(self).into_string() } #[allow(deprecated)] fn to_base58_with_alphabet(&self, alpha: &[u8; 58]) -> String { encode(self).with_alphabet(alpha).into_string() } } // Subset of test cases from https://github.com/cryptocoinjs/base-x/blob/master/test/fixtures.json #[cfg(test)] mod tests { #[allow(deprecated)] use { FromBase58, ToBase58 }; #[test] #[allow(deprecated)] fn test_to_base58() { for &(val, s) in super::super::TEST_CASES.iter() { assert_eq!(s, val.to_base58()); } } #[test] #[allow(deprecated)] fn test_from_base58() { for &(val, s) in super::super::TEST_CASES.iter() { assert_eq!(val.to_vec(), s.from_base58().unwrap()); } } }