From aabcbc5dd1cdff326e9e251ff621a52dc0954c05 Mon Sep 17 00:00:00 2001 From: Alain Brenzikofer Date: Mon, 4 Feb 2019 09:23:39 +0100 Subject: [PATCH] !ported to no_std for sgx --- third_party/rust-base58/Cargo.lock | 375 +++++++++++++++++++++++++ third_party/rust-base58/Cargo.toml | 21 ++ third_party/rust-base58/LICENSE-APACHE | 201 +++++++++++++ third_party/rust-base58/LICENSE-MIT | 25 ++ third_party/rust-base58/readme.md | 41 +++ third_party/rust-base58/src/lib.rs | 219 +++++++++++++++ 6 files changed, 882 insertions(+) create mode 100644 third_party/rust-base58/Cargo.lock create mode 100644 third_party/rust-base58/Cargo.toml create mode 100644 third_party/rust-base58/LICENSE-APACHE create mode 100644 third_party/rust-base58/LICENSE-MIT create mode 100644 third_party/rust-base58/readme.md create mode 100644 third_party/rust-base58/src/lib.rs diff --git a/third_party/rust-base58/Cargo.lock b/third_party/rust-base58/Cargo.lock new file mode 100644 index 000000000..4b7b9ede4 --- /dev/null +++ b/third_party/rust-base58/Cargo.lock @@ -0,0 +1,375 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "autocfg" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "bitflags" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "cfg-if" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "cloudabi" +version = "0.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "filetime" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "fuchsia-cprng" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "libc" +version = "0.2.48" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "num" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "num-bigint 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "num-complex 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)", + "num-iter 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", + "num-rational 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "num-bigint" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "num-complex" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "num-integer" +version = "0.1.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "num-iter" +version = "0.1.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "num-rational" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "num-bigint 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "num-traits" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "rand" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_hc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_isaac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_jitter 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_os 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_pcg 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rand_chacha" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rand_core" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rand_core" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "rand_hc" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rand_isaac" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rand_jitter" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rand_os" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fuchsia-cprng 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rand_pcg" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rand_xorshift" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rdrand" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "redox_syscall" +version = "0.1.51" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "rust-base58" +version = "0.0.4" +dependencies = [ + "num 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", + "sgx_tstd 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rustc_version" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "semver" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "semver-parser" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "sgx_alloc" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "sgx_trts 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "sgx_build_helper" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "filetime 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "sgx_libc" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "sgx_types 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "sgx_tprotected_fs" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "sgx_trts 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", + "sgx_types 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "sgx_trts" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "sgx_libc 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", + "sgx_types 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "sgx_tstd" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "sgx_alloc 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", + "sgx_build_helper 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "sgx_libc 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", + "sgx_tprotected_fs 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", + "sgx_trts 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", + "sgx_types 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", + "sgx_unwind 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "sgx_types" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "sgx_unwind" +version = "0.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "sgx_trts 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "winapi" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[metadata] +"checksum autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a6d640bee2da49f60a4068a7fae53acde8982514ab7bae8b8cea9e88cbcfd799" +"checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12" +"checksum cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "082bb9b28e00d3c9d39cc03e64ce4cea0f1bb9b3fde493f0cbc008472d22bdf4" +"checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" +"checksum filetime 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)" = "714653f3e34871534de23771ac7b26e999651a0a228f47beb324dfdf1dd4b10f" +"checksum fuchsia-cprng 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "81f7f8eb465745ea9b02e2704612a9946a59fa40572086c6fd49d6ddcf30bf31" +"checksum libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)" = "e962c7641008ac010fa60a7dfdc1712449f29c44ef2d4702394aea943ee75047" +"checksum num 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cf4825417e1e1406b3782a8ce92f4d53f26ec055e3622e1881ca8e9f5f9e08db" +"checksum num-bigint 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "57450397855d951f1a41305e54851b1a7b8f5d2e349543a02a2effe25459f718" +"checksum num-complex 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "107b9be86cd2481930688277b675b0114578227f034674726605b8a482d8baf8" +"checksum num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "e83d528d2677f0518c570baf2b7abdcf0cd2d248860b68507bdcb3e91d4c0cea" +"checksum num-iter 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "af3fdbbc3291a5464dc57b03860ec37ca6bf915ed6ee385e7c6c052c422b2124" +"checksum num-rational 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4e96f040177bb3da242b5b1ecf3f54b5d5af3efbbfb18608977a5d2767b22f10" +"checksum num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0b3a5d7cc97d6d30d8b9bc8fa19bf45349ffe46241e8816f50f62f6d6aaabee1" +"checksum rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca" +"checksum rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef" +"checksum rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" +"checksum rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d0e7a549d590831370895ab7ba4ea0c1b6b011d106b5ff2da6eee112615e6dc0" +"checksum rand_hc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4" +"checksum rand_isaac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08" +"checksum rand_jitter 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "080723c6145e37503a2224f801f252e14ac5531cb450f4502698542d188cb3c0" +"checksum rand_os 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b7c690732391ae0abafced5015ffb53656abfaec61b342290e5eb56b286a679d" +"checksum rand_pcg 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "086bd09a33c7044e56bb44d5bdde5a60e7f119a9e95b0775f545de759a32fe05" +"checksum rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c" +"checksum rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" +"checksum redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)" = "423e376fffca3dfa06c9e9790a9ccd282fafb3cc6e6397d01dbf64f9bacc6b85" +"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" +"checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" +"checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" +"checksum sgx_alloc 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "cc0635268dc99d479341f5a99aa6ac67a6e98b17aea9ceb6caa53f7b629cb7ac" +"checksum sgx_build_helper 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee53e3b297178bf5a3b6275015020875149e12424d7d2ec01a2f0cfcc475b878" +"checksum sgx_libc 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "d8c5c9ba30db56c3d066a9bfbc90600b981cf389689bf8dce53d9af5302d7eac" +"checksum sgx_tprotected_fs 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "747a8d686d362fc4c734b320bd153b6256af73c0e6cb991e28c406262e75d4ad" +"checksum sgx_trts 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "06e0230fbfd322b8deb71ad887755a761bdd656944145dd610bdf9f4074c737c" +"checksum sgx_tstd 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ecc7e96841c7990e9d1234d11a5349c7d7e3fb2ee71e9f9014b0345af11881ef" +"checksum sgx_types 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "4fbbd6ab078bf8020683bf750906ace93a0f2a9c5b1e3fc7ae0859f596db8dfd" +"checksum sgx_unwind 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "02106e1c1a0dc78e322eb3d3e26a70fc3c900011306ea73b1e1edb4ff75189fa" +"checksum winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "92c1eb33641e276cfa214a0522acad57be5c56b10cb348b3c5117db75f3ac4b0" +"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/third_party/rust-base58/Cargo.toml b/third_party/rust-base58/Cargo.toml new file mode 100644 index 000000000..9291c1e54 --- /dev/null +++ b/third_party/rust-base58/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "rust-base58" +version = "0.0.4" +authors = ["Nick Hamann "] +license = "MIT/Apache-2.0" +homepage = "https://github.com/nham/rust-base58" +repository = "https://github.com/nham/rust-base58" +description = """ +Simple library for converting to and from base-58 strings. +""" + +[target.'cfg(not(target_env = "sgx"))'.dependencies] +sgx_tstd = "1.0.5" +num = { path = "../num/"} +num-bigint = { path = "../num/bigint"} +[dependencies] +num = { path = "../num/"} + +[dev-dependencies] +rand = "*" + diff --git a/third_party/rust-base58/LICENSE-APACHE b/third_party/rust-base58/LICENSE-APACHE new file mode 100644 index 000000000..16fe87b06 --- /dev/null +++ b/third_party/rust-base58/LICENSE-APACHE @@ -0,0 +1,201 @@ + 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. diff --git a/third_party/rust-base58/LICENSE-MIT b/third_party/rust-base58/LICENSE-MIT new file mode 100644 index 000000000..092473146 --- /dev/null +++ b/third_party/rust-base58/LICENSE-MIT @@ -0,0 +1,25 @@ +Copyright (c) 2015 Nick Hamann + +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. diff --git a/third_party/rust-base58/readme.md b/third_party/rust-base58/readme.md new file mode 100644 index 000000000..eafe5f8e5 --- /dev/null +++ b/third_party/rust-base58/readme.md @@ -0,0 +1,41 @@ +# rust-base58 + +Conversion library for [base-58](http://en.wikipedia.org/wiki/Base58). Currently it uses the Bitcoin base58 alphabet: + +``` +123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz +``` + + +## Usage + +Add this to `Cargo.toml`: + +```toml +[dependencies] +rust-base58 = "*" +``` + +and use it like this: + +```rust +extern crate rust_base58; + +use rust_base58::{ToBase58, FromBase58}; + +fn main() { + let x = &[1, 2, 3]; + + // to_base58() returns a String + let x_b58 = x.to_base58(); + assert_eq!("Ldp", x_b58); + + // from_base58() returns a Vec + let x_again = x_b58.from_base58().unwrap(); + assert_eq!(x, &x_again[..]); + + // from_base58() can fail, for example due to the input string + // containing an invalid base58 character like "I": + assert!("I".from_base58().is_err()); +} +``` diff --git a/third_party/rust-base58/src/lib.rs b/third_party/rust-base58/src/lib.rs new file mode 100644 index 000000000..5c7534c21 --- /dev/null +++ b/third_party/rust-base58/src/lib.rs @@ -0,0 +1,219 @@ +#![cfg_attr(not(target_env = "sgx"), no_std)] +#![cfg_attr(target_env = "sgx", feature(rustc_private))] + +#[cfg(not(target_env = "sgx"))] +extern crate sgx_tstd as std; +extern crate num; +extern crate num_bigint; +#[cfg(test)] extern crate rand; + +use num_bigint::ToBigUint; +use num_bigint::BigUint; +use num::{Zero, One}; +use num::traits::ToPrimitive; +use std::fmt; +use std::vec::Vec; +use std::string::String; + +pub use self::FromBase58Error::*; + +const BTC_ALPHA: &'static[u8] = b"123456789\ + ABCDEFGHJKLMNPQRSTUVWXYZ\ + abcdefghijkmnopqrstuvwxyz"; + +const FLICKR_ALPHA: &'static[u8] = b"123456789\ + abcdefghijkmnopqrstuvwxyz\ + ABCDEFGHJKLMNPQRSTUVWXYZ"; + +/// A trait for converting base58-encoded values +pub trait FromBase58 { + /// Converts the value of `self`, interpreted as base58 encoded data, + /// into an owned vector of bytes, returning the vector. + fn from_base58(&self) -> Result, FromBase58Error>; +} + + +/// Errors that can occur when decoding a base58-encoded string +#[derive(Clone, Copy)] +pub enum FromBase58Error { + /// The input contained a character not part of the base58 alphabet + InvalidBase58Byte(u8, usize), +} + +impl fmt::Debug for FromBase58Error { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match *self { + InvalidBase58Byte(ch, idx) => + write!(f, "Invalid character '{}' at position {}", ch, idx), + } + } +} + +impl fmt::Display for FromBase58Error { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(&self, f) + } +} + + + +impl FromBase58 for str { + fn from_base58(&self) -> Result, FromBase58Error> { + self.as_bytes().from_base58() + } +} + +impl FromBase58 for [u8] { + // TODO: fix some of the below when the binary assignment operators +=, *= + // are overloadable + fn from_base58(&self) -> Result, FromBase58Error> { + let radix = 58.to_biguint().unwrap(); + let mut x: BigUint = Zero::zero(); + let mut rad_mult: BigUint = One::one(); + + // Convert the base58 string to a BigUint `x` + for (idx, &byte) in self.iter().enumerate().rev() { + let first_idx = BTC_ALPHA.iter() + .enumerate() + .find(|x| *x.1 == byte) + .map(|x| x.0); + match first_idx { + Some(i) => { x = x + i.to_biguint().unwrap() * &rad_mult; }, + None => return Err(InvalidBase58Byte(self[idx], idx)) + } + + rad_mult = &rad_mult * &radix; + } + + let mut r = Vec::with_capacity(self.len()); + for _ in self.iter().take_while(|&x| *x == BTC_ALPHA[0]) { + r.push(0); + } + if x > Zero::zero() { + // TODO: use append when it becomes stable + r.extend(x.to_bytes_be()); + } + Ok(r) + } +} + + +/// A trait for converting a value to base58 encoding. +pub trait ToBase58 { + /// Converts the value of `self` to a base-58 value, returning the owned + /// string. + fn to_base58(&self) -> String; +} + +impl ToBase58 for [u8] { + // This function has to read in the entire byte slice and convert it to a + // (big) int before creating the string. There's no way to incrementally read + // the slice and create parts of the base58 string. Example: + // [1, 33] should be "5z" + // [1, 34] should be "61" + // so by reading "1", no way to know if first character should be 5 or 6 + // without reading the rest + fn to_base58(&self) -> String { + let radix = 58.to_biguint().unwrap(); + let mut x = BigUint::from_bytes_be(&self); + let mut ans = Vec::new(); //vec![]; + while x > Zero::zero() { + let rem = (&x % &radix).to_usize().unwrap(); + ans.push(BTC_ALPHA[rem]); + x = &x / &radix; + } + + // take care of leading zeros + for _ in self.iter().take_while(|&x| *x == 0) { + ans.push(BTC_ALPHA[0]); + } + ans.reverse(); + String::from_utf8(ans).unwrap() + } +} + + +#[cfg(test)] +mod tests { + use super::{FromBase58, ToBase58}; + + #[test] + fn test_from_base58_basic() { + assert_eq!("".from_base58().unwrap(), b""); + assert_eq!("Z".from_base58().unwrap(), &[32]); + assert_eq!("n".from_base58().unwrap(), &[45]); + assert_eq!("q".from_base58().unwrap(), &[48]); + assert_eq!("r".from_base58().unwrap(), &[49]); + assert_eq!("z".from_base58().unwrap(), &[57]); + assert_eq!("4SU".from_base58().unwrap(), &[45, 49]); + assert_eq!("4k8".from_base58().unwrap(), &[49, 49]); + assert_eq!("ZiCa".from_base58().unwrap(), &[97, 98, 99]); + assert_eq!("3mJr7AoUXx2Wqd".from_base58().unwrap(), b"1234598760"); + assert_eq!("3yxU3u1igY8WkgtjK92fbJQCd4BZiiT1v25f".from_base58().unwrap(), b"abcdefghijklmnopqrstuvwxyz"); + } + + #[test] + fn test_from_base58_bytes() { + assert_eq!(b"ZiCa".from_base58().unwrap(), b"abc"); + } + + #[test] + fn test_from_base58_invalid_char() { + assert!("0".from_base58().is_err()); + assert!("O".from_base58().is_err()); + assert!("I".from_base58().is_err()); + assert!("l".from_base58().is_err()); + assert!("3mJr0".from_base58().is_err()); + assert!("O3yxU".from_base58().is_err()); + assert!("3sNI".from_base58().is_err()); + assert!("4kl8".from_base58().is_err()); + assert!("s!5<".from_base58().is_err()); + assert!("t$@mX<*".from_base58().is_err()); + } + + #[test] + fn test_from_base58_initial_zeros() { + assert_eq!("1ZiCa".from_base58().unwrap(), b"\0abc"); + assert_eq!("11ZiCa".from_base58().unwrap(), b"\0\0abc"); + assert_eq!("111ZiCa".from_base58().unwrap(), b"\0\0\0abc"); + assert_eq!("1111ZiCa".from_base58().unwrap(), b"\0\0\0\0abc"); + } + + #[test] + fn test_to_base58_basic() { + assert_eq!(b"".to_base58(), ""); + assert_eq!(&[32].to_base58(), "Z"); + assert_eq!(&[45].to_base58(), "n"); + assert_eq!(&[48].to_base58(), "q"); + assert_eq!(&[49].to_base58(), "r"); + assert_eq!(&[57].to_base58(), "z"); + assert_eq!(&[45, 49].to_base58(), "4SU"); + assert_eq!(&[49, 49].to_base58(), "4k8"); + assert_eq!(b"abc".to_base58(), "ZiCa"); + assert_eq!(b"1234598760".to_base58(), "3mJr7AoUXx2Wqd"); + assert_eq!(b"abcdefghijklmnopqrstuvwxyz".to_base58(), "3yxU3u1igY8WkgtjK92fbJQCd4BZiiT1v25f"); + } + + #[test] + fn test_to_base58_initial_zeros() { + assert_eq!(b"\0abc".to_base58(), "1ZiCa"); + assert_eq!(b"\0\0abc".to_base58(), "11ZiCa"); + assert_eq!(b"\0\0\0abc".to_base58(), "111ZiCa"); + assert_eq!(b"\0\0\0\0abc".to_base58(), "1111ZiCa"); + } + + #[test] + fn test_base58_random() { + use rand::{thread_rng, Rng}; + + for _ in 0..200 { + let times = thread_rng().gen_range(1, 100); + let v = thread_rng().gen_iter::().take(times) + .collect::>(); + assert_eq!(v.to_base58() + .from_base58() + .unwrap(), + v); + } + } +}