diff --git a/Cargo.lock b/Cargo.lock index 79d25e2..b920977 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,15 +1,75 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. [[package]] +name = "aead" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fc95d1bdb8e6666b2b217308eeeb09f2d6728d104be3e31916cc74d15420331" +dependencies = [ + "generic-array 0.14.4", +] + +[[package]] +name = "aes" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "884391ef1066acaa41e766ba8f596341b96e93ce34f9a43e7d24bf0a0eaf0561" +dependencies = [ + "aes-soft", + "aesni", + "cipher", +] + +[[package]] +name = "aes-gcm" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5278b5fabbb9bd46e24aa69b2fdea62c99088e0a950a9be40e3e0101298f88da" +dependencies = [ + "aead", + "aes", + "cipher", + "ctr", + "ghash", + "subtle", +] + +[[package]] +name = "aes-soft" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be14c7498ea50828a38d0e24a765ed2effe92a705885b57d029cd67d45744072" +dependencies = [ + "cipher", + "opaque-debug 0.3.0", +] + +[[package]] +name = "aesni" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea2e11f5e94c2f7d386164cc2aa1f97823fed6f259e486940a71c174dd01b0ce" +dependencies = [ + "cipher", + "opaque-debug 0.3.0", +] + +[[package]] name = "ansi_term" version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" dependencies = [ - "winapi 0.3.9", + "winapi", ] [[package]] +name = "anyhow" +version = "1.0.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c0df63cb2955042487fad3aefd2c6e3ae7389ac5dc1beb28921de0b69f779d4" + +[[package]] name = "arrayref" version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -22,6 +82,182 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" [[package]] +name = "async-attributes" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "efd3d156917d94862e779f356c5acae312b08fd3121e792c857d7928c8088423" +dependencies = [ + "quote", + "syn", +] + +[[package]] +name = "async-channel" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59740d83946db6a5af71ae25ddf9562c2b176b2ca42cf99a455f09f4a220d6b9" +dependencies = [ + "concurrent-queue", + "event-listener", + "futures-core", +] + +[[package]] +name = "async-executor" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb877970c7b440ead138f6321a3b5395d6061183af779340b65e20c0fede9146" +dependencies = [ + "async-task", + "concurrent-queue", + "fastrand", + "futures-lite", + "once_cell", + "vec-arena", +] + +[[package]] +name = "async-global-executor" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73079b49cd26b8fd5a15f68fc7707fc78698dc2a3d61430f2a7a9430230dfa04" +dependencies = [ + "async-executor", + "async-io", + "futures-lite", + "num_cpus", + "once_cell", +] + +[[package]] +name = "async-h1" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbd08aac4521ff179a4f91a0710729f0caf4d796fd913569d0613704e50da405" +dependencies = [ + "async-std", + "byte-pool", + "futures-core", + "http-types", + "httparse", + "lazy_static", + "log", + "pin-project", +] + +[[package]] +name = "async-io" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9315f8f07556761c3e48fec2e6b276004acf426e6dc068b2c2251854d65ee0fd" +dependencies = [ + "concurrent-queue", + "fastrand", + "futures-lite", + "libc", + "log", + "nb-connect", + "once_cell", + "parking", + "polling", + "vec-arena", + "waker-fn", + "winapi", +] + +[[package]] +name = "async-mutex" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "479db852db25d9dbf6204e6cb6253698f175c15726470f78af0d918e99d6156e" +dependencies = [ + "event-listener", +] + +[[package]] +name = "async-process" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c8cea09c1fb10a317d1b5af8024eeba256d6554763e85ecd90ff8df31c7bbda" +dependencies = [ + "async-io", + "blocking", + "cfg-if 0.1.10", + "event-listener", + "futures-lite", + "once_cell", + "signal-hook", + "winapi", +] + +[[package]] +name = "async-sse" +version = "4.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53bba003996b8fd22245cd0c59b869ba764188ed435392cf2796d03b805ade10" +dependencies = [ + "async-channel", + "async-std", + "http-types", + "log", + "memchr", + "pin-project-lite 0.1.11", +] + +[[package]] +name = "async-std" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f9f84f1280a2b436a2c77c2582602732b6c2f4321d5494d6e799e6c367859a8" +dependencies = [ + "async-attributes", + "async-channel", + "async-global-executor", + "async-io", + "async-mutex", + "async-process", + "blocking", + "crossbeam-utils 0.8.1", + "futures-channel", + "futures-core", + "futures-io", + "futures-lite", + "gloo-timers", + "kv-log-macro", + "log", + "memchr", + "num_cpus", + "once_cell", + "pin-project-lite 0.2.0", + "pin-utils", + "slab", + "wasm-bindgen-futures", +] + +[[package]] +name = "async-task" +version = "4.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e91831deabf0d6d7ec49552e489aed63b7456a7a3c46cff62adad428110b0af0" + +[[package]] +name = "async-trait" +version = "0.1.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d3a45e77e34375a7923b1e8febb049bb011f064714a8e17a1a616fef01da13d" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "atomic-waker" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "065374052e7df7ee4047b1160cca5e1467a12351a40b3da123c870ba0b8eda2a" + +[[package]] name = "atty" version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -29,7 +265,7 @@ checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" dependencies = [ "hermit-abi", "libc", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -39,6 +275,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" [[package]] +name = "base-x" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4521f3e3d031370679b3b140beb36dfe4801b09ac77e30c61941f97df3ef28b" + +[[package]] name = "base64" version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -108,12 +350,42 @@ dependencies = [ ] [[package]] +name = "blocking" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c5e170dbede1f740736619b776d7251cb1b9095c435c34d8ca9f57fcd2f335e9" +dependencies = [ + "async-channel", + "async-task", + "atomic-waker", + "fastrand", + "futures-lite", + "once_cell", +] + +[[package]] name = "bs58" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "771fe0050b883fcc3ea2359b1a96bcfbc090b7116eae7c3c512c7a083fdf23d3" [[package]] +name = "bumpalo" +version = "3.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e8c087f005730276d1096a652e92a8bacee2e2472bcc9715a74d2bec38b5820" + +[[package]] +name = "byte-pool" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38e98299d518ec351ca016363e0cbfc77059dcd08dfa9700d15e405536097a" +dependencies = [ + "crossbeam-queue", + "stable_deref_trait", +] + +[[package]] name = "byte-tools" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -126,10 +398,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" [[package]] -name = "bytes" -version = "0.5.6" +name = "cache-padded" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38" +checksum = "631ae5198c9be5e753e5cc215e1bd73c2b466a3565173db433f52bb9d3e66dba" + +[[package]] +name = "cc" +version = "1.0.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c0496836a84f8d0495758516b8621a622beb77c0fed418570e50764093ced48" [[package]] name = "cfg-if" @@ -144,6 +422,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] +name = "cipher" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12f8e7987cbd042a63249497f41aed09f8e65add917ea6566effbc56578d6801" +dependencies = [ + "generic-array 0.14.4", +] + +[[package]] name = "clap" version = "2.33.3" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -159,6 +446,15 @@ dependencies = [ ] [[package]] +name = "concurrent-queue" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30ed07550be01594c6026cff2a1d7fe9c8f683caa798e12b68694ac9e88286a3" +dependencies = [ + "cache-padded", +] + +[[package]] name = "const_fn" version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -171,12 +467,35 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" [[package]] +name = "cookie" +version = "0.14.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "784ad0fbab4f3e9cef09f20e0aea6000ae08d2cb98ac4c0abc53df18803d702f" +dependencies = [ + "aes-gcm", + "base64 0.12.3", + "hkdf", + "hmac", + "percent-encoding", + "rand", + "sha2", + "time", + "version_check", +] + +[[package]] name = "cpuid-bool" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8aebca1129a03dc6dc2b127edd729435bbc4a37e1d5f4d7513165089ceb02634" [[package]] +name = "cpuid-bool" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcb25d077389e53838a8158c8e99174c5a9d902dee4904320db714f3c653ffba" + +[[package]] name = "crc32fast" version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -193,13 +512,35 @@ checksum = "a1aaa739f95311c2c7887a76863f500026092fb1dce0161dab577e559ef3569d" dependencies = [ "cfg-if 1.0.0", "const_fn", - "crossbeam-utils", + "crossbeam-utils 0.8.1", "lazy_static", "memoffset", "scopeguard", ] [[package]] +name = "crossbeam-queue" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "774ba60a54c213d409d5353bda12d49cd68d14e45036a285234c8d6f91f92570" +dependencies = [ + "cfg-if 0.1.10", + "crossbeam-utils 0.7.2", + "maybe-uninit", +] + +[[package]] +name = "crossbeam-utils" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3c7c73a2d1e9fc0886a08b93e98eb643461230d5f1925e4036204d5f2e261a8" +dependencies = [ + "autocfg", + "cfg-if 0.1.10", + "lazy_static", +] + +[[package]] name = "crossbeam-utils" version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -211,6 +552,31 @@ dependencies = [ ] [[package]] +name = "crypto-mac" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4857fd85a0c34b3c3297875b747c1e02e06b6a0ea32dd892d8192b9ce0813ea6" +dependencies = [ + "generic-array 0.14.4", + "subtle", +] + +[[package]] +name = "ctr" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb4a30d54f7443bf3d6191dcd486aca19e67cb3c49fa7a06a319966346707e7f" +dependencies = [ + "cipher", +] + +[[package]] +name = "data-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "993a608597367c6377b258c25d7120740f00ed23a2252b729b1932dd7866f908" + +[[package]] name = "digest" version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -245,14 +611,20 @@ checksum = "8e93d7f5705de3e49895a2b5e0b8855a1c27f080192ae9c32a6432d50741a57a" dependencies = [ "libc", "redox_users", - "winapi 0.3.9", + "winapi", ] [[package]] -name = "dtoa" -version = "0.4.6" +name = "discard" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "134951f4028bdadb9b84baf4232681efbf277da25144b9b0ad65df75946c422b" +checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0" + +[[package]] +name = "event-listener" +version = "2.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7531096570974c3a9dcf9e4b8e1cede1ec26cf5046219fb3b9d897503b9be59" [[package]] name = "fake-simd" @@ -261,10 +633,29 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" [[package]] -name = "fnv" -version = "1.0.7" +name = "fastrand" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +checksum = "ca5faf057445ce5c9d4329e382b2ce7ca38550ef3b73a5348362d5f24e0c7fe3" +dependencies = [ + "instant", +] + +[[package]] +name = "femme" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2af1a24f391a5a94d756db5092c6576aad494b88a71a5a36b20c67b63e0df034" +dependencies = [ + "cfg-if 0.1.10", + "js-sys", + "log", + "serde", + "serde_derive", + "serde_json", + "wasm-bindgen", + "web-sys", +] [[package]] name = "form_urlencoded" @@ -283,37 +674,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9564fc758e15025b46aa6643b1b77d047d1a56a1aea6e01002ac0c7026876213" dependencies = [ "libc", - "winapi 0.3.9", -] - -[[package]] -name = "fuchsia-zircon" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" -dependencies = [ - "bitflags", - "fuchsia-zircon-sys", -] - -[[package]] -name = "fuchsia-zircon-sys" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" - -[[package]] -name = "futures" -version = "0.3.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b3b0c040a1fe6529d30b3c5944b280c7f0dcb2930d2c3062bca967b602583d0" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", + "winapi", ] [[package]] @@ -323,7 +684,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4b7109687aa4e177ef6fe84553af6280ef2778bdb7783ba44c9dc3399110fe64" dependencies = [ "futures-core", - "futures-sink", ] [[package]] @@ -339,16 +699,40 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "611834ce18aaa1bd13c4b374f5d653e1027cf99b6b502584ff8c9a64413b30bb" [[package]] -name = "futures-sink" +name = "futures-lite" +version = "1.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e6c079abfac3ab269e2927ec048dabc89d009ebfdda6b8ee86624f30c689658" +dependencies = [ + "fastrand", + "futures-core", + "futures-io", + "memchr", + "parking", + "pin-project-lite 0.1.11", + "waker-fn", +] + +[[package]] +name = "futures-macro" version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f878195a49cee50e006b02b93cf7e0a95a38ac7b776b4c4d9cc1207cd20fcb3d" +checksum = "77408a692f1f97bcc61dc001d752e00643408fbc922e4d634c655df50d595556" +dependencies = [ + "proc-macro-hack", + "proc-macro2", + "quote", + "syn", +] [[package]] name = "futures-task" version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7c554eb5bf48b2426c4771ab68c6b14468b6e76cc90996f528c3338d761a4d0d" +dependencies = [ + "once_cell", +] [[package]] name = "futures-util" @@ -357,10 +741,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d304cff4a7b99cfb7986f7d43fbe93d175e72e704a8860787cc95e9ffd85cbd2" dependencies = [ "futures-core", - "futures-sink", + "futures-macro", "futures-task", - "pin-project 1.0.2", + "pin-project", "pin-utils", + "proc-macro-hack", + "proc-macro-nested", + "slab", ] [[package]] @@ -399,48 +786,48 @@ checksum = "fc587bc0ec293155d5bfa6b9891ec18a1e330c234f896ea47fbada4cadbe47e6" dependencies = [ "cfg-if 0.1.10", "libc", - "wasi 0.9.0+wasi-snapshot-preview1", + "wasi", +] + +[[package]] +name = "ghash" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6e27f0689a6e15944bdce7e45425efb87eaa8ab0c6e87f11d0987a9133e2531" +dependencies = [ + "polyval", +] + +[[package]] +name = "gloo-timers" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47204a46aaff920a1ea58b11d03dec6f704287d27561724a4631e450654a891f" +dependencies = [ + "futures-channel", + "futures-core", + "js-sys", + "wasm-bindgen", + "web-sys", ] [[package]] name = "gmarche" version = "0.1.0" dependencies = [ + "async-std", "bincode", "bs58", "dirs", "handlebars", "hex", - "http", "rand", "serde", "serde_json", "sha2", "sled", "structopt", - "tokio", - "urlencoding", - "warp", -] - -[[package]] -name = "h2" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e4728fd124914ad25e99e3d15a9361a879f6620f63cb56bbb08f95abb97a535" -dependencies = [ - "bytes", - "fnv", - "futures-core", - "futures-sink", - "futures-util", - "http", - "indexmap", - "slab", - "tokio", - "tokio-util", - "tracing", - "tracing-futures", + "tide", ] [[package]] @@ -458,37 +845,6 @@ dependencies = [ ] [[package]] -name = "hashbrown" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04" - -[[package]] -name = "headers" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed18eb2459bf1a09ad2d6b1547840c3e5e62882fa09b9a6a20b1de8e3228848f" -dependencies = [ - "base64 0.12.3", - "bitflags", - "bytes", - "headers-core", - "http", - "mime", - "sha-1", - "time", -] - -[[package]] -name = "headers-core" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7f66481bfee273957b1f20485a4ff3362987f85b2c236580d81b4eb7a326429" -dependencies = [ - "http", -] - -[[package]] name = "heck" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -513,24 +869,56 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "644f9158b2f133fd50f5fb3242878846d9eb792e445c893805ff0e3824006e35" [[package]] -name = "http" -version = "0.2.1" +name = "hkdf" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28d569972648b2c512421b5f2a405ad6ac9666547189d0c5477a3f200f3e02f9" +checksum = "51ab2f639c231793c5f6114bdb9bbe50a7dbbfcd7c7c6bd8475dec2d991e964f" dependencies = [ - "bytes", - "fnv", - "itoa", + "digest 0.9.0", + "hmac", ] [[package]] -name = "http-body" -version = "0.3.1" +name = "hmac" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13d5ff830006f7646652e057693569bfe0d51760c0085a071769d142a205111b" +checksum = "c1441c6b1e930e2817404b5046f1f989899143a12bf92de603b69f4e0aee1e15" dependencies = [ - "bytes", - "http", + "crypto-mac", + "digest 0.9.0", +] + +[[package]] +name = "http-client" +version = "6.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "010092b71b94ee49293995625ce7a607778b8b4099c8088fa84fd66bd3e0f21c" +dependencies = [ + "async-trait", + "http-types", + "log", +] + +[[package]] +name = "http-types" +version = "2.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2ab8d0085fb82859c9adf050bd53992297ecdd03a665a230dfa50c8c964bf3d" +dependencies = [ + "anyhow", + "async-channel", + "async-std", + "base64 0.13.0", + "cookie", + "futures-lite", + "infer", + "pin-project-lite 0.1.11", + "rand", + "serde", + "serde_json", + "serde_qs", + "serde_urlencoded", + "url", ] [[package]] @@ -540,36 +928,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cd179ae861f0c2e53da70d892f5f3029f9594be0c41dc5269cd371691b1dc2f9" [[package]] -name = "httpdate" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "494b4d60369511e7dea41cf646832512a94e542f68bb9c49e54518e0f468eb47" - -[[package]] -name = "hyper" -version = "0.13.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6ad767baac13b44d4529fcf58ba2cd0995e36e7b435bc5b039de6f47e880dbf" -dependencies = [ - "bytes", - "futures-channel", - "futures-core", - "futures-util", - "h2", - "http", - "http-body", - "httparse", - "httpdate", - "itoa", - "pin-project 1.0.2", - "socket2", - "tokio", - "tower-service", - "tracing", - "want", -] - -[[package]] name = "idna" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -581,14 +939,10 @@ dependencies = [ ] [[package]] -name = "indexmap" -version = "1.6.0" +name = "infer" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55e2e4c765aa53a0424761bf9f41aa7a6ac1efa87238f59560640e27fca028f2" -dependencies = [ - "autocfg", - "hashbrown", -] +checksum = "64e9829a50b42bb782c1df523f78d332fe371b10c661e78b7a3c34b0198e9fac" [[package]] name = "instant" @@ -600,28 +954,27 @@ dependencies = [ ] [[package]] -name = "iovec" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e" -dependencies = [ - "libc", -] - -[[package]] name = "itoa" version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6" [[package]] -name = "kernel32-sys" -version = "0.2.2" +name = "js-sys" +version = "0.3.46" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" +checksum = "cf3d7383929f7c9c7c2d0fa596f325832df98c3704f2c60553080f7127a58175" dependencies = [ - "winapi 0.2.8", - "winapi-build", + "wasm-bindgen", +] + +[[package]] +name = "kv-log-macro" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0de8b303297635ad57c9f5059fd9cee7a47f8e8daa09df0fcd07dd39fb22977f" +dependencies = [ + "log", ] [[package]] @@ -667,6 +1020,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" [[package]] +name = "maybe-uninit" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00" + +[[package]] name = "memchr" version = "2.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -682,61 +1041,13 @@ dependencies = [ ] [[package]] -name = "mime" -version = "0.3.16" +name = "nb-connect" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" - -[[package]] -name = "mime_guess" -version = "2.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2684d4c2e97d99848d30b324b00c8fcc7e5c897b7cbb5819b09e7c90e8baf212" +checksum = "8123a81538e457d44b933a02faf885d3fe8408806b23fa700e8f01c6c3a98998" dependencies = [ - "mime", - "unicase", -] - -[[package]] -name = "mio" -version = "0.6.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4afd66f5b91bf2a3bc13fad0e21caedac168ca4c707504e75585648ae80e4cc4" -dependencies = [ - "cfg-if 0.1.10", - "fuchsia-zircon", - "fuchsia-zircon-sys", - "iovec", - "kernel32-sys", "libc", - "log", - "miow", - "net2", - "slab", - "winapi 0.2.8", -] - -[[package]] -name = "miow" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebd808424166322d4a38da87083bfddd3ac4c131334ed55856112eb06d46944d" -dependencies = [ - "kernel32-sys", - "net2", - "winapi 0.2.8", - "ws2_32-sys", -] - -[[package]] -name = "net2" -version = "0.2.37" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "391630d12b68002ae1e25e8f974306474966550ad82dac6886fb8910c19568ae" -dependencies = [ - "cfg-if 0.1.10", - "libc", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -750,6 +1061,12 @@ dependencies = [ ] [[package]] +name = "once_cell" +version = "1.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13bd41f508810a131401606d54ac32a467c97172d74ba7662562ebba5ad07fa0" + +[[package]] name = "opaque-debug" version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -762,6 +1079,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] +name = "parking" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "427c3892f9e783d91cc128285287e70a59e206ca452770ece88a76f7a3eddd72" + +[[package]] name = "parking_lot" version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -783,7 +1106,7 @@ dependencies = [ "libc", "redox_syscall", "smallvec", - "winapi 0.3.9", + "winapi", ] [[package]] @@ -837,31 +1160,11 @@ dependencies = [ [[package]] name = "pin-project" -version = "0.4.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ffbc8e94b38ea3d2d8ba92aea2983b503cd75d0888d75b86bb37970b5698e15" -dependencies = [ - "pin-project-internal 0.4.27", -] - -[[package]] -name = "pin-project" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ccc2237c2c489783abd8c4c80e5450fc0e98644555b1364da68cc29aa151ca7" dependencies = [ - "pin-project-internal 1.0.2", -] - -[[package]] -name = "pin-project-internal" -version = "0.4.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65ad2ae56b6abe3a1ee25f15ee605bacadb9a764edaba9c2bf4103800d4a1895" -dependencies = [ - "proc-macro2", - "quote", - "syn", + "pin-project-internal", ] [[package]] @@ -894,6 +1197,29 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] +name = "polling" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2a7bc6b2a29e632e45451c941832803a18cce6781db04de8a04696cdca8bde4" +dependencies = [ + "cfg-if 0.1.10", + "libc", + "log", + "wepoll-sys", + "winapi", +] + +[[package]] +name = "polyval" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4fd92d8e0c06d08525d2e2643cc2b5c80c69ae8eb12c18272d501cd7079ccc0" +dependencies = [ + "cpuid-bool 0.2.0", + "universal-hash", +] + +[[package]] name = "ppv-lite86" version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -924,6 +1250,18 @@ dependencies = [ ] [[package]] +name = "proc-macro-hack" +version = "0.5.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" + +[[package]] +name = "proc-macro-nested" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eba180dafb9038b050a4c280019bbedf9f2467b61e5d892dcad585bb57aadc5a" + +[[package]] name = "proc-macro2" version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1006,6 +1344,12 @@ dependencies = [ ] [[package]] +name = "route-recognizer" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56770675ebc04927ded3e60633437841581c285dc6236109ea25fbf3beb7b59e" + +[[package]] name = "rust-argon2" version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1014,7 +1358,16 @@ dependencies = [ "base64 0.13.0", "blake2b_simd", "constant_time_eq", - "crossbeam-utils", + "crossbeam-utils 0.8.1", +] + +[[package]] +name = "rustc_version" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" +dependencies = [ + "semver", ] [[package]] @@ -1024,18 +1377,27 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" [[package]] -name = "scoped-tls" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2" - -[[package]] name = "scopeguard" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] +name = "semver" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" +dependencies = [ + "semver-parser", +] + +[[package]] +name = "semver-parser" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" + +[[package]] name = "serde" version = "1.0.118" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1067,15 +1429,27 @@ dependencies = [ ] [[package]] -name = "serde_urlencoded" -version = "0.6.1" +name = "serde_qs" +version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ec5d77e2d4c73717816afac02670d5c4f534ea95ed430442cad02e7a6e32c97" +checksum = "5af82de3c6549b001bec34961ff2d6a54339a87bab37ce901b693401f27de6cb" dependencies = [ - "dtoa", - "itoa", + "data-encoding", + "percent-encoding", + "serde", + "thiserror", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edfa57a7f8d9c1d260a549e7224100f6c43d43f9103e06dd8b4095a9b2b43ce9" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", "serde", - "url", ] [[package]] @@ -1091,6 +1465,12 @@ dependencies = [ ] [[package]] +name = "sha1" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2579985fda508104f7587689507983eadd6a6e84dd35d6d115361f530916fa0d" + +[[package]] name = "sha2" version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1098,12 +1478,31 @@ checksum = "6e7aab86fe2149bad8c507606bdb3f4ef5e7b2380eb92350f56122cca72a42a8" dependencies = [ "block-buffer 0.9.0", "cfg-if 1.0.0", - "cpuid-bool", + "cpuid-bool 0.1.2", "digest 0.9.0", "opaque-debug 0.3.0", ] [[package]] +name = "signal-hook" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "604508c1418b99dfe1925ca9224829bb2a8a9a04dda655cc01fcad46f4ab05ed" +dependencies = [ + "libc", + "signal-hook-registry", +] + +[[package]] +name = "signal-hook-registry" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce32ea0c6c56d5eacaeb814fbed9960547021d3edd010ded1425f180536b20ab" +dependencies = [ + "libc", +] + +[[package]] name = "slab" version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1117,7 +1516,7 @@ checksum = "1d0132f3e393bcb7390c60bb45769498cf4550bcb7a21d7f95c02b69f6362cdc" dependencies = [ "crc32fast", "crossbeam-epoch", - "crossbeam-utils", + "crossbeam-utils 0.8.1", "fs2", "fxhash", "libc", @@ -1132,18 +1531,70 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae524f056d7d770e174287294f562e95044c68e88dec909a00d2094805db9d75" [[package]] -name = "socket2" -version = "0.3.17" +name = "stable_deref_trait" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c29947abdee2a218277abeca306f25789c938e500ea5a9d4b12a5a504466902" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "standback" +version = "0.2.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf906c8b8fc3f6ecd1046e01da1d8ddec83e48c8b08b84dcc02b585a6bedf5a8" dependencies = [ - "cfg-if 1.0.0", - "libc", - "redox_syscall", - "winapi 0.3.9", + "version_check", ] [[package]] +name = "stdweb" +version = "0.4.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d022496b16281348b52d0e30ae99e01a73d737b2f45d38fed4edf79f9325a1d5" +dependencies = [ + "discard", + "rustc_version", + "stdweb-derive", + "stdweb-internal-macros", + "stdweb-internal-runtime", + "wasm-bindgen", +] + +[[package]] +name = "stdweb-derive" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c87a60a40fccc84bef0652345bbbbbe20a605bf5d0ce81719fc476f5c03b50ef" +dependencies = [ + "proc-macro2", + "quote", + "serde", + "serde_derive", + "syn", +] + +[[package]] +name = "stdweb-internal-macros" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58fa5ff6ad0d98d1ffa8cb115892b6e69d67799f6763e162a1c9db421dc22e11" +dependencies = [ + "base-x", + "proc-macro2", + "quote", + "serde", + "serde_derive", + "serde_json", + "sha1", + "syn", +] + +[[package]] +name = "stdweb-internal-runtime" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "213701ba3370744dcd1a12960caa4843b3d68b4d1c0a5d575e0d65b2ee9d16c0" + +[[package]] name = "strsim" version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1174,6 +1625,12 @@ dependencies = [ ] [[package]] +name = "subtle" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "343f3f510c2915908f155e94f17220b19ccfacf2a64a2a5d8004f2c3e311e7fd" + +[[package]] name = "syn" version = "1.0.54" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1194,14 +1651,83 @@ dependencies = [ ] [[package]] -name = "time" -version = "0.1.44" +name = "thiserror" +version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" +checksum = "0e9ae34b84616eedaaf1e9dd6026dbe00dcafa92aa0c8077cb69df1fcfe5e53e" dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ba20f23e85b10754cd195504aebf6a27e2e6cbe28c17778a0c930724628dd56" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tide" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c832ca099a0645f6446b6c8900b09e3b76978dedc0d7383438698b32ff07f734" +dependencies = [ + "async-h1", + "async-sse", + "async-std", + "async-trait", + "femme", + "futures-util", + "http-client", + "http-types", + "kv-log-macro", + "log", + "pin-project-lite 0.1.11", + "route-recognizer", + "serde", + "serde_json", +] + +[[package]] +name = "time" +version = "0.2.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bcdaeea317915d59b2b4cd3b5efcd156c309108664277793f5351700c02ce98b" +dependencies = [ + "const_fn", "libc", - "wasi 0.10.0+wasi-snapshot-preview1", - "winapi 0.3.9", + "standback", + "stdweb", + "time-macros", + "version_check", + "winapi", +] + +[[package]] +name = "time-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "957e9c6e26f12cb6d0dd7fc776bb67a706312e7299aed74c8dd5b17ebb27e2f1" +dependencies = [ + "proc-macro-hack", + "time-macros-impl", +] + +[[package]] +name = "time-macros-impl" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5c3be1edfad6027c69f5491cf4cb310d1a71ecd6af742788c6ff8bced86b8fa" +dependencies = [ + "proc-macro-hack", + "proc-macro2", + "quote", + "standback", + "syn", ] [[package]] @@ -1220,93 +1746,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] -name = "tokio" -version = "0.2.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "099837d3464c16a808060bb3f02263b412f6fafcb5d01c533d309985fbeebe48" -dependencies = [ - "bytes", - "fnv", - "futures-core", - "iovec", - "lazy_static", - "memchr", - "mio", - "num_cpus", - "pin-project-lite 0.1.11", - "slab", - "tokio-macros", -] - -[[package]] -name = "tokio-macros" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e44da00bfc73a25f814cd8d7e57a68a5c31b74b3152a0a1d1f590c97ed06265a" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "tokio-util" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be8242891f2b6cbef26a2d7e8605133c2c554cd35b3e4948ea892d6d68436499" -dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "log", - "pin-project-lite 0.1.11", - "tokio", -] - -[[package]] -name = "tower-service" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e987b6bf443f4b5b3b6f38704195592cca41c5bb7aedd3c3693c7081f8289860" - -[[package]] -name = "tracing" -version = "0.1.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f47026cdc4080c07e49b37087de021820269d996f581aac150ef9e5583eefe3" -dependencies = [ - "cfg-if 1.0.0", - "log", - "pin-project-lite 0.2.0", - "tracing-core", -] - -[[package]] -name = "tracing-core" -version = "0.1.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f50de3927f93d202783f4513cda820ab47ef17f624b03c096e86ef00c67e6b5f" -dependencies = [ - "lazy_static", -] - -[[package]] -name = "tracing-futures" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab7bb6f14721aa00656086e9335d363c5c8747bae02ebe32ea2c7dece5689b4c" -dependencies = [ - "pin-project 0.4.27", - "tracing", -] - -[[package]] -name = "try-lock" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" - -[[package]] name = "typenum" version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1319,15 +1758,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "56dee185309b50d1f11bfedef0fe6d036842e3fb77413abef29f8f8d1c5d4c1c" [[package]] -name = "unicase" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6" -dependencies = [ - "version_check", -] - -[[package]] name = "unicode-bidi" version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1364,6 +1794,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" [[package]] +name = "universal-hash" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8326b2c654932e3e4f9196e69d08fdf7cfd718e1dc6f66b347e6024a0c961402" +dependencies = [ + "generic-array 0.14.4", + "subtle", +] + +[[package]] name = "url" version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1373,13 +1813,14 @@ dependencies = [ "idna", "matches", "percent-encoding", + "serde", ] [[package]] -name = "urlencoding" -version = "1.1.1" +name = "vec-arena" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9232eb53352b4442e40d7900465dfc534e8cb2dc8f18656fcb2ac16112b5593" +checksum = "eafc1b9b2dfc6f5529177b62cf806484db55b32dc7c9658a118e11bbeb33061d" [[package]] name = "vec_map" @@ -1394,40 +1835,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed" [[package]] -name = "want" -version = "0.3.0" +name = "waker-fn" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" -dependencies = [ - "log", - "try-lock", -] - -[[package]] -name = "warp" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f41be6df54c97904af01aa23e613d4521eed7ab23537cede692d4058f6449407" -dependencies = [ - "bytes", - "futures", - "headers", - "http", - "hyper", - "log", - "mime", - "mime_guess", - "pin-project 0.4.27", - "scoped-tls", - "serde", - "serde_json", - "serde_urlencoded", - "tokio", - "tower-service", - "tracing", - "tracing-futures", - "urlencoding", -] +checksum = "9d5b2c62b4012a3e1eca5a7e077d13b3bf498c4073e33ccd58626607748ceeca" [[package]] name = "wasi" @@ -1436,16 +1847,91 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" [[package]] -name = "wasi" -version = "0.10.0+wasi-snapshot-preview1" +name = "wasm-bindgen" +version = "0.2.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" +checksum = "3cd364751395ca0f68cafb17666eee36b63077fb5ecd972bbcd74c90c4bf736e" +dependencies = [ + "cfg-if 1.0.0", + "serde", + "serde_json", + "wasm-bindgen-macro", +] [[package]] -name = "winapi" -version = "0.2.8" +name = "wasm-bindgen-backend" +version = "0.2.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" +checksum = "1114f89ab1f4106e5b55e688b828c0ab0ea593a1ea7c094b141b14cbaaec2d62" +dependencies = [ + "bumpalo", + "lazy_static", + "log", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fe9756085a84584ee9457a002b7cdfe0bfff169f45d2591d8be1345a6780e35" +dependencies = [ + "cfg-if 1.0.0", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a6ac8995ead1f084a8dea1e65f194d0973800c7f571f6edd70adf06ecf77084" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5a48c72f299d80557c7c62e37e7225369ecc0c963964059509fbafe917c7549" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e7811dd7f9398f14cc76efd356f98f03aa30419dea46aa810d71e819fc97158" + +[[package]] +name = "web-sys" +version = "0.3.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "222b1ef9334f92a21d3fb53dc3fd80f30836959a90f9274a626d7e06315ba3c3" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "wepoll-sys" +version = "3.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fcb14dea929042224824779fbc82d9fab8d2e6d3cbc0ac404de8edf489e77ff" +dependencies = [ + "cc", +] [[package]] name = "winapi" @@ -1458,12 +1944,6 @@ dependencies = [ ] [[package]] -name = "winapi-build" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" - -[[package]] name = "winapi-i686-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1474,13 +1954,3 @@ name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" - -[[package]] -name = "ws2_32-sys" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" -dependencies = [ - "winapi 0.2.8", - "winapi-build", -] diff --git a/Cargo.toml b/Cargo.toml index 341705c..449e458 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,18 +5,16 @@ authors = ["Pascal Engélibert "] edition = "2018" [dependencies] +async-std = { version = "1.6.0", features = ["attributes"] } bincode = "1.3.1" bs58 = "0.4.0" dirs = "3.0.1" handlebars = "3.5.1" hex = "0.4.2" -http = "0.2.1" rand = "0.7.3" serde = { version = "1.0.118", features = ["derive"] } serde_json = "1.0.60" sha2 = "0.9.2" sled = "0.34.6" structopt = "0.3.21" -tokio = { version = "0.2.24", features = ["macros", "rt-threaded"] } -urlencoding = "1.1.1" -warp = { version = "0.2.5", default-features = false } +tide = { version = "0.15.0", default-features = false, features = ["h1-server", "cookies", "logger"] } diff --git a/src/main.rs b/src/main.rs index 026c989..c2d82bd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,6 +3,7 @@ mod cli; mod config; mod db; +mod queries; mod server; mod static_files; mod templates; @@ -10,7 +11,7 @@ mod utils; use structopt::StructOpt; -#[tokio::main] +#[async_std::main] async fn main() { let opt = cli::MainOpt::from_args(); diff --git a/src/queries.rs b/src/queries.rs new file mode 100644 index 0000000..b3aba13 --- /dev/null +++ b/src/queries.rs @@ -0,0 +1,50 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct NewAdQuery { + pub author: String, + pub price: String, + pub psw: String, + pub pubkey: String, + pub quantity: String, + pub title: String, +} + +#[derive(Clone, Debug, Deserialize)] +pub struct RmAdQuery { + pub ad: String, + pub psw: String, +} + +#[derive(Clone, Debug, Deserialize)] +pub struct AdminRmAdQuery { + pub ad: String, +} + +#[derive(Clone, Debug, Deserialize)] +pub struct AdminLoginQuery { + pub psw: String, +} + +#[derive(Clone, Debug, Deserialize)] +#[serde(tag = "a")] +pub enum Query { + #[serde(rename = "new_ad")] + NewAdQuery(NewAdQuery), + #[serde(rename = "rm_ad")] + RmAdQuery(RmAdQuery), +} + +#[derive(Clone, Debug, Deserialize)] +#[serde(tag = "a")] +pub enum AdminQuery { + #[serde(rename = "login")] + LoginQuery(AdminLoginQuery), + #[serde(rename = "rm_ad")] + RmAdQuery(AdminRmAdQuery), +} + +#[derive(Debug, Deserialize)] +struct SelectAdQuery { + pub ad: String, +} diff --git a/src/server.rs b/src/server.rs index e530f2a..ddbc6ce 100644 --- a/src/server.rs +++ b/src/server.rs @@ -1,430 +1,350 @@ -use super::{cli, config, db, static_files, templates, utils::*}; +use super::{cli, config, db, queries::*, static_files, templates::*, utils::*}; use handlebars::to_json; -use serde::{Deserialize, Serialize}; -use serde_json::value::Value as Json; use sha2::{Digest, Sha512Trunc256}; use std::{ convert::{TryFrom, TryInto}, - sync::{Arc, RwLock}, + sync::Arc, }; -use warp::Filter; -use warp::Reply; - -type PasswordHash = [u8; 32]; - -#[derive(Clone, Debug, Hash, Eq, PartialEq, Serialize)] -struct AdId([u8; 16]); - -impl AdId { - fn random() -> Self { - Self(rand::random()) - } -} - -impl AsRef<[u8]> for AdId { - fn as_ref(&self) -> &[u8] { - &self.0 - } -} - -impl TryFrom<&[u8]> for AdId { - type Error = std::array::TryFromSliceError; - - fn try_from(v: &[u8]) -> Result { - Ok(Self(v.try_into()?)) - } -} pub async fn start_server( config: config::Config, dbs: db::Dbs, - templates: templates::Templates<'static>, + templates: Templates<'static>, opt: cli::MainOpt, ) { let templates = Arc::new(templates); - - let cache_ads = Arc::new(RwLock::new(to_json( - dbs.ads - .iter() - .filter_map(|x| { - let (ad_id, ad) = x.ok()?; - Some(AdWithId { - id: hex::encode(ad_id.as_ref()), - ad: bincode::deserialize::(&ad).ok()?, - }) - }) - .collect::>(), - ))); - let config = Arc::new(config); let dbs = Arc::new(dbs); - let handle_index = { - let cache_ads = cache_ads.clone(); + let mut app = tide::new(); + app.at("/static") + .serve_dir(opt.dir.0.join(static_files::STATIC_DIR)) + .unwrap(); + app.at("/").get({ let templates = templates.clone(); - move |errors: &[ErrorTemplate], new_ad_form_refill| { - warp::reply::html( - templates - .hb - .render( - "index.html", - &IndexTemplate { - lang: "fr", - errors, - ads: &*cache_ads.read().unwrap(), - new_ad_form_refill, - }, - ) - .unwrap_or_else(|e| e.to_string()), - ) - .into_response() - } - }; - - let handle_admin_login = { + let dbs = dbs.clone(); + move |req: tide::Request<()>| serve_index(req, templates.clone(), dbs.clone(), &[], None) + }); + app.at("/").post({ let templates = templates.clone(); - move |errors: &[ErrorTemplate]| { - warp::reply::html( - templates - .hb - .render( - "admin_login.html", - &AdminLoginTemplate { lang: "fr", errors }, - ) - .unwrap_or_else(|e| e.to_string()), - ) - .into_response() - } - }; - - let handle_admin = { - let cache_ads = cache_ads.clone(); - move |errors: &[ErrorTemplate]| { - warp::reply::html( - templates - .hb - .render( - "admin.html", - &AdminTemplate { - lang: "fr", - errors, - ads: &*cache_ads.read().unwrap(), - }, - ) - .unwrap_or_else(|e| e.to_string()), - ) - .into_response() - } - }; - - let route_static = warp::path("static") - .and(warp::get()) - .and(warp::fs::dir(opt.dir.0.join(static_files::STATIC_DIR))); - - let handle_new_ad = { - let handle_index = handle_index.clone(); let dbs = dbs.clone(); - let cache_ads = cache_ads.clone(); - move |query: NewAdQuery| { - let mut hasher = Sha512Trunc256::new(); - hasher.update(&query.psw); - dbs.ads - .insert( - AdId::random(), - bincode::serialize(&Ad { - pubkey: if query.pubkey.is_empty() { - None - } else { - Some(match format_pubkey(&query.pubkey) { - Ok(pubkey) => pubkey, - Err(e) => return handle_index(&[ErrorTemplate{text: match e { - PubkeyDecodeError::BadChecksum => "La somme de contrôle de la clé publique est incorrecte.", - PubkeyDecodeError::BadFormat => "Le format de la clé publique est incorrect.", - }}], Some(query)) - }) - }, - author: query.author, - password: hasher.finalize()[..].try_into().unwrap(), - price: query.price, - quantity: query.quantity, - time: 0, - title: query.title, - }) - .unwrap(), - ) - .unwrap(); - dbs.ads.flush().unwrap(); - let mut cache_ads = cache_ads.write().unwrap(); - *cache_ads = to_json( - dbs.ads - .iter() - .filter_map(|x| { - let (ad_id, ad) = x.ok()?; - Some(AdWithId { - id: hex::encode(ad_id.as_ref()), - ad: bincode::deserialize::(&ad).ok()?, - }) - }) - .collect::>(), - ); - drop(cache_ads); - redirect_302("/").into_response() - } - }; - - let handle_rm_ad = { - let handle_index = handle_index.clone(); + move |req: tide::Request<()>| handle_post_index(req, templates.clone(), dbs.clone()) + }); + app.at("/ad/:ad").get({ + let templates = templates.clone(); let dbs = dbs.clone(); - let cache_ads = cache_ads.clone(); - move |query: RmAdQuery| { - let mut hasher = Sha512Trunc256::new(); - hasher.update(query.psw); - let password: PasswordHash = hasher.finalize()[..].try_into().unwrap(); - /*query - .ads - .into_iter() - .filter_map(|x| Some(AdId::try_from(hex::decode(x).ok()?.as_ref()).ok()?)) - .for_each(|ad_id| { - if let Some(raw) = dbs.ads.get(&ad_id).unwrap() { - if let Ok(ad) = bincode::deserialize::(&raw) { - if ad.password == password { - dbs.ads.remove(&ad_id).unwrap(); - } - } - } - });*/ - if let Ok(ad_id) = hex::decode(query.ad) { - if let Ok(ad_id) = AdId::try_from(ad_id.as_ref()) { - if let Some(raw) = dbs.ads.get(&ad_id).unwrap() { - if let Ok(ad) = bincode::deserialize::(&raw) { - if ad.password == password { - dbs.ads.remove(&ad_id).unwrap(); - - dbs.ads.flush().unwrap(); - let mut cache_ads = cache_ads.write().unwrap(); - *cache_ads = to_json( - dbs.ads - .iter() - .filter_map(|x| { - let (ad_id, ad) = x.ok()?; - Some(AdWithId { - id: hex::encode(ad_id.as_ref()), - ad: bincode::deserialize::(&ad).ok()?, - }) - }) - .collect::>(), - ); - } else { - return handle_index( - &[ErrorTemplate { - text: "Le mot de passe de l'annonce est incorrect.", - }], - None, - ); - } - } - } - } - } - redirect_302("/").into_response() + move |req: tide::Request<()>| serve_index(req, templates.clone(), dbs.clone(), &[], None) + }); + app.at("/admin").get({ + let config = config.clone(); + let templates = templates.clone(); + let dbs = dbs.clone(); + move |req: tide::Request<()>| { + handle_admin(req, config.clone(), templates.clone(), dbs.clone()) } - }; + }); + app.at("/admin").post({ + let config = config.clone(); + move |req: tide::Request<()>| { + handle_post_admin(req, config.clone(), templates.clone(), dbs.clone()) + } + }); + app.at("/admin/logout").get(handle_admin_logout); + app.listen(config.listen).await.unwrap(); +} - let handle_admin_rm_ad = { - move |query: AdminRmAdQuery| { - if let Ok(ad_id) = hex::decode(query.ad) { - if let Ok(ad_id) = AdId::try_from(ad_id.as_ref()) { - if dbs.ads.remove(&ad_id).unwrap().is_some() { - dbs.ads.flush().unwrap(); - let mut cache_ads = cache_ads.write().unwrap(); - *cache_ads = to_json( +async fn serve_index<'a>( + req: tide::Request<()>, + templates: Arc>, + dbs: Arc, + errors: &[ErrorTemplate<'a>], + new_ad_form_refill: Option, +) -> tide::Result { + let selected_ad = req.param("ad").ok(); + Ok(tide::Response::builder(200) + .content_type(tide::http::mime::HTML) + .body( + templates + .hb + .render( + "index.html", + &IndexTemplate { + lang: "fr", + errors, + ads: &to_json( dbs.ads .iter() .filter_map(|x| { let (ad_id, ad) = x.ok()?; + let ad_id = hex::encode(ad_id.as_ref()); Some(AdWithId { - id: hex::encode(ad_id.as_ref()), ad: bincode::deserialize::(&ad).ok()?, + selected: selected_ad.map_or(false, |i| i == ad_id), + id: ad_id, }) }) .collect::>(), - ); + ), + new_ad_form_refill, + }, + ) + .unwrap_or_else(|e| e.to_string()), + ) + .build()) +} + +async fn serve_admin<'a>( + req: tide::Request<()>, + templates: Arc>, + dbs: Arc, + errors: &[ErrorTemplate<'a>], +) -> tide::Result { + let selected_ad = req.param("ad").ok(); + Ok(tide::Response::builder(200) + .content_type(tide::http::mime::HTML) + .body( + templates + .hb + .render( + "admin.html", + &AdminTemplate { + lang: "fr", + errors, + ads: &to_json( + dbs.ads + .iter() + .filter_map(|x| { + let (ad_id, ad) = x.ok()?; + let ad_id = hex::encode(ad_id.as_ref()); + Some(AdWithId { + ad: bincode::deserialize::(&ad).ok()?, + selected: selected_ad.map_or(false, |i| i == ad_id), + id: ad_id, + }) + }) + .collect::>(), + ), + }, + ) + .unwrap_or_else(|e| e.to_string()), + ) + .build()) +} + +async fn serve_admin_login<'a>( + _req: tide::Request<()>, + templates: Arc>, + errors: &[ErrorTemplate<'a>], +) -> tide::Result { + Ok(tide::Response::builder(200) + .content_type(tide::http::mime::HTML) + .body( + templates + .hb + .render( + "admin_login.html", + &AdminLoginTemplate { lang: "fr", errors }, + ) + .unwrap_or_else(|e| e.to_string()), + ) + .build()) +} + +async fn handle_post_index( + mut req: tide::Request<()>, + templates: Arc>, + dbs: Arc, +) -> tide::Result { + match req.body_form::().await? { + Query::NewAdQuery(query) => handle_new_ad(req, templates.clone(), dbs.clone(), query).await, + Query::RmAdQuery(query) => handle_rm_ad(req, templates.clone(), dbs.clone(), query).await, + } +} + +async fn handle_new_ad( + req: tide::Request<()>, + templates: Arc>, + dbs: Arc, + query: NewAdQuery, +) -> tide::Result { + let mut hasher = Sha512Trunc256::new(); + hasher.update(&query.psw); + dbs.ads + .insert( + AdId::random(), + bincode::serialize(&Ad { + pubkey: if query.pubkey.is_empty() { + None + } else { + Some(match format_pubkey(&query.pubkey) { + Ok(pubkey) => pubkey, + Err(e) => return serve_index( + req, + templates, + dbs, + &[ErrorTemplate { + text: match e { + PubkeyDecodeError::BadChecksum => { + "La somme de contrôle de la clé publique est incorrecte." + } + PubkeyDecodeError::BadFormat => { + "Le format de la clé publique est incorrect." + } + }, + }], + Some(query), + ) + .await, + }) + }, + author: query.author, + password: hasher.finalize()[..].try_into().unwrap(), + price: query.price, + quantity: query.quantity, + time: 0, + title: query.title, + }) + .unwrap(), + ) + .unwrap(); + dbs.ads.flush().unwrap(); + Ok(tide::Redirect::new("/").into()) +} + +async fn handle_rm_ad( + req: tide::Request<()>, + templates: Arc>, + dbs: Arc, + query: RmAdQuery, +) -> tide::Result { + let mut hasher = Sha512Trunc256::new(); + hasher.update(query.psw); + let password: PasswordHash = hasher.finalize()[..].try_into().unwrap(); + /*query + .ads + .into_iter() + .filter_map(|x| Some(AdId::try_from(hex::decode(x).ok()?.as_ref()).ok()?)) + .for_each(|ad_id| { + if let Some(raw) = dbs.ads.get(&ad_id).unwrap() { + if let Ok(ad) = bincode::deserialize::(&raw) { + if ad.password == password { + dbs.ads.remove(&ad_id).unwrap(); + } + } + } + });*/ + if let Ok(ad_id) = hex::decode(query.ad) { + if let Ok(ad_id) = AdId::try_from(ad_id.as_ref()) { + if let Some(raw) = dbs.ads.get(&ad_id).unwrap() { + if let Ok(ad) = bincode::deserialize::(&raw) { + if ad.password == password { + dbs.ads.remove(&ad_id).unwrap(); + + dbs.ads.flush().unwrap(); + } else { + return serve_index( + req, + templates, + dbs, + &[ErrorTemplate { + text: "Le mot de passe de l'annonce est incorrect.", + }], + None, + ) + .await; } } } - redirect_302("/admin").into_response() } - }; + } + Ok(tide::Redirect::new("/").into()) +} - let route_index = warp::path::end().and(warp::get().map(move || handle_index(&[], None)).or( - warp::post().and( - warp::body::form::().map(move |query: Query| match query { - Query::NewAdQuery(query) => handle_new_ad(query), - Query::RmAdQuery(query) => handle_rm_ad(query), - }), - ), - )); - - let route_admin = warp::path("admin").and( - warp::path::end() - .and( - warp::cookie("admin") - .and(warp::body::form::()) - .map({ - let handle_admin_login = handle_admin_login.clone(); - let config = config.clone(); - move |psw, query| { - if config.admin_passwords.contains(&psw) { - let AdminQuery::RmAdQuery(query) = query; - handle_admin_rm_ad(query) - } else { - handle_admin_login(&[ErrorTemplate { - text: "Mot de passe administrateur invalide", - }]) - } - } - }) - .or(warp::cookie("admin").map({ - let handle_admin = handle_admin.clone(); - let handle_admin_login = handle_admin_login.clone(); - let config = config.clone(); - move |psw| { - if config.admin_passwords.contains(&psw) { - handle_admin(&[]) - } else { - handle_admin_login(&[ErrorTemplate { - text: "Mot de passe administrateur invalide", - }]) - } - } - })) - .or(warp::path::end().map({ - let handle_admin_login = handle_admin_login.clone(); - move || handle_admin_login(&[]) - })), +async fn handle_admin( + req: tide::Request<()>, + config: Arc, + templates: Arc>, + dbs: Arc, +) -> tide::Result { + if let Some(psw) = req.cookie("admin") { + if config.admin_passwords.contains(&String::from(psw.value())) { + serve_admin(req, templates, dbs, &[]).await + } else { + serve_admin_login( + req, + templates, + &[ErrorTemplate { + text: "Mot de passe administrateur invalide", + }], ) - .or(warp::path("login").and(warp::path::end()).and( - warp::post() - .and(warp::get().map(move || handle_admin(&[]))) - .or(warp::body::form::().map({ - let config = config.clone(); - move |query: AdminLoginQuery| { - if config.admin_passwords.contains(&query.psw) { - warp::reply::with_header( - redirect_302("/admin").into_response(), - "Set-Cookie", - format!( - "admin={}; path=/; HttpOnly", - urlencoding::encode(&query.psw) - ), - ) - .into_response() - } else { - handle_admin_login(&[ErrorTemplate { - text: "Mot de passe administrateur invalide", - }]) - .into_response() - } + .await + } + } else { + serve_admin_login(req, templates, &[]).await + } +} + +async fn handle_post_admin( + mut req: tide::Request<()>, + config: Arc, + templates: Arc>, + dbs: Arc, +) -> tide::Result { + if let Some(psw) = req.cookie("admin") { + if config.admin_passwords.contains(&String::from(psw.value())) { + match req.body_form::().await? { + AdminQuery::RmAdQuery(query) => { + if let Ok(ad_id) = hex::decode(query.ad) { + if let Ok(ad_id) = AdId::try_from(ad_id.as_ref()) { + dbs.ads.remove(&ad_id).unwrap(); + + dbs.ads.flush().unwrap(); } - })), - )) - .or(warp::path("logout").and(warp::path::end()).map(|| { - warp::reply::with_header( - redirect_302("/").into_response(), - "Set-Cookie", - "admin=; HttpOnly; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT", - ) - .into_response() - })), - ); - - warp::serve(route_static.or(route_index).or(route_admin)) - .run(config.listen) - .await; + } + Ok(tide::Redirect::new("/admin").into()) + } + _ => serve_admin(req, templates, dbs, &[]).await, + } + } else { + serve_admin_login( + req, + templates, + &[ErrorTemplate { + text: "Mot de passe administrateur invalide", + }], + ) + .await + } + } else if let AdminQuery::LoginQuery(query) = req.body_form::().await? { + if config.admin_passwords.contains(&query.psw) { + serve_admin(req, templates, dbs, &[]).await.map(|mut r| { + let mut cookie = tide::http::Cookie::new("admin", query.psw); + cookie.set_http_only(Some(true)); + cookie.set_path("/"); + r.insert_cookie(cookie); + r + }) + } else { + serve_admin_login( + req, + templates, + &[ErrorTemplate { + text: "Mot de passe administrateur invalide", + }], + ) + .await + } + } else { + serve_admin_login(req, templates, &[]).await + } } -#[derive(Serialize)] -struct IndexTemplate<'a> { - lang: &'a str, - errors: &'a [ErrorTemplate<'a>], - ads: &'a Json, - new_ad_form_refill: Option, -} - -#[derive(Serialize)] -struct AdminLoginTemplate<'a> { - lang: &'a str, - errors: &'a [ErrorTemplate<'a>], -} - -#[derive(Serialize)] -struct AdminTemplate<'a> { - lang: &'a str, - errors: &'a [ErrorTemplate<'a>], - ads: &'a Json, -} - -#[derive(Serialize)] -struct ErrorTemplate<'a> { - text: &'a str, -} - -#[derive(Clone, Debug, Deserialize, Serialize)] -struct NewAdQuery { - author: String, - price: String, - psw: String, - pubkey: String, - quantity: String, - title: String, -} - -#[derive(Clone, Debug, Deserialize)] -struct RmAdQuery { - ad: String, - psw: String, -} - -#[derive(Clone, Debug, Deserialize)] -struct AdminRmAdQuery { - ad: String, -} - -#[derive(Clone, Debug, Deserialize)] -struct AdminLoginQuery { - psw: String, -} - -#[derive(Clone, Debug, Deserialize)] -#[serde(tag = "a")] -enum Query { - #[serde(rename = "new_ad")] - NewAdQuery(NewAdQuery), - #[serde(rename = "rm_ad")] - RmAdQuery(RmAdQuery), -} - -#[derive(Clone, Debug, Deserialize)] -#[serde(tag = "a")] -enum AdminQuery { - #[serde(rename = "rm_ad")] - RmAdQuery(AdminRmAdQuery), -} - -#[derive(Clone, Debug, Deserialize, Serialize)] -struct Ad { - author: String, - password: PasswordHash, - price: String, - pubkey: Option, - quantity: String, - time: u64, - title: String, -} - -#[derive(Clone, Debug, Serialize)] -struct AdWithId { - id: String, - ad: Ad, +async fn handle_admin_logout(req: tide::Request<()>) -> tide::Result { + let mut r: tide::Response = tide::Redirect::new("/").into(); + if let Some(mut cookie) = req.cookie("admin") { + cookie.set_path("/"); + r.remove_cookie(cookie); + } + Ok(r) } diff --git a/src/templates.rs b/src/templates.rs index f23dba2..28c7746 100644 --- a/src/templates.rs +++ b/src/templates.rs @@ -1,4 +1,8 @@ +use super::queries::*; + use handlebars::Handlebars; +use serde::Serialize; +use serde_json::value::Value as Json; use std::path::Path; const TEMPLATES_DIR: &str = "templates"; @@ -41,3 +45,29 @@ pub fn load_templates<'reg>(dir: &Path) -> Templates<'reg> { } Templates { hb } } + +#[derive(Serialize)] +pub struct IndexTemplate<'a> { + pub lang: &'a str, + pub errors: &'a [ErrorTemplate<'a>], + pub ads: &'a Json, + pub new_ad_form_refill: Option, +} + +#[derive(Serialize)] +pub struct AdminLoginTemplate<'a> { + pub lang: &'a str, + pub errors: &'a [ErrorTemplate<'a>], +} + +#[derive(Serialize)] +pub struct AdminTemplate<'a> { + pub lang: &'a str, + pub errors: &'a [ErrorTemplate<'a>], + pub ads: &'a Json, +} + +#[derive(Serialize)] +pub struct ErrorTemplate<'a> { + pub text: &'a str, +} diff --git a/src/utils.rs b/src/utils.rs index 681d038..2190235 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,4 +1,49 @@ +use serde::{Deserialize, Serialize}; use sha2::{Digest, Sha256}; +use std::convert::{TryFrom, TryInto}; + +pub type PasswordHash = [u8; 32]; + +#[derive(Clone, Debug, Hash, Eq, PartialEq, Serialize)] +pub struct AdId([u8; 16]); + +impl AdId { + pub fn random() -> Self { + Self(rand::random()) + } +} + +impl AsRef<[u8]> for AdId { + fn as_ref(&self) -> &[u8] { + &self.0 + } +} + +impl TryFrom<&[u8]> for AdId { + type Error = std::array::TryFromSliceError; + + fn try_from(v: &[u8]) -> Result { + Ok(Self(v.try_into()?)) + } +} + +#[derive(Clone, Debug, Deserialize, Serialize)] +pub struct Ad { + pub author: String, + pub password: PasswordHash, + pub price: String, + pub pubkey: Option, + pub quantity: String, + pub time: u64, + pub title: String, +} + +#[derive(Clone, Debug, Serialize)] +pub struct AdWithId { + pub id: String, + pub ad: Ad, + pub selected: bool, +} pub enum PubkeyDecodeError { BadChecksum, @@ -39,10 +84,3 @@ pub fn format_pubkey(raw: &str) -> Result { &checksum[..3] )) } - -pub fn redirect_302(url: &str) -> warp::reply::WithStatus> { - warp::reply::with_status( - warp::reply::with_header("", "Location", url), - http::status::StatusCode::FOUND, - ) -} diff --git a/templates/admin.html b/templates/admin.html index 46d0ee1..c8a1b77 100644 --- a/templates/admin.html +++ b/templates/admin.html @@ -38,7 +38,7 @@ {{#each ads}} - {{this.ad.title}} + {{this.ad.title}} {{this.ad.quantity}} {{this.ad.author}} diff --git a/templates/admin_login.html b/templates/admin_login.html index 0750545..293d85b 100644 --- a/templates/admin_login.html +++ b/templates/admin_login.html @@ -28,9 +28,10 @@ {{/if}} -
+ + - +
diff --git a/templates/index.html b/templates/index.html index 0462b53..079c980 100644 --- a/templates/index.html +++ b/templates/index.html @@ -42,11 +42,11 @@ {{#each ads}} - {{this.ad.title}} + {{this.ad.title}} {{this.ad.quantity}} {{this.ad.author}} - +

{{#if this.ad.pubkey}}Clé publique : {{this.ad.pubkey}}
{{/if}} Prix : {{this.ad.price}}