diff options
-rw-r--r-- | Cargo.lock | 300 | ||||
-rw-r--r-- | lockchain-core/Cargo.toml | 7 | ||||
-rw-r--r-- | lockchain-core/src/lib.rs | 11 | ||||
-rw-r--r-- | lockchain-core/src/record.rs | 17 | ||||
-rw-r--r-- | lockchain-core/src/traits.rs | 54 | ||||
-rw-r--r-- | lockchain-core/src/users.rs | 23 | ||||
-rw-r--r-- | lockchain-crypto/Cargo.toml | 6 | ||||
-rw-r--r-- | lockchain-crypto/src/lib.rs | 45 |
8 files changed, 419 insertions, 44 deletions
@@ -1,15 +1,169 @@ [[package]] +name = "aesni" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "block-cipher-trait 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "opaque-debug 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "base64" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "byteorder 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "safemem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "base64" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "byteorder 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "safemem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "bcrypt" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "base64 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", + "blowfish 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "byte-tools 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "bitflags" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "block-cipher-trait" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "generic-array 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "blowfish" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "block-cipher-trait 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "byte-tools 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "opaque-debug 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "byte-tools" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "byteorder" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "cc" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] name = "chrono" version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "num-integer 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.38 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] +name = "clear_on_drop" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cc 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "cmac" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "block-cipher-trait 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "crypto-mac 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "dbl 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "constant_time_eq" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "crypto-mac" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "constant_time_eq 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "generic-array 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "dbl" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "generic-array 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "dtoa" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "fuchsia-zircon" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "fuchsia-zircon-sys" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "generic-array" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "typenum 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "itoa" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "lazy_static" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] name = "libc" version = "0.2.40" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -20,16 +174,25 @@ version = "0.1.0" [[package]] name = "lockchain-core" -version = "0.3.0" +version = "0.3.1" dependencies = [ + "base64 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "bcrypt 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "chrono 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.38 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.38 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "lockchain-crypto" version = "0.1.0" +dependencies = [ + "lockchain-core 0.3.1", + "miscreant 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)", +] [[package]] name = "lockchain-files" @@ -44,6 +207,23 @@ name = "lockchain-server" version = "0.1.0" [[package]] +name = "miscreant" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "aesni 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "block-cipher-trait 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "clear_on_drop 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "cmac 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "crypto-mac 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "dbl 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "generic-array 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "pmac 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "subtle 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] name = "num-integer" version = "0.1.36" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -57,8 +237,23 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] +name = "opaque-debug" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "pmac" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "block-cipher-trait 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "crypto-mac 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "dbl 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] name = "proc-macro2" -version = "0.3.6" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -66,10 +261,20 @@ dependencies = [ [[package]] name = "quote" -version = "0.5.1" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rand" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -78,37 +283,47 @@ version = "0.1.37" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] +name = "safemem" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] name = "serde" -version = "1.0.38" +version = "1.0.50" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "serde_derive" -version = "1.0.38" +version = "1.0.50" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive_internals 0.23.1 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.13.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] -name = "serde_derive_internals" -version = "0.23.1" +name = "serde_json" +version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)", + "dtoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "itoa 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] +name = "subtle" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] name = "syn" -version = "0.13.1" +version = "0.13.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -123,6 +338,11 @@ dependencies = [ ] [[package]] +name = "typenum" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] name = "unicode-xid" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -147,18 +367,46 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" [metadata] +"checksum aesni 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "5e88c3698cd61460af7bdbcc747d0e37b61255492fcfc81845dd4666f3bf6714" +"checksum base64 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7c4a342b450b268e1be8036311e2c613d7f8a7ed31214dff1cc3b60852a3168d" +"checksum base64 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9263aa6a38da271eec5c91a83ce1e800f093c8535788d403d626d8d5c3f8f007" +"checksum bcrypt 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1a1512813db09170b44a00870b58421876d797b77b085c5205a24db90905f758" +"checksum bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d0c54bb8f454c567f21197eefcdbf5679d0bd99f2ddbe52e84c77061952e6789" +"checksum block-cipher-trait 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d6136d803280ae3532efa36114335255ea94f3d75d735ddedd66b0d7cd30bad3" +"checksum blowfish 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "95ede07672d9f4144c578439aa352604ec5c67a80c940fe8d382ddbeeeb3c6d8" +"checksum byte-tools 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "560c32574a12a89ecd91f5e742165893f86e3ab98d21f8ea548658eb9eef5f40" +"checksum byteorder 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "73b5bdfe7ee3ad0b99c9801d58807a9dbc9e09196365b0203853b99889ab3c87" +"checksum cc 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)" = "0ebb87d1116151416c0cf66a0e3fb6430cccd120fd6300794b4dfaa050ac40ba" "checksum chrono 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1cce36c92cb605414e9b824f866f5babe0a0368e39ea07393b9b63cf3844c0e6" +"checksum clear_on_drop 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "97276801e127ffb46b66ce23f35cc96bd454fa311294bced4bbace7baa8b1d17" +"checksum cmac 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "44f175b5f76aa82ebe4c7e85ef95b23e9293c5618db28461cb10ee929e0f6e2f" +"checksum constant_time_eq 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8ff012e225ce166d4422e0e78419d901719760f62ae2b7969ca6b564d1b54a9e" +"checksum crypto-mac 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "99376574a55849855052aa6e3b15f3bdebf8bcdd3b24f3cbc3371469bcd5b480" +"checksum dbl 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "920e117b69060a961c4164ccf83af573292cb167ccdd918950bcf0f5afc32c1c" +"checksum dtoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "09c3753c3db574d215cba4ea76018483895d7bff25a31b49ba45db21c48e50ab" +"checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" +"checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" +"checksum generic-array 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ef25c5683767570c2bbd7deba372926a55eaae9982d7726ee2a1050239d45b9d" +"checksum itoa 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c069bbec61e1ca5a596166e55dfe4773ff745c3d16b700013bcaff9a6df2c682" +"checksum lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c8f31047daa365f19be14b47c29df4f7c3b581832407daabe6ae77397619237d" "checksum libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)" = "6fd41f331ac7c5b8ac259b8bf82c75c0fb2e469bbf37d2becbba9a6a2221965b" +"checksum miscreant 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "345b52b06ce7a0e2fab0a0ea99ef52e81d63102ba0425b2914f1867b9d820628" "checksum num-integer 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)" = "f8d26da319fb45674985c78f1d1caf99aa4941f785d384a2ae36d0740bc3e2fe" "checksum num-traits 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dee092fcdf725aee04dd7da1d21debff559237d49ef1cb3e69bcb8ece44c7364" -"checksum proc-macro2 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "49b6a521dc81b643e9a51e0d1cf05df46d5a2f3c0280ea72bcb68276ba64a118" -"checksum quote 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7b0ff51282f28dc1b53fd154298feaa2e77c5ea0dba68e1fd8b03b72fbe13d2a" +"checksum opaque-debug 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d620c9c26834b34f039489ac0dfdb12c7ac15ccaf818350a64c9b5334a452ad7" +"checksum pmac 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0a82cc12454dc99354a9342c237149aec041ef16f618066d0a682df256b97714" +"checksum proc-macro2 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "1b06e2f335f48d24442b35a19df506a835fb3547bc3c06ef27340da9acf5cae7" +"checksum quote 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9949cfe66888ffe1d53e6ec9d9f3b70714083854be20fd5e271b232a017401e8" +"checksum rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "eba5f8cb59cc50ed56be8880a5c7b496bfd9bd26394e176bc67884094145c2c5" "checksum redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "0d92eecebad22b767915e4d529f89f28ee96dbbf5a4810d2b844373f136417fd" -"checksum serde 1.0.38 (registry+https://github.com/rust-lang/crates.io-index)" = "4c36359ac1a823e00db02a243376ced650f088dc1f6259bbf828e4668e3c7399" -"checksum serde_derive 1.0.38 (registry+https://github.com/rust-lang/crates.io-index)" = "f0477feff739386f5bca8e13fa43d96a4e834904d538f503906c8179f9205f50" -"checksum serde_derive_internals 0.23.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9d30c4596450fd7bbda79ef15559683f9a79ac0193ea819db90000d7e1cae794" -"checksum syn 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)" = "91b52877572087400e83d24b9178488541e3d535259e04ff17a63df1e5ceff59" +"checksum safemem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e27a8b19b835f7aea908818e871f5cc3a5a186550c30773be987e155e8163d8f" +"checksum serde 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)" = "428d3d818cb94ee037a17bf4f2200db2552e19b1825d33df2196624290716f92" +"checksum serde_derive 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)" = "ee76093b16868c4c9c8e5329c3d30745833e35390624019738472bd13e996e79" +"checksum serde_json 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)" = "f3ad6d546e765177cf3dded3c2e424a8040f870083a0e64064746b958ece9cb1" +"checksum subtle 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c7a6bab57c3efd01ebd3d750f4244ae0af4cdd1fc505a7904a41603192b803c5" +"checksum syn 0.13.7 (registry+https://github.com/rust-lang/crates.io-index)" = "61b8f1b737f929c6516ba46a3133fd6d5215ad8a62f66760f851f7048aebedfb" "checksum time 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "a15375f1df02096fb3317256ce2cee6a1f42fc84ea5ad5fc8c421cfe40c73098" +"checksum typenum 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "612d636f949607bdf9b123b4a6f6d966dedf3ff669f7f045890d3a4a73948169" "checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" "checksum winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "04e3bd221fcbe8a271359c04f21a76db7d0c6028862d1bb5512d85e1e2eb5bb3" "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" diff --git a/lockchain-core/Cargo.toml b/lockchain-core/Cargo.toml index ebff766..4c8a2e8 100644 --- a/lockchain-core/Cargo.toml +++ b/lockchain-core/Cargo.toml @@ -10,5 +10,10 @@ authors = ["Katharina Fey <kookie@spacekookie.de>"] [dependencies] chrono = { version = "0.4", features = ["serde"] } + serde_derive = "1.0" -serde = "1.0"
\ No newline at end of file +serde_json = "1.0" +serde = "1.0" + +base64 = "0.8" +bcrypt = "0.2" diff --git a/lockchain-core/src/lib.rs b/lockchain-core/src/lib.rs index 41fa380..87a5c60 100644 --- a/lockchain-core/src/lib.rs +++ b/lockchain-core/src/lib.rs @@ -4,13 +4,18 @@ #[macro_use] extern crate serde_derive; -extern crate chrono; +extern crate serde_json; extern crate serde; +extern crate chrono; +extern crate bcrypt; +extern crate base64; pub mod errors; -mod record; pub mod traits; +mod users; +mod record; mod vault; -pub use self::record::{Header, Payload, Record}; +pub use self::record::{Header, Payload, Record, EncryptedBody}; pub use self::vault::Vault; +pub use self::users::User;
\ No newline at end of file diff --git a/lockchain-core/src/record.rs b/lockchain-core/src/record.rs index 5245ad4..97f5fd2 100644 --- a/lockchain-core/src/record.rs +++ b/lockchain-core/src/record.rs @@ -93,3 +93,20 @@ impl<T: Body> Record<T> { (self.body.as_ref()?).get_field(key) } } + +#[derive(Serialize, Deserialize)] +pub struct EncryptedBody { + pub cipher: String, +} + +impl Body for EncryptedBody { + fn get_field(&self, _: &str) -> Option<&Payload> { + None + } + fn set_field(&mut self, _: &str, _: Payload) -> Option<()> { + None + } + fn flatten(&mut self) -> Option<()> { + None + } +} diff --git a/lockchain-core/src/traits.rs b/lockchain-core/src/traits.rs index 1f328dc..01ae484 100644 --- a/lockchain-core/src/traits.rs +++ b/lockchain-core/src/traits.rs @@ -1,18 +1,22 @@ //! Common vault traits for plugin-crates -//! +//! //! The core of this crate has no functionality and is dependant //! on other libraries to fill those holes. To make this easer //! (and sometimes possible), we defined a few common behaviours //! in traits to expand on in implementations specific to the //! library. -//! +//! //! Each trait is documented in more detail and provides default -//! implementations with `unimplemented!` macros to make +//! implementations with `unimplemented!` macros to make //! compilation work without external crates but not calling //! functions at runtime. +use record::{Header, Payload, EncryptedBody}; use serde::{de::DeserializeOwned, Serialize}; -use record::{Header, Payload}; +use users::User; + +use base64; +use serde_json; /// A Body trait that can be implemented to hook into the generic Record /// data module. @@ -27,7 +31,6 @@ pub trait Body: DeserializeOwned + Serialize { fn flatten(&mut self) -> Option<()>; } - /// A simple trait that allows libraries to hook into the /// `body()` and `record()` hooks for vault records. pub trait LoadRecord<T: Body> { @@ -40,15 +43,19 @@ pub trait LoadRecord<T: Body> { } } +pub trait UserLogin { + /// Login a user and return it with a token + fn login(name: &str, password: &str, salt: &str) -> Option<User>; +} /// This is a trait which needs to be implemented by any /// backend which hopes to do encryption on data. -pub trait Encryption: Body { - fn encrypt(&mut self) -> Vec<u8> { +pub trait Encryption: Body + AutoEncoder { + fn encrypt(&mut self) -> EncryptedBody { unimplemented!() } - fn decrypt(_data: Vec<u8>) -> Box<Self> { + fn decrypt(_enc: EncryptedBody) -> Box<Self> { unimplemented!() } } @@ -72,4 +79,33 @@ pub trait VaultLayer { fn fetch(&mut self); fn pull(&mut self, name: &str); fn sync(&mut self); -}
\ No newline at end of file +} + +/// Auto-implement this trait to serialise types to json +pub trait AutoEncoder: Serialize + DeserializeOwned { + fn encode(&self) -> String { + serde_json::to_string_pretty(self).unwrap() + } + + fn decode(s: &str) -> Self { + serde_json::from_str(s).unwrap() + } +} + +/// Include this trait to monkey-patch base64 functions onto String types +pub trait Base64AutoEncoder { + fn to_base64(&self) -> String; + fn from_base64(base64: &str) -> String; +} + +impl Base64AutoEncoder for String { + /// Automatically encode this string to base64 + fn to_base64(&self) -> String { + base64::encode(self.as_bytes()) + } + + /// Craft a string from an existing base64 string slice + fn from_base64(base64: &str) -> String { + String::from_utf8(base64::decode(base64).unwrap()).unwrap() + } +} diff --git a/lockchain-core/src/users.rs b/lockchain-core/src/users.rs new file mode 100644 index 0000000..9fd4476 --- /dev/null +++ b/lockchain-core/src/users.rs @@ -0,0 +1,23 @@ +//! A commonly used user-abstraction for the lockchain ecosystem + +use bcrypt::{self, DEFAULT_COST}; + +/// Simple user authentication abstraction +pub struct User { + name: String, + pw_hash: String, + pw_salt: String, + token: Option<String>, +} + +impl User { + /// + fn register(name: &str, password: &str, salt: &str) -> Option<User> { + Some(User { + name: name.to_owned(), + pw_hash: bcrypt::hash(&format!("{}{}", password, salt), DEFAULT_COST).ok()?, + pw_salt: salt.to_owned(), + token: None, + }) + } +} diff --git a/lockchain-crypto/Cargo.toml b/lockchain-crypto/Cargo.toml index b598a42..b028bd1 100644 --- a/lockchain-crypto/Cargo.toml +++ b/lockchain-crypto/Cargo.toml @@ -4,3 +4,9 @@ version = "0.1.0" authors = ["Katharina Fey <kookie@spacekookie.de>"] [dependencies] +lockchain-core = { path = "../lockchain-core" } +serde_derive = "1.0" +serde = "1.0" + +# Cryptography +miscreant = "^0.3" diff --git a/lockchain-crypto/src/lib.rs b/lockchain-crypto/src/lib.rs index 31e1bb2..5648106 100644 --- a/lockchain-crypto/src/lib.rs +++ b/lockchain-crypto/src/lib.rs @@ -1,7 +1,42 @@ -#[cfg(test)] -mod tests { - #[test] - fn it_works() { - assert_eq!(2 + 2, 4); +//! + +#[macro_use] +extern crate serde_derive; +extern crate serde; + +extern crate lockchain_core as lcc; + +use lcc::{Payload, EncryptedBody}; +use lcc::traits::{Body, AutoEncoder, Base64AutoEncoder, Encryption}; + +use std::collections::BTreeMap; + +#[derive(Serialize, Deserialize)] +pub struct DataBody { + tree: BTreeMap<String, Payload>, +} + +impl AutoEncoder for DataBody {} + +impl Body for DataBody { + fn get_field(&self, key: &str) -> Option<&Payload> { + self.tree.get(key).as_ref()? + } + + fn set_field(&mut self, key: &str, value: Payload) -> Option<()> { + self.tree.insert(key, value); + Some(()) + } + + fn flatten(&mut self) -> Option<()> { + None } } + +impl Encryption for DataBody { + fn encrypt(&mut self) -> EncryptedBody { + EncryptedBody { + cipher: self.encode() + } + } +}
\ No newline at end of file |