Skip to content
Snippets Groups Projects
Commit fa3bd674 authored by Éloïs's avatar Éloïs
Browse files

[ref] externalize crate dup-crypto

parent 36a081db
Branches
No related tags found
1 merge request!271Elois/extern crypto
Showing
with 32 additions and 2347 deletions
...@@ -396,7 +396,7 @@ dependencies = [ ...@@ -396,7 +396,7 @@ dependencies = [
"dubp-common-doc 0.1.0", "dubp-common-doc 0.1.0",
"dubp-currency-params 0.2.0", "dubp-currency-params 0.2.0",
"dubp-user-docs 0.14.0", "dubp-user-docs 0.14.0",
"dup-crypto 0.8.0", "dup-crypto 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"dup-crypto-tests-tools 0.1.0", "dup-crypto-tests-tools 0.1.0",
"durs-bc-db-reader 0.3.0-dev", "durs-bc-db-reader 0.3.0-dev",
"durs-bc-db-writer 0.3.0-dev", "durs-bc-db-writer 0.3.0-dev",
...@@ -715,7 +715,7 @@ dependencies = [ ...@@ -715,7 +715,7 @@ dependencies = [
"dubp-currency-params 0.2.0", "dubp-currency-params 0.2.0",
"dubp-user-docs 0.14.0", "dubp-user-docs 0.14.0",
"dubp-user-docs-tests-tools 0.1.0", "dubp-user-docs-tests-tools 0.1.0",
"dup-crypto 0.8.0", "dup-crypto 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"durs-common-tools 0.2.0", "durs-common-tools 0.2.0",
"failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"json-pest-parser 0.2.0", "json-pest-parser 0.2.0",
...@@ -738,7 +738,7 @@ dependencies = [ ...@@ -738,7 +738,7 @@ dependencies = [
"dubp-currency-params 0.2.0", "dubp-currency-params 0.2.0",
"dubp-user-docs 0.14.0", "dubp-user-docs 0.14.0",
"dubp-user-docs-tests-tools 0.1.0", "dubp-user-docs-tests-tools 0.1.0",
"dup-crypto 0.8.0", "dup-crypto 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"dup-crypto-tests-tools 0.1.0", "dup-crypto-tests-tools 0.1.0",
"failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"json-pest-parser 0.2.0", "json-pest-parser 0.2.0",
...@@ -748,7 +748,7 @@ dependencies = [ ...@@ -748,7 +748,7 @@ dependencies = [
name = "dubp-common-doc" name = "dubp-common-doc"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"dup-crypto 0.8.0", "dup-crypto 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"durs-common-tools 0.2.0", "durs-common-tools 0.2.0",
"failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"json-pest-parser 0.2.0", "json-pest-parser 0.2.0",
...@@ -780,7 +780,7 @@ dependencies = [ ...@@ -780,7 +780,7 @@ dependencies = [
"dubp-common-doc 0.1.0", "dubp-common-doc 0.1.0",
"dubp-currency-params 0.2.0", "dubp-currency-params 0.2.0",
"dubp-user-docs 0.14.0", "dubp-user-docs 0.14.0",
"dup-crypto 0.8.0", "dup-crypto 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"durs-common-tools 0.2.0", "durs-common-tools 0.2.0",
"failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
...@@ -795,7 +795,7 @@ name = "dubp-user-docs" ...@@ -795,7 +795,7 @@ name = "dubp-user-docs"
version = "0.14.0" version = "0.14.0"
dependencies = [ dependencies = [
"dubp-common-doc 0.1.0", "dubp-common-doc 0.1.0",
"dup-crypto 0.8.0", "dup-crypto 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"durs-common-tools 0.2.0", "durs-common-tools 0.2.0",
"failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"json-pest-parser 0.2.0", "json-pest-parser 0.2.0",
...@@ -817,7 +817,7 @@ dependencies = [ ...@@ -817,7 +817,7 @@ dependencies = [
"dubp-common-doc 0.1.0", "dubp-common-doc 0.1.0",
"dubp-currency-params 0.2.0", "dubp-currency-params 0.2.0",
"dubp-user-docs 0.14.0", "dubp-user-docs 0.14.0",
"dup-crypto 0.8.0", "dup-crypto 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"dup-crypto-tests-tools 0.1.0", "dup-crypto-tests-tools 0.1.0",
] ]
...@@ -839,9 +839,9 @@ dependencies = [ ...@@ -839,9 +839,9 @@ dependencies = [
[[package]] [[package]]
name = "dup-crypto" name = "dup-crypto"
version = "0.8.0" version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"base64 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "base64 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"bincode 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"bs58 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "bs58 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"ring 0.16.9 (registry+https://github.com/rust-lang/crates.io-index)", "ring 0.16.9 (registry+https://github.com/rust-lang/crates.io-index)",
...@@ -856,7 +856,7 @@ dependencies = [ ...@@ -856,7 +856,7 @@ dependencies = [
name = "dup-crypto-tests-tools" name = "dup-crypto-tests-tools"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"dup-crypto 0.8.0", "dup-crypto 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]] [[package]]
...@@ -869,7 +869,7 @@ dependencies = [ ...@@ -869,7 +869,7 @@ dependencies = [
"dubp-currency-params 0.2.0", "dubp-currency-params 0.2.0",
"dubp-user-docs 0.14.0", "dubp-user-docs 0.14.0",
"dubp-user-docs-tests-tools 0.1.0", "dubp-user-docs-tests-tools 0.1.0",
"dup-crypto 0.8.0", "dup-crypto 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"dup-crypto-tests-tools 0.1.0", "dup-crypto-tests-tools 0.1.0",
"durs-bc-db-reader 0.3.0-dev", "durs-bc-db-reader 0.3.0-dev",
"durs-bc-db-writer 0.3.0-dev", "durs-bc-db-writer 0.3.0-dev",
...@@ -909,7 +909,7 @@ dependencies = [ ...@@ -909,7 +909,7 @@ dependencies = [
"dubp-indexes 0.1.0", "dubp-indexes 0.1.0",
"dubp-user-docs 0.14.0", "dubp-user-docs 0.14.0",
"dubp-user-docs-tests-tools 0.1.0", "dubp-user-docs-tests-tools 0.1.0",
"dup-crypto 0.8.0", "dup-crypto 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"dup-crypto-tests-tools 0.1.0", "dup-crypto-tests-tools 0.1.0",
"durs-common-tests-tools 0.1.0", "durs-common-tests-tools 0.1.0",
"durs-common-tools 0.2.0", "durs-common-tools 0.2.0",
...@@ -936,7 +936,7 @@ dependencies = [ ...@@ -936,7 +936,7 @@ dependencies = [
"dubp-indexes 0.1.0", "dubp-indexes 0.1.0",
"dubp-user-docs 0.14.0", "dubp-user-docs 0.14.0",
"dubp-user-docs-tests-tools 0.1.0", "dubp-user-docs-tests-tools 0.1.0",
"dup-crypto 0.8.0", "dup-crypto 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"dup-crypto-tests-tools 0.1.0", "dup-crypto-tests-tools 0.1.0",
"durs-bc-db-reader 0.3.0-dev", "durs-bc-db-reader 0.3.0-dev",
"durs-common-tests-tools 0.1.0", "durs-common-tests-tools 0.1.0",
...@@ -975,7 +975,7 @@ dependencies = [ ...@@ -975,7 +975,7 @@ dependencies = [
"dirs 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "dirs 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"dubp-currency-params 0.2.0", "dubp-currency-params 0.2.0",
"dubp-user-docs 0.14.0", "dubp-user-docs 0.14.0",
"dup-crypto 0.8.0", "dup-crypto 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"durs-common-tools 0.2.0", "durs-common-tools 0.2.0",
"durs-message 0.3.0-dev", "durs-message 0.3.0-dev",
"durs-module 0.3.0-dev", "durs-module 0.3.0-dev",
...@@ -998,7 +998,7 @@ dependencies = [ ...@@ -998,7 +998,7 @@ dependencies = [
"chrono 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", "chrono 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)",
"clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)",
"dubp-currency-params 0.2.0", "dubp-currency-params 0.2.0",
"dup-crypto 0.8.0", "dup-crypto 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"durs-bc 0.3.0-dev", "durs-bc 0.3.0-dev",
"durs-bc-db-reader 0.3.0-dev", "durs-bc-db-reader 0.3.0-dev",
"durs-common-tools 0.2.0", "durs-common-tools 0.2.0",
...@@ -1047,7 +1047,7 @@ dependencies = [ ...@@ -1047,7 +1047,7 @@ dependencies = [
"dubp-blocks-tests-tools 0.1.0", "dubp-blocks-tests-tools 0.1.0",
"dubp-common-doc 0.1.0", "dubp-common-doc 0.1.0",
"dubp-currency-params 0.2.0", "dubp-currency-params 0.2.0",
"dup-crypto 0.8.0", "dup-crypto 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"dup-crypto-tests-tools 0.1.0", "dup-crypto-tests-tools 0.1.0",
"durs-bc-db-reader 0.3.0-dev", "durs-bc-db-reader 0.3.0-dev",
"durs-common-tools 0.2.0", "durs-common-tools 0.2.0",
...@@ -1075,7 +1075,7 @@ dependencies = [ ...@@ -1075,7 +1075,7 @@ dependencies = [
"dubp-common-doc 0.1.0", "dubp-common-doc 0.1.0",
"dubp-currency-params 0.2.0", "dubp-currency-params 0.2.0",
"dubp-user-docs 0.14.0", "dubp-user-docs 0.14.0",
"dup-crypto 0.8.0", "dup-crypto 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"durs-module 0.3.0-dev", "durs-module 0.3.0-dev",
"durs-network 0.3.0-dev", "durs-network 0.3.0-dev",
"durs-network-documents 0.4.0", "durs-network-documents 0.4.0",
...@@ -1090,7 +1090,7 @@ version = "0.3.0-dev" ...@@ -1090,7 +1090,7 @@ version = "0.3.0-dev"
dependencies = [ dependencies = [
"dubp-currency-params 0.2.0", "dubp-currency-params 0.2.0",
"dubp-user-docs 0.14.0", "dubp-user-docs 0.14.0",
"dup-crypto 0.8.0", "dup-crypto 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"durs-common-tools 0.2.0", "durs-common-tools 0.2.0",
"durs-network-documents 0.4.0", "durs-network-documents 0.4.0",
"envy 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "envy 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
...@@ -1109,7 +1109,7 @@ dependencies = [ ...@@ -1109,7 +1109,7 @@ dependencies = [
"dubp-block-doc 0.1.0", "dubp-block-doc 0.1.0",
"dubp-common-doc 0.1.0", "dubp-common-doc 0.1.0",
"dubp-user-docs 0.14.0", "dubp-user-docs 0.14.0",
"dup-crypto 0.8.0", "dup-crypto 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"durs-common-tools 0.2.0", "durs-common-tools 0.2.0",
"durs-module 0.3.0-dev", "durs-module 0.3.0-dev",
"durs-network-documents 0.4.0", "durs-network-documents 0.4.0",
...@@ -1128,7 +1128,7 @@ dependencies = [ ...@@ -1128,7 +1128,7 @@ dependencies = [
"dubp-common-doc 0.1.0", "dubp-common-doc 0.1.0",
"dubp-currency-params 0.2.0", "dubp-currency-params 0.2.0",
"dubp-user-docs 0.14.0", "dubp-user-docs 0.14.0",
"dup-crypto 0.8.0", "dup-crypto 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"durs-common-tests-tools 0.1.0", "durs-common-tests-tools 0.1.0",
"durs-common-tools 0.2.0", "durs-common-tools 0.2.0",
"failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
...@@ -1150,7 +1150,7 @@ version = "0.1.0" ...@@ -1150,7 +1150,7 @@ version = "0.1.0"
dependencies = [ dependencies = [
"dubp-currency-params 0.2.0", "dubp-currency-params 0.2.0",
"dubp-user-docs 0.14.0", "dubp-user-docs 0.14.0",
"dup-crypto 0.8.0", "dup-crypto 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"durs-common-tools 0.2.0", "durs-common-tools 0.2.0",
"durs-conf 0.3.0-dev", "durs-conf 0.3.0-dev",
"durs-message 0.3.0-dev", "durs-message 0.3.0-dev",
...@@ -1170,7 +1170,7 @@ version = "0.3.0-dev" ...@@ -1170,7 +1170,7 @@ version = "0.3.0-dev"
dependencies = [ dependencies = [
"dubp-currency-params 0.2.0", "dubp-currency-params 0.2.0",
"dubp-user-docs 0.14.0", "dubp-user-docs 0.14.0",
"dup-crypto 0.8.0", "dup-crypto 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"durs-common-tools 0.2.0", "durs-common-tools 0.2.0",
"durs-conf 0.3.0-dev", "durs-conf 0.3.0-dev",
"durs-message 0.3.0-dev", "durs-message 0.3.0-dev",
...@@ -1191,7 +1191,7 @@ name = "durs-wot" ...@@ -1191,7 +1191,7 @@ name = "durs-wot"
version = "0.8.0-a0.9" version = "0.8.0-a0.9"
dependencies = [ dependencies = [
"bincode 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "bincode 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"dup-crypto 0.8.0", "dup-crypto 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"durs-common-tools 0.2.0", "durs-common-tools 0.2.0",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"rayon 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
...@@ -1206,7 +1206,7 @@ dependencies = [ ...@@ -1206,7 +1206,7 @@ dependencies = [
"dubp-common-doc 0.1.0", "dubp-common-doc 0.1.0",
"dubp-currency-params 0.2.0", "dubp-currency-params 0.2.0",
"dubp-user-docs 0.14.0", "dubp-user-docs 0.14.0",
"dup-crypto 0.8.0", "dup-crypto 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"durs-common-tests-tools 0.1.0", "durs-common-tests-tools 0.1.0",
"durs-common-tools 0.2.0", "durs-common-tools 0.2.0",
"durs-conf 0.3.0-dev", "durs-conf 0.3.0-dev",
...@@ -1238,7 +1238,7 @@ dependencies = [ ...@@ -1238,7 +1238,7 @@ dependencies = [
"dubp-common-doc 0.1.0", "dubp-common-doc 0.1.0",
"dubp-currency-params 0.2.0", "dubp-currency-params 0.2.0",
"dubp-user-docs 0.14.0", "dubp-user-docs 0.14.0",
"dup-crypto 0.8.0", "dup-crypto 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"durs-common-tools 0.2.0", "durs-common-tools 0.2.0",
"durs-network-documents 0.4.0", "durs-network-documents 0.4.0",
"failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
...@@ -1257,7 +1257,7 @@ dependencies = [ ...@@ -1257,7 +1257,7 @@ dependencies = [
"dubp-common-doc 0.1.0", "dubp-common-doc 0.1.0",
"dubp-currency-params 0.2.0", "dubp-currency-params 0.2.0",
"dubp-user-docs 0.14.0", "dubp-user-docs 0.14.0",
"dup-crypto 0.8.0", "dup-crypto 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"durs-common-tools 0.2.0", "durs-common-tools 0.2.0",
"durs-module 0.3.0-dev", "durs-module 0.3.0-dev",
"durs-network-documents 0.4.0", "durs-network-documents 0.4.0",
...@@ -1279,7 +1279,7 @@ dependencies = [ ...@@ -1279,7 +1279,7 @@ dependencies = [
"dubp-common-doc 0.1.0", "dubp-common-doc 0.1.0",
"dubp-currency-params 0.2.0", "dubp-currency-params 0.2.0",
"dubp-user-docs 0.14.0", "dubp-user-docs 0.14.0",
"dup-crypto 0.8.0", "dup-crypto 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"durs-common-tools 0.2.0", "durs-common-tools 0.2.0",
"durs-conf 0.3.0-dev", "durs-conf 0.3.0-dev",
"durs-message 0.3.0-dev", "durs-message 0.3.0-dev",
...@@ -3199,6 +3199,7 @@ dependencies = [ ...@@ -3199,6 +3199,7 @@ dependencies = [
"checksum dirs-sys 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "afa0b23de8fd801745c471deffa6e12d248f962c9fd4b4c33787b055599bde7b" "checksum dirs-sys 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "afa0b23de8fd801745c471deffa6e12d248f962c9fd4b4c33787b055599bde7b"
"checksum downcast 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4bb454f0228b18c7f4c3b0ebbee346ed9c52e7443b0999cd543ff3571205701d" "checksum downcast 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4bb454f0228b18c7f4c3b0ebbee346ed9c52e7443b0999cd543ff3571205701d"
"checksum dtoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "ea57b42383d091c85abcc2706240b94ab2a8fa1fc81c10ff23c4de06e2a90b5e" "checksum dtoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "ea57b42383d091c85abcc2706240b94ab2a8fa1fc81c10ff23c4de06e2a90b5e"
"checksum dup-crypto 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6dddcce79edf70a20334a520d6a467404d8b6a44cea109ea4b50c36884e5c2d8"
"checksum either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3" "checksum either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3"
"checksum encoding_rs 0.8.22 (registry+https://github.com/rust-lang/crates.io-index)" = "cd8d03faa7fe0c1431609dfad7bbe827af30f82e1e2ae6f7ee4fca6bd764bc28" "checksum encoding_rs 0.8.22 (registry+https://github.com/rust-lang/crates.io-index)" = "cd8d03faa7fe0c1431609dfad7bbe827af30f82e1e2ae6f7ee4fca6bd764bc28"
"checksum enum-as-inner 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "900a6c7fbe523f4c2884eaf26b57b81bb69b6810a01a236390a7ac021d09492e" "checksum enum-as-inner 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "900a6c7fbe523f4c2884eaf26b57b81bb69b6810a01a236390a7ac021d09492e"
......
...@@ -6,7 +6,6 @@ members = [ ...@@ -6,7 +6,6 @@ members = [
"lib/core/message", "lib/core/message",
"lib/core/module", "lib/core/module",
"lib/core/network", "lib/core/network",
"lib/crypto",
"lib/dubp/block-doc", "lib/dubp/block-doc",
"lib/dubp/common-doc", "lib/dubp/common-doc",
"lib/dubp/currency-params", "lib/dubp/currency-params",
......
...@@ -11,7 +11,7 @@ path = "src/lib.rs" ...@@ -11,7 +11,7 @@ path = "src/lib.rs"
[dependencies] [dependencies]
dirs = "2.0.2" dirs = "2.0.2"
dup-crypto = { path = "../../crypto" } dup-crypto = "0.8.0"
dubp-currency-params = { path = "../../dubp/currency-params" } dubp-currency-params = { path = "../../dubp/currency-params" }
dubp-user-docs= { path = "../../dubp/user-docs" } dubp-user-docs= { path = "../../dubp/user-docs" }
durs-message = { path = "../message" } durs-message = { path = "../message" }
......
...@@ -17,7 +17,7 @@ durs-common-tools = { path = "../../tools/common-tools" } ...@@ -17,7 +17,7 @@ durs-common-tools = { path = "../../tools/common-tools" }
durs-bc-db-reader = { path = "../../modules-lib/bc-db-reader" } durs-bc-db-reader = { path = "../../modules-lib/bc-db-reader" }
durs-conf = { path = "../conf" } durs-conf = { path = "../conf" }
durs-dbs-tools = { path = "../../tools/dbs-tools" } durs-dbs-tools = { path = "../../tools/dbs-tools" }
dup-crypto = { path = "../../crypto" } dup-crypto = "0.8.0"
dubp-currency-params = { path = "../../dubp/currency-params" } dubp-currency-params = { path = "../../dubp/currency-params" }
durs-message = { path = "../message" } durs-message = { path = "../message" }
durs-module = { path = "../module" } durs-module = { path = "../module" }
......
...@@ -14,7 +14,7 @@ dubp-block-doc = { path = "../../dubp/block-doc"} #, version = "0.1.0" } ...@@ -14,7 +14,7 @@ dubp-block-doc = { path = "../../dubp/block-doc"} #, version = "0.1.0" }
dubp-common-doc = { path = "../../dubp/common-doc"} #, version = "0.1.0" } dubp-common-doc = { path = "../../dubp/common-doc"} #, version = "0.1.0" }
dubp-currency-params = { path = "../../dubp/currency-params" } dubp-currency-params = { path = "../../dubp/currency-params" }
dubp-user-docs= { path = "../../dubp/user-docs" } dubp-user-docs= { path = "../../dubp/user-docs" }
dup-crypto = { path = "../../crypto" } dup-crypto = "0.8.0"
durs-module = { path = "../module" } durs-module = { path = "../module" }
durs-network = { path = "../network" } durs-network = { path = "../network" }
durs-network-documents = { path = "../../dunp/network-documents" } durs-network-documents = { path = "../../dunp/network-documents" }
......
...@@ -10,7 +10,7 @@ edition = "2018" ...@@ -10,7 +10,7 @@ edition = "2018"
path = "src/lib.rs" path = "src/lib.rs"
[dependencies] [dependencies]
dup-crypto = { path = "../../crypto" } dup-crypto = "0.8.0"
dubp-currency-params = { path = "../../dubp/currency-params" } dubp-currency-params = { path = "../../dubp/currency-params" }
dubp-user-docs = { path = "../../dubp/user-docs" } dubp-user-docs = { path = "../../dubp/user-docs" }
durs-common-tools = { path = "../../tools/common-tools" } durs-common-tools = { path = "../../tools/common-tools" }
......
...@@ -13,7 +13,7 @@ path = "lib.rs" ...@@ -13,7 +13,7 @@ path = "lib.rs"
dubp-block-doc = { path = "../../dubp/block-doc"} #, version = "0.1.0" } dubp-block-doc = { path = "../../dubp/block-doc"} #, version = "0.1.0" }
dubp-common-doc = { path = "../../dubp/common-doc"} #, version = "0.1.0" } dubp-common-doc = { path = "../../dubp/common-doc"} #, version = "0.1.0" }
dubp-user-docs= { path = "../../dubp/user-docs" } dubp-user-docs= { path = "../../dubp/user-docs" }
dup-crypto = { path = "../../crypto" } dup-crypto = "0.8.0"
durs-common-tools = { path = "../../tools/common-tools" } durs-common-tools = { path = "../../tools/common-tools" }
durs-module = { path = "../module" } durs-module = { path = "../module" }
durs-network-documents = { path = "../../dunp/network-documents" } durs-network-documents = { path = "../../dunp/network-documents" }
......
[package]
name = "dup-crypto"
version = "0.8.0"
authors = ["nanocryk <nanocryk@duniter.org>", "elois <elois@duniter.org>"]
description = "Manage cryptographic operations for DUPs (DUniter Protocols)."
repository = "https://git.duniter.org/nodes/rust/duniter-rs"
readme = "README.md"
keywords = ["duniter", "keys", "cryptography"]
license = "AGPL-3.0"
edition = "2018"
[lib]
path = "src/lib.rs"
[dependencies]
base64 = "0.11.0"
bs58 = "0.3.0"
byteorder = "1.3.2"
ring = "0.16.9"
scrypt = { version = "0.2", default-features = false }
serde = { version = "1.0.*", features = ["derive"] }
thiserror = "1.0.11"
unwrap = "1.2.1"
zeroize = { version = "1.1.0", features = ["zeroize_derive"] }
[dev-dependencies]
bincode = "1.2.0"
[features]
# crypto
`dup-crypto` is a crate managing cryptographic operations for the DUP (DUniter Protocol).
## How to use it
You can add `dup-crypto` as a `cargo` dependency in your Rust project.
// Copyright (C) 2017-2019 The AXIOM TEAM Association.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//! Provide base16 convertion tools
use crate::bases::BaseConvertionError;
/// Convert a hexadecimal string in an array of 32 bytes.
///
/// The hex string must only contains hex characters
/// and produce a 32 bytes value.
pub fn str_hex_to_32bytes(text: &str) -> Result<[u8; 32], BaseConvertionError> {
if text.len() != 64 {
Err(BaseConvertionError::InvalidLength {
expected: 64,
found: text.len(),
})
} else {
let mut bytes = [0u8; 32];
let chars: Vec<char> = text.chars().collect();
for i in 0..64 {
if i % 2 != 0 {
continue;
}
let byte1 = chars[i].to_digit(16);
let byte2 = chars[i + 1].to_digit(16);
if let Some(byte1) = byte1 {
if let Some(byte2) = byte2 {
let byte = ((byte1 as u8) << 4) | byte2 as u8;
bytes[i / 2] = byte;
} else {
return Err(BaseConvertionError::InvalidCharacter {
character: chars[i + 1],
offset: i + 1,
});
}
} else {
return Err(BaseConvertionError::InvalidCharacter {
character: chars[i],
offset: i,
});
}
}
Ok(bytes)
}
}
// Copyright (C) 2017-2019 The AXIOM TEAM Association.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//! Provide base58 convertion tools
use crate::bases::BaseConvertionError;
/// Convert to base58 string
pub trait ToBase58 {
/// Convert to base58 string
fn to_base58(&self) -> String;
}
/// Create an array of 32 bytes from a Base58 string.
pub fn str_base58_to_32bytes(base58_data: &str) -> Result<([u8; 32], usize), BaseConvertionError> {
match bs58::decode(base58_data).into_vec() {
Ok(result) => {
let len = result.len();
if len <= 32 {
let mut u8_array = [0; 32];
u8_array[..len].clone_from_slice(&result[..len]);
Ok((u8_array, len))
} else {
Err(BaseConvertionError::InvalidLength {
expected: 32,
found: len,
})
}
}
Err(bs58::decode::Error::InvalidCharacter { character, index }) => {
Err(BaseConvertionError::InvalidCharacter {
character,
offset: index,
})
}
Err(bs58::decode::Error::BufferTooSmall) => {
Err(BaseConvertionError::InvalidBaseConverterLength)
}
_ => Err(BaseConvertionError::UnknownError),
}
}
/// Create a Base58 string from a slice of bytes.
pub fn bytes_to_str_base58(bytes: &[u8]) -> String {
bs58::encode(bytes).into_string()
}
/*/// Create an array of 64bytes from a Base58 string.
pub fn str_base58_to_64bytes(base58_data: &str) -> Result<[u8; 64], BaseConvertionError> {
match base58_data.from_base58() {
Ok(result) => {
if result.len() == 64 {
let mut u8_array = [0; 64];
u8_array[..64].clone_from_slice(&result[..64]);
Ok(u8_array)
} else {
Err(BaseConvertionError::InvalidLength {
expected: 64,
found: result.len(),
})
}
}
Err(FromBase58Error::InvalidBase58Character(character, offset)) => {
Err(BaseConvertionError::InvalidCharacter { character, offset })
}
Err(FromBase58Error::InvalidBase58Length) => {
Err(BaseConvertionError::InvalidBaseConverterLength)
}
}
}*/
// Copyright (C) 2017-2019 The AXIOM TEAM Association.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//! Provide base64 convertion tools
use crate::bases::BaseConvertionError;
/// Create an array of 64 bytes from a Base64 string.
pub fn str_base64_to64bytes(base64_data: &str) -> Result<[u8; 64], BaseConvertionError> {
let result = base64::decode(base64_data)?;
if result.len() == 64 {
let mut u8_array = [0; 64];
u8_array[..64].clone_from_slice(&base64::decode(base64_data)?[..64]);
Ok(u8_array)
} else {
Err(BaseConvertionError::InvalidLength {
found: result.len(),
expected: 64,
})
}
}
// Copyright (C) 2017-2019 The AXIOM TEAM Association.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//! Provide base convertion tools
use thiserror::Error;
/// Base16 conversion tools
pub mod b16;
/// Base58 conversion tools
pub mod b58;
/// Base64 conversion tools
pub mod b64;
/// Errors enumeration for Base58/64 strings convertion.
#[derive(Clone, Copy, Debug, Error, Eq, PartialEq)]
pub enum BaseConvertionError {
#[error("Data have invalid key length : expected {expected:?}, found {found:?}.")]
/// Data have invalid length.
InvalidLength {
/// Expected length
expected: usize,
/// Actual length
found: usize,
},
#[error("Invalid character '{character:?}' at offset {offset:?}.")]
/// Base58/64 have an invalid character.
InvalidCharacter {
/// Character
character: char,
/// Offset (=position)
offset: usize,
},
#[error("Invalid base converter length.")]
/// Base58/64 have invalid lendth
InvalidBaseConverterLength,
#[error("Invalid last symbol '{symbol:?}' at offset {offset:?}.")]
/// Base64 have invalid last symbol (symbol, offset)
InvalidLastSymbol {
/// Symbol
symbol: u8,
/// Offset (=position)
offset: usize,
},
/// Unknown error
#[error("Unknown error.")]
UnknownError,
}
impl From<base64::DecodeError> for BaseConvertionError {
fn from(err: base64::DecodeError) -> Self {
match err {
base64::DecodeError::InvalidByte(offset, byte) => {
BaseConvertionError::InvalidCharacter {
character: byte as char,
offset,
}
}
base64::DecodeError::InvalidLength => BaseConvertionError::InvalidBaseConverterLength,
base64::DecodeError::InvalidLastSymbol(offset, symbol) => {
BaseConvertionError::InvalidLastSymbol { symbol, offset }
}
}
}
}
// Copyright (C) 2017-2019 The AXIOM TEAM Association.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//! Provide wrappers for cryptographic hashs
use crate::bases::*;
use crate::rand::UnspecifiedRandError;
use ring::{digest, rand};
use serde::{Deserialize, Serialize};
use std::fmt::{Debug, Display, Error, Formatter};
/// A hash wrapper.
///
/// A hash is often provided as string composed of 64 hexadecimal character (0 to 9 then A to F).
#[derive(Copy, Clone, Deserialize, Eq, Ord, PartialEq, PartialOrd, Hash, Serialize)]
pub struct Hash(pub [u8; 32]);
impl Display for Hash {
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
write!(f, "{}", self.to_hex())
}
}
impl Debug for Hash {
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
write!(f, "Hash({})", self)
}
}
impl Default for Hash {
fn default() -> Hash {
Hash([0; 32])
}
}
impl Hash {
/// Hash size (in bytes).
pub const SIZE_IN_BYTES: usize = 32;
/// Generate a random Hash
#[inline]
pub fn random() -> Result<Self, UnspecifiedRandError> {
let random_bytes = rand::generate::<[u8; 32]>(&rand::SystemRandom::new())
.map_err(|_| UnspecifiedRandError)?;
Ok(Hash(random_bytes.expose()))
}
/// Compute hash of any binary datas
pub fn compute(datas: &[u8]) -> Hash {
let mut hash_buffer = [0u8; 32];
hash_buffer.copy_from_slice(digest::digest(&digest::SHA256, datas).as_ref());
Hash(hash_buffer)
}
/// Compute hash of a string
pub fn compute_str(str_datas: &str) -> Hash {
Hash::compute(str_datas.as_bytes())
}
/// Convert Hash into bytes vector
pub fn to_bytes_vector(&self) -> Vec<u8> {
self.0.to_vec()
}
/// Convert a `Hash` to an hex string.
pub fn to_hex(&self) -> String {
let strings: Vec<String> = self.0.iter().map(|b| format!("{:02X}", b)).collect();
strings.join("")
}
/// Convert a hex string in a `Hash`.
///
/// The hex string must only contains hex characters
/// and produce a 32 bytes value.
#[inline]
pub fn from_hex(text: &str) -> Result<Hash, BaseConvertionError> {
Ok(Hash(b16::str_hex_to_32bytes(text)?))
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_hash_random() {
let hash1 = Hash::random();
let hash2 = Hash::random();
assert_ne!(hash1, hash2);
}
#[test]
fn test_hash_debug() {
assert_eq!(
"Hash(0000000000000000000000000000000000000000000000000000000000000000)".to_owned(),
format!("{:?}", Hash::default()),
);
}
#[test]
fn test_hash_to_bytes() {
assert_eq!(
vec![
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0
],
Hash::default().to_bytes_vector(),
);
}
#[test]
fn test_hash_computation() {
assert_eq!(
Hash::from_hex("2CF24DBA5FB0A30E26E83B2AC5B9E29E1B161E5C1FA7425E73043362938B9824")
.expect("dev err"),
Hash::compute(b"hello"),
);
assert_eq!(
Hash::from_hex("2CF24DBA5FB0A30E26E83B2AC5B9E29E1B161E5C1FA7425E73043362938B9824")
.expect("dev err"),
Hash::compute_str("hello"),
);
}
#[test]
fn test_hash_from_hex() {
assert_eq!(
Ok(Hash::default()),
Hash::from_hex("0000000000000000000000000000000000000000000000000000000000000000")
);
assert_eq!(
Err(BaseConvertionError::InvalidLength {
expected: 64,
found: 65,
}),
Hash::from_hex("00000000000000000000000000000000000000000000000000000000000000000")
);
assert_eq!(
Err(BaseConvertionError::InvalidCharacter {
character: '_',
offset: 0,
}),
Hash::from_hex("_000000000000000000000000000000000000000000000000000000000000000")
);
assert_eq!(
Err(BaseConvertionError::InvalidCharacter {
character: '_',
offset: 1,
}),
Hash::from_hex("0_00000000000000000000000000000000000000000000000000000000000000")
);
}
}
// Copyright (C) 2017-2019 The AXIOM TEAM Association.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//! Generic code for signing data in binary format
use super::*;
use serde::{Deserialize, Serialize};
/// Signatureable in binary format
pub trait BinSignable<'de>: Serialize + Deserialize<'de> {
/// Error when serialize self into binary
type SerdeError: std::error::Error;
/// Return entity issuer pubkey
fn issuer_pubkey(&self) -> PubKey;
/// Return signature
fn signature(&self) -> Option<Sig>;
/// Change signature
fn set_signature(&mut self, _signature: Sig);
/// Get binary datas without signature
fn get_bin_without_sig(&self) -> Result<Vec<u8>, Self::SerdeError>;
/// Add signature to bin datas
fn add_sig_to_bin_datas(&self, bin_datas: &mut Vec<u8>);
/// Sign entity with a signator
fn sign(&mut self, signator: &SignatorEnum) -> Result<Vec<u8>, SignError> {
if self.signature().is_some() {
return Err(SignError::AlreadySign);
}
match self.issuer_pubkey() {
PubKey::Ed25519(_) => {
let mut bin_msg = self
.get_bin_without_sig()
.map_err(|e| SignError::SerdeError(e.to_string()))?;
let sig = signator.sign(&bin_msg);
self.set_signature(sig);
self.add_sig_to_bin_datas(&mut bin_msg);
Ok(bin_msg)
}
_ => Err(SignError::WrongAlgo),
}
}
/// Check signature of entity
fn verify(&self) -> Result<(), SigError> {
if let Some(signature) = self.signature() {
match self.issuer_pubkey() {
PubKey::Ed25519(pubkey) => match signature {
Sig::Ed25519(sig) => {
let signed_part: Vec<u8> = self
.get_bin_without_sig()
.map_err(|e| SigError::SerdeError(format!("{}", e)))?;
pubkey.verify(&signed_part, &sig)
/*
if pubkey.verify(&signed_part, &sig) {
Ok(())
} else {
Err(SigError::InvalidSig())
}
*/
}
_ => Err(SigError::NotSameAlgo),
},
_ => Err(SigError::NotSameAlgo),
}
} else {
Err(SigError::NotSig)
}
}
}
#[cfg(test)]
mod tests {
use super::*;
use bincode;
#[derive(Deserialize, Serialize)]
struct BinSignableTestImpl {
datas: Vec<u8>,
issuer: PubKey,
sig: Option<Sig>,
}
impl BinSignable<'_> for BinSignableTestImpl {
type SerdeError = bincode::Error;
#[inline]
fn add_sig_to_bin_datas(&self, bin_datas: &mut Vec<u8>) {
bin_datas
.extend_from_slice(&bincode::serialize(&self.sig).expect("Fail to binarize sig !"));
}
#[inline]
fn get_bin_without_sig(&self) -> Result<Vec<u8>, bincode::Error> {
let mut bin_msg = bincode::serialize(&self)?;
let sig_size = bincode::serialized_size(&self.signature())?;
let bin_msg_len = bin_msg.len();
bin_msg.truncate(bin_msg_len - (sig_size as usize));
Ok(bin_msg)
}
fn issuer_pubkey(&self) -> PubKey {
self.issuer
}
fn signature(&self) -> Option<Sig> {
self.sig
}
fn set_signature(&mut self, new_signature: Sig) {
self.sig = Some(new_signature);
}
}
#[test]
fn test_bin_signable() {
let key_pair = ed25519::KeyPairFromSeed32Generator::generate(Seed32::new([
0u8, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14, 15,
]));
let signator = SignatorEnum::Ed25519(
key_pair
.generate_signator()
.expect("fail to generate signator !"),
);
let mut bin_signable_datas = BinSignableTestImpl {
datas: vec![0, 1, 2, 3],
issuer: PubKey::Ed25519(key_pair.pubkey),
sig: None,
};
assert_eq!(Err(SigError::NotSig), bin_signable_datas.verify());
let _bin_msg = bin_signable_datas
.sign(&signator)
.expect("Fail to sign datas !");
assert_eq!(
Err(SignError::AlreadySign),
bin_signable_datas.sign(&signator)
);
assert_eq!(Ok(()), bin_signable_datas.verify())
}
}
This diff is collapsed.
This diff is collapsed.
// Copyright (C) 2017-2019 The AXIOM TEAM Association.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//! Generic code for signing data in text format
use super::*;
/// Signatureable in text format
pub trait TextSignable: Debug + Clone {
/// Return signable text
fn as_signable_text(&self) -> String;
/// Return entity issuer pubkey
fn issuer_pubkey(&self) -> PubKey;
/// Return entity signature
fn signature(&self) -> Option<Sig>;
/// Change signature
fn set_signature(&mut self, _signature: Sig);
/// Sign entity
fn sign(&mut self, signator: &SignatorEnum) -> Result<String, SignError> {
if self.signature().is_some() {
return Err(SignError::AlreadySign);
}
match self.issuer_pubkey() {
PubKey::Ed25519(_) => match signator {
SignatorEnum::Ed25519(ed25519_signator) => {
let text = self.as_signable_text();
let sig = ed25519_signator.sign(&text.as_bytes());
self.set_signature(Sig::Ed25519(sig));
let str_sig = sig.to_base64();
Ok(format!("{}{}", text, str_sig))
}
_ => Err(SignError::WrongAlgo),
},
_ => Err(SignError::WrongAlgo),
}
}
/// Check signature of entity
fn verify(&self) -> Result<(), SigError> {
if let Some(signature) = self.signature() {
match self.issuer_pubkey() {
PubKey::Ed25519(pubkey) => match signature {
Sig::Ed25519(sig) => {
pubkey.verify(&self.as_signable_text().as_bytes(), &sig)
/*
if pubkey.verify(&self.as_signable_text().as_bytes(), &sig) {
Ok(())
} else {
Err(SigError::InvalidSig())
}
*/
}
_ => Err(SigError::NotSameAlgo),
},
_ => Err(SigError::NotSameAlgo),
}
} else {
Err(SigError::NotSig)
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[derive(Debug, Clone)]
struct TextSignableTestImpl {
issuer: PubKey,
text: String,
sig: Option<Sig>,
}
impl TextSignable for TextSignableTestImpl {
fn as_signable_text(&self) -> String {
format!("{}:{}", self.issuer, self.text)
}
fn issuer_pubkey(&self) -> PubKey {
self.issuer
}
fn signature(&self) -> Option<Sig> {
self.sig
}
fn set_signature(&mut self, new_signature: Sig) {
self.sig = Some(new_signature);
}
}
#[test]
fn test_text_signable() {
let key_pair = super::super::tests::valid_key_pair_1();
let signator = key_pair
.generate_signator()
.expect("fail to generate signator");
let mut text_signable = TextSignableTestImpl {
issuer: key_pair.public_key(),
text: "toto".to_owned(),
sig: None,
};
assert_eq!(Err(SigError::NotSig), text_signable.verify());
assert_eq!(
Err(SignError::WrongAlgo),
text_signable.sign(&SignatorEnum::Schnorr())
);
text_signable.issuer = PubKey::Schnorr();
assert_eq!(Err(SignError::WrongAlgo), text_signable.sign(&signator));
text_signable.issuer = key_pair.public_key();
assert_eq!(
Ok("VYgskcKKh525MzFRzpCiT5KXCQrnFLTnzMLffbvm9uw:toto+IC1fFkkYo5ox2loc1IMLCtrir1i6oyljfshNXIyXVcz6sJMFqn+6o8Zip4XdTzoBEORkbcnEnqQEr4TgaHpCw==".to_owned()),
text_signable.sign(&signator)
);
assert_eq!(Err(SignError::AlreadySign), text_signable.sign(&signator));
assert_eq!(Ok(()), text_signable.verify());
let old_sig = text_signable.sig.replace(Sig::Schnorr());
assert_eq!(Err(SigError::NotSameAlgo), text_signable.verify());
text_signable.sig = old_sig;
text_signable.issuer = PubKey::Schnorr();
assert_eq!(Err(SigError::NotSameAlgo), text_signable.verify());
}
}
// Copyright (C) 2017-2019 The AXIOM TEAM Association.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//! Manage cryptographic operations.
#![deny(
clippy::option_unwrap_used,
clippy::result_unwrap_used,
missing_docs,
missing_copy_implementations,
trivial_casts,
trivial_numeric_casts,
unsafe_code,
unstable_features,
unused_import_braces,
unused_qualifications
)]
#![allow(non_camel_case_types)]
pub mod bases;
pub mod hashs;
pub mod keys;
pub mod rand;
pub mod seeds;
// Copyright (C) 2017-2019 The AXIOM TEAM Association.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//! Manage random generation.
use byteorder::ByteOrder;
use ring::rand;
/// An error with absolutely no details.
///
/// *dup-crypto* uses this unit type as the error type in most of its results
/// because (a) usually the specific reasons for a failure are obvious or are
/// not useful to know, and/or (b) providing more details about a failure might
/// provide a dangerous side channel, and/or (c) it greatly simplifies the
/// error handling logic.
///
/// Experience with using and implementing other crypto libraries like has
/// shown that sophisticated error reporting facilities often cause significant
/// bugs themselves, both within the crypto library and within users of the
/// crypto library. This approach attempts to minimize complexity in the hopes
/// of avoiding such problems. In some cases, this approach may be too extreme,
/// and it may be important for an operation to provide some details about the
/// cause of a failure. Users of *dup-crypto* are encouraged to report such cases so
/// that they can be addressed individually.
#[derive(Copy, Clone, Debug, PartialEq)]
pub struct UnspecifiedRandError;
#[inline]
/// Generate random u32
pub fn gen_u32() -> Result<u32, UnspecifiedRandError> {
let rng = rand::SystemRandom::new();
let random_bytes = rand::generate::<[u8; 4]>(&rng).map_err(|_| UnspecifiedRandError)?;
Ok(byteorder::BigEndian::read_u32(&random_bytes.expose()))
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_gen_u32() {
assert_ne!(gen_u32(), gen_u32())
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment