diff --git a/Cargo.lock b/Cargo.lock index 7920c56..d9865b4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,13 +2,19 @@ # It is not intended for manual editing. [[package]] name = "addr2line" -version = "0.12.2" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "602d785912f476e480434627e8732e6766b760c045bbf897d9dfaa9f4fbd399c" +checksum = "1b6a2d3371669ab3ca9797670853d61402b03d0b4b9ebf33d677dfa720203072" dependencies = [ "gimli", ] +[[package]] +name = "adler" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee2a4ec343196209d6594e19543ae87a39f96d5534d7174822a3ad825dd6ed7e" + [[package]] name = "adler32" version = "1.1.0" @@ -17,57 +23,56 @@ checksum = "567b077b825e468cc974f0020d4082ee6e03132512f207ef1a02fd5d00d1f32d" [[package]] name = "aead" -version = "0.2.0" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4cf01b9b56e767bb57b94ebf91a58b338002963785cdd7013e21c0d4679471e4" +checksum = "7fc95d1bdb8e6666b2b217308eeeb09f2d6728d104be3e31916cc74d15420331" dependencies = [ "generic-array", ] [[package]] name = "aes" -version = "0.3.2" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54eb1d8fe354e5fc611daf4f2ea97dd45a765f4f1e4512306ec183ae2e8f20c9" +checksum = "f7001367fde4c768a19d1029f0a8be5abd9308e1119846d5bd9ad26297b8faf5" dependencies = [ "aes-soft", "aesni", - "block-cipher-trait", + "block-cipher", ] [[package]] name = "aes-gcm" -version = "0.5.0" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "834a6bda386024dbb7c8fc51322856c10ffe69559f972261c868485f5759c638" +checksum = "86f5007801316299f922a6198d1d09a0bae95786815d066d5880d13f7c45ead1" dependencies = [ "aead", "aes", - "block-cipher-trait", + "block-cipher", "ghash", - "subtle 2.2.3", - "zeroize", + "subtle", ] [[package]] name = "aes-soft" -version = "0.3.3" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cfd7e7ae3f9a1fb5c03b389fc6bb9a51400d0c13053f0dca698c832bfd893a0d" +checksum = "4925647ee64e5056cf231608957ce7c81e12d6d6e316b9ce1404778cc1d35fa7" dependencies = [ - "block-cipher-trait", + "block-cipher", "byteorder", - "opaque-debug", + "opaque-debug 0.2.3", ] [[package]] name = "aesni" -version = "0.6.0" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f70a6b5f971e473091ab7cfb5ffac6cde81666c4556751d8d5620ead8abf100" +checksum = "d050d39b0b7688b3a3254394c3e30a9d66c41dcf9b05b0e2dbdc623f6505d264" dependencies = [ - "block-cipher-trait", - "opaque-debug", + "block-cipher", + "opaque-debug 0.2.3", ] [[package]] @@ -76,6 +81,12 @@ version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4d25d88fd6b8041580a654f9d0c581a047baee2b3efee13275f2fc392fc75034" +[[package]] +name = "array-init" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f30bbe2f5e3d117f55bd8c7a1f9191e4a5deba9f15f595bbea4f670c59c765db" + [[package]] name = "arrayref" version = "0.3.6" @@ -124,14 +135,14 @@ checksum = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d" [[package]] name = "backtrace" -version = "0.3.49" +version = "0.3.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05100821de9e028f12ae3d189176b41ee198341eb8f369956407fea2f5cc666c" +checksum = "46254cf2fdcdf1badb5934448c1bcbe046a56537b3987d96c51a7afc5d03f293" dependencies = [ "addr2line", "cfg-if", "libc", - "miniz_oxide", + "miniz_oxide 0.4.0", "object", "rustc-demangle", ] @@ -179,32 +190,20 @@ dependencies = [ [[package]] name = "block-buffer" -version = "0.7.3" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b" -dependencies = [ - "block-padding", - "byte-tools", - "byteorder", - "generic-array", -] - -[[package]] -name = "block-cipher-trait" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c924d49bd09e7c06003acda26cd9742e796e34282ec6c1189404dee0c1f4774" +checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" dependencies = [ "generic-array", ] [[package]] -name = "block-padding" -version = "0.1.5" +name = "block-cipher" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa79dedbb091f449f1f39e53edf88d5dbe95f895dae6135a8d7b881fb5af73f5" +checksum = "fa136449e765dc7faa244561ccae839c394048667929af599b5d931ebe7b7f10" dependencies = [ - "byte-tools", + "generic-array", ] [[package]] @@ -213,17 +212,11 @@ version = "3.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2e8c087f005730276d1096a652e92a8bacee2e2472bcc9715a74d2bec38b5820" -[[package]] -name = "byte-tools" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" - [[package]] name = "bytemuck" -version = "1.2.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37fa13df2292ecb479ec23aa06f4507928bef07839be9ef15281411076629431" +checksum = "d40636046a60a45ee5185e885a3ccb771f7a2065fb7cbcc2a7ecfd9896d1c365" [[package]] name = "byteorder" @@ -233,18 +226,15 @@ checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" [[package]] name = "bytes" -version = "0.5.5" +version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "118cf036fbb97d0816e3c34b2d7a1e8cfc60f68fcf63d550ddbe9bd5f59c213b" -dependencies = [ - "loom", -] +checksum = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38" [[package]] name = "cc" -version = "1.0.55" +version = "1.0.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1be3409f94d7bdceeb5f5fac551039d9b3f00e25da7a74fc4d33400a0d96368" +checksum = "f9a06fb2e53271d7c279ec1efea6ab691c35a2ae67ec0d91d7acec0caf13b518" [[package]] name = "cfg-if" @@ -254,9 +244,9 @@ checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" [[package]] name = "cloudabi" -version = "0.0.3" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" +checksum = "4344512281c643ae7638bbabc3af17a11307803ec8f0fcad9fae512a8bf36467" dependencies = [ "bitflags", ] @@ -297,9 +287,9 @@ checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" [[package]] name = "cookie" -version = "0.14.1" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca761767cf3fa9068cc893ec8c247a22d0fd0535848e65640c0548bd1f8bbb36" +checksum = "1373a16a4937bc34efec7b391f9c1500c30b8478a701a4f44c9165cc0475a6e0" dependencies = [ "aes-gcm", "base64 0.12.3", @@ -308,6 +298,7 @@ dependencies = [ "rand", "sha2", "time 0.2.16", + "version_check", ] [[package]] @@ -326,6 +317,12 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3a71ab494c0b5b860bdc8407ae08978052417070c2ced38573a9157ad75b8ac" +[[package]] +name = "cpuid-bool" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8aebca1129a03dc6dc2b127edd729435bbc4a37e1d5f4d7513165089ceb02634" + [[package]] name = "crc32fast" version = "1.2.0" @@ -363,19 +360,19 @@ dependencies = [ [[package]] name = "crypto-mac" -version = "0.7.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4434400df11d95d556bac068ddfedd482915eb18fe8bea89bc80b6e4b1c179e5" +checksum = "b584a330336237c1eecd3e94266efb216c56ed91225d634cb2991c5f3fd1aeab" dependencies = [ "generic-array", - "subtle 1.0.0", + "subtle", ] [[package]] name = "deflate" -version = "0.8.4" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7e5d2a2273fed52a7f947ee55b092c4057025d7a3e04e5ecdbd25d6c3fb1bd7" +checksum = "73770f8e1fe7d64df17ca66ad28994a0a623ea497fa69486e14984e715c5d174" dependencies = [ "adler32", "byteorder", @@ -413,9 +410,9 @@ dependencies = [ [[package]] name = "digest" -version = "0.8.1" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5" +checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" dependencies = [ "generic-array", ] @@ -462,12 +459,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "fake-simd" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" - [[package]] name = "fnv" version = "1.0.7" @@ -489,6 +480,16 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" +[[package]] +name = "form_urlencoded" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ece68d15c92e84fa4f19d3780f1294e5ca82a78a6d515f1efaabcc144688be00" +dependencies = [ + "matches", + "percent-encoding", +] + [[package]] name = "fs2" version = "0.4.3" @@ -619,26 +620,14 @@ dependencies = [ "byteorder", ] -[[package]] -name = "generator" -version = "0.6.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "add72f17bb81521258fcc8a7a3245b1e184e916bfbe34f0ea89558f440df5c68" -dependencies = [ - "cc", - "libc", - "log", - "rustc_version", - "winapi 0.3.9", -] - [[package]] name = "generic-array" -version = "0.12.3" +version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c68f0274ae0e023facc3c97b2e00f076be70e254bc851d972503b328db79b2ec" +checksum = "60fb4bb6bba52f78a471264d9a3b7d026cc0af47b22cd2cffbc0b787ca003e63" dependencies = [ "typenum", + "version_check", ] [[package]] @@ -654,9 +643,9 @@ dependencies = [ [[package]] name = "ghash" -version = "0.2.3" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f0930ed19a7184089ea46d2fedead2f6dc2b674c5db4276b7da336c7cd83252" +checksum = "d6e27f0689a6e15944bdce7e45425efb87eaa8ab0c6e87f11d0987a9133e2531" dependencies = [ "polyval", ] @@ -673,9 +662,9 @@ dependencies = [ [[package]] name = "gimli" -version = "0.21.0" +version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcc8e0c9bce37868955864dbecd2b1ab2bdf967e6f28066d65aaac620444b65c" +checksum = "aaf91faf136cb47367fa430cd46e37a788775e7fa104f8b4bcb3861dc389b724" [[package]] name = "glob" @@ -685,9 +674,9 @@ checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" [[package]] name = "h2" -version = "0.2.5" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79b7246d7e4b979c03fa093da39cfb3617a96bbeee6310af63991668d7e843ff" +checksum = "993f9e0baeed60001cf565546b0d3dbe6a6ad23f2bd31644a133c641eccf6d53" dependencies = [ "bytes", "fnv", @@ -696,10 +685,19 @@ dependencies = [ "futures-util", "http", "indexmap", - "log", "slab", "tokio", "tokio-util", + "tracing", +] + +[[package]] +name = "hashbrown" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34f595585f103464d8d2f6e9864682d74c1601fed5e07d62b1c9058dba8246fb" +dependencies = [ + "autocfg", ] [[package]] @@ -713,18 +711,18 @@ dependencies = [ [[package]] name = "hermit-abi" -version = "0.1.14" +version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9586eedd4ce6b3c498bc3b4dd92fc9f11166aa908a914071953768066c67909" +checksum = "3deed196b6e7f9e44a2ae8d94225d80302d81208b1bb673fd21fe634645c85a9" dependencies = [ "libc", ] [[package]] name = "hkdf" -version = "0.8.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fa08a006102488bd9cd5b8013aabe84955cf5ae22e304c2caf655b633aefae3" +checksum = "fe1149865383e4526a43aee8495f9a325f0b806c63ce6427d06336a590abbbc9" dependencies = [ "digest", "hmac", @@ -732,9 +730,9 @@ dependencies = [ [[package]] name = "hmac" -version = "0.7.1" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5dcb5e64cda4c23119ab41ba960d1e170a774c8e4b9d9e6a9bc18aabf5e59695" +checksum = "126888268dcc288495a26bf004b38c5fdbb31682f992c84ceb046a1f0fe38840" dependencies = [ "crypto-mac", "digest", @@ -769,9 +767,9 @@ checksum = "cd179ae861f0c2e53da70d892f5f3029f9594be0c41dc5269cd371691b1dc2f9" [[package]] name = "hyper" -version = "0.13.6" +version = "0.13.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6e7655b9594024ad0ee439f3b5a7299369dc2a3f459b47c696f9ff676f9aa1f" +checksum = "3e68a8dd9716185d9e64ea473ea6ef63529252e3e27623295a0378a19665d5eb" dependencies = [ "bytes", "futures-channel", @@ -782,20 +780,20 @@ dependencies = [ "http-body", "httparse", "itoa", - "log", "pin-project", "socket2", "time 0.1.43", "tokio", "tower-service", + "tracing", "want", ] [[package]] name = "hyper-tls" -version = "0.4.1" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3adcd308402b9553630734e9c36b77a7e48b3821251ca2493e8cd596763aafaa" +checksum = "d979acc56dcb5b8dddba3917601745e877576475aa046df3226eabdecef78eed" dependencies = [ "bytes", "hyper", @@ -817,9 +815,9 @@ dependencies = [ [[package]] name = "image" -version = "0.23.6" +version = "0.23.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5b0553fec6407d63fe2975b794dfb099f3f790bdc958823851af37b26404ab4" +checksum = "a2397fc43bd5648b7117aabb3c5e62d0e62c194826ec77b0b4d0c41e62744635" dependencies = [ "bytemuck", "byteorder", @@ -833,11 +831,12 @@ dependencies = [ [[package]] name = "indexmap" -version = "1.4.0" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c398b2b113b55809ceb9ee3e753fcbac793f1956663f3c36549c1346015c2afe" +checksum = "5b88cd59ee5f71fea89a62248fc8f387d44400cefe05ef548466d61ced9029a7" dependencies = [ "autocfg", + "hashbrown", ] [[package]] @@ -846,6 +845,12 @@ version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb6ee2a7da03bfc3b66ca47c92c2e392fcc053ea040a85561749b026f7aad09a" +[[package]] +name = "instant" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b141fdc7836c525d4d594027d318c84161ca17aaf8113ab1f81ab93ae897485" + [[package]] name = "iovec" version = "0.1.4" @@ -855,6 +860,12 @@ dependencies = [ "libc", ] +[[package]] +name = "ipnet" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47be2f14c678be2fdcab04ab1171db51b2762ce6f0a8ee87c8dd4a04ed216135" + [[package]] name = "itoa" version = "0.4.6" @@ -863,27 +874,27 @@ checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6" [[package]] name = "jpeg-decoder" -version = "0.1.19" +version = "0.1.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b47b4c4e017b01abdc5bcc126d2d1002e5a75bbe3ce73f9f4f311a916363704" +checksum = "cc797adac5f083b8ff0ca6f6294a999393d76e197c36488e2ef732c4715f6fa3" dependencies = [ "byteorder", ] [[package]] name = "js-sys" -version = "0.3.40" +version = "0.3.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce10c23ad2ea25ceca0093bd3192229da4c5b3c0f2de499c1ecac0d98d452177" +checksum = "52732a3d3ad72c58ad2dc70624f9c17b46ecd0943b9a4f1ee37c4c18c5d983e2" dependencies = [ "wasm-bindgen", ] [[package]] name = "js_int" -version = "0.1.8" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b2b63d60564122f2a7d6592c2f1d6c1c60e7a266b4d24715950a1ddad784f66" +checksum = "b96797f53235a1d6dc985f244a69de54b04c45b7e0e357a35c85a45a847d92f2" dependencies = [ "serde", ] @@ -906,39 +917,28 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.71" +version = "0.2.73" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9457b06509d27052635f90d6466700c65095fdf75409b3fbdd903e988b886f49" +checksum = "bd7d4bd64732af4bf3a67f367c27df8520ad7e230c5817b8ff485864d80242b9" [[package]] name = "lock_api" -version = "0.3.4" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4da24a77a3d8a6d4862d95f72e6fdb9c09a643ecdb402d754004a557f2bec75" +checksum = "28247cc5a5be2f05fbcd76dd0cf2c7d3b5400cb978a28042abcd4fa0b3f8261c" dependencies = [ "scopeguard", ] [[package]] name = "log" -version = "0.4.8" +version = "0.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7" +checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b" dependencies = [ "cfg-if", ] -[[package]] -name = "loom" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ecc775857611e1df29abba5c41355cdf540e7e9d4acfdf0f355eefee82330b7" -dependencies = [ - "cfg-if", - "generator", - "scoped-tls", -] - [[package]] name = "lzw" version = "0.10.0" @@ -965,9 +965,9 @@ checksum = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400" [[package]] name = "memoffset" -version = "0.5.4" +version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4fc2c02a7e374099d4ee95a193111f72d2110197fe200272371758f6c3643d8" +checksum = "c198b026e1bbf08a937e94c6c60f9ec4a2267f5b0d2eec9c1b21b061ce2be55f" dependencies = [ "autocfg", ] @@ -997,6 +997,15 @@ dependencies = [ "adler32", ] +[[package]] +name = "miniz_oxide" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be0f75932c1f6cfae3c04000e40114adf955636e19040f9c0a2c380702aa1c7f" +dependencies = [ + "adler", +] + [[package]] name = "mio" version = "0.6.22" @@ -1137,6 +1146,12 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c" +[[package]] +name = "opaque-debug" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" + [[package]] name = "openssl" version = "0.10.30" @@ -1172,22 +1187,24 @@ dependencies = [ [[package]] name = "parking_lot" -version = "0.10.2" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3a704eb390aafdc107b0e392f56a82b668e3a71366993b5340f5833fd62505e" +checksum = "a4893845fa2ca272e647da5d0e46660a314ead9c2fdd9a883aabc32e481a8733" dependencies = [ + "instant", "lock_api", "parking_lot_core", ] [[package]] name = "parking_lot_core" -version = "0.7.2" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d58c7c768d4ba344e3e8d72518ac13e259d7c7ade24167003b8488e10b6740a3" +checksum = "c361aa727dd08437f2f1447be8b59a33b0edd15e0fcee698f935613d9efbca9b" dependencies = [ "cfg-if", "cloudabi", + "instant", "libc", "redox_syscall", "smallvec", @@ -1255,27 +1272,27 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "pkg-config" -version = "0.3.17" +version = "0.3.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05da548ad6865900e60eaba7f589cc0783590a92e940c26953ff81ddbab2d677" +checksum = "d36492546b6af1463394d46f0c834346f31548646f6ba10849802c9c9a27ac33" [[package]] name = "png" -version = "0.16.5" +version = "0.16.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34ccdd66f6fe4b2433b07e4728e9a013e43233120427046e93ceb709c3a439bf" +checksum = "dfe7f9f1c730833200b134370e1d5098964231af8450bce9b78ee3ab5278b970" dependencies = [ "bitflags", "crc32fast", "deflate", - "miniz_oxide", + "miniz_oxide 0.3.7", ] [[package]] name = "polyval" -version = "0.3.3" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ec3341498978de3bfd12d1b22f1af1de22818f5473a11e8a6ef997989e3a212" +checksum = "d9a50142b55ab3ed0e9f68dfb3709f1d90d29da24e91033f28b96330643107dc" dependencies = [ "cfg-if", "universal-hash", @@ -1301,9 +1318,9 @@ checksum = "eba180dafb9038b050a4c280019bbedf9f2467b61e5d892dcad585bb57aadc5a" [[package]] name = "proc-macro2" -version = "1.0.18" +version = "1.0.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "beae6331a816b1f65d04c45b078fd8e6c93e8071771f41b8163255bbd8d7c8fa" +checksum = "04f5f085b5d71e2188cb8271e5da0161ad52c3f227a661a3c135fdf28e258b12" dependencies = [ "unicode-xid", ] @@ -1372,9 +1389,9 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.1.56" +version = "0.1.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84" +checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" [[package]] name = "redox_users" @@ -1418,9 +1435,9 @@ dependencies = [ [[package]] name = "reqwest" -version = "0.10.6" +version = "0.10.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b82c9238b305f26f53443e3a4bc8528d64b8d0bee408ec949eb7bf5635ec680" +checksum = "12427a5577082c24419c9c417db35cfeb65962efc7675bb6b0d5f1f9d315bfe6" dependencies = [ "base64 0.12.3", "bytes", @@ -1431,6 +1448,7 @@ dependencies = [ "http-body", "hyper", "hyper-tls", + "ipnet", "js-sys", "lazy_static", "log", @@ -1527,26 +1545,27 @@ dependencies = [ [[package]] name = "ruma" version = "0.1.0" -source = "git+https://github.com/timokoesters/ruma#5a30f9cfc6c168f25cfcf51f3d80b3594c0f59b1" +source = "git+https://github.com/ruma/ruma?rev=08fbace#08fbace022f732319b9c5d2b97954b935bf39bf2" dependencies = [ "ruma-api", "ruma-client-api", "ruma-common", "ruma-events", "ruma-federation-api", - "ruma-identifiers", + "ruma-identifiers 0.17.0 (git+https://github.com/ruma/ruma?rev=08fbace)", + "ruma-identifiers-macros", "ruma-signatures", ] [[package]] name = "ruma-api" version = "0.16.1" -source = "git+https://github.com/timokoesters/ruma#5a30f9cfc6c168f25cfcf51f3d80b3594c0f59b1" +source = "git+https://github.com/ruma/ruma?rev=08fbace#08fbace022f732319b9c5d2b97954b935bf39bf2" dependencies = [ "http", "percent-encoding", "ruma-api-macros", - "ruma-identifiers", + "ruma-identifiers 0.17.0 (git+https://github.com/ruma/ruma?rev=08fbace)", "ruma-serde", "serde", "serde_json", @@ -1556,7 +1575,7 @@ dependencies = [ [[package]] name = "ruma-api-macros" version = "0.16.1" -source = "git+https://github.com/timokoesters/ruma#5a30f9cfc6c168f25cfcf51f3d80b3594c0f59b1" +source = "git+https://github.com/ruma/ruma?rev=08fbace#08fbace022f732319b9c5d2b97954b935bf39bf2" dependencies = [ "proc-macro2", "quote", @@ -1566,14 +1585,14 @@ dependencies = [ [[package]] name = "ruma-client-api" version = "0.9.0" -source = "git+https://github.com/timokoesters/ruma#5a30f9cfc6c168f25cfcf51f3d80b3594c0f59b1" +source = "git+https://github.com/ruma/ruma?rev=08fbace#08fbace022f732319b9c5d2b97954b935bf39bf2" dependencies = [ "http", "js_int", "ruma-api", "ruma-common", "ruma-events", - "ruma-identifiers", + "ruma-identifiers 0.17.0 (git+https://github.com/ruma/ruma?rev=08fbace)", "ruma-serde", "serde", "serde_json", @@ -1582,10 +1601,10 @@ dependencies = [ [[package]] name = "ruma-common" -version = "0.1.3" -source = "git+https://github.com/timokoesters/ruma#5a30f9cfc6c168f25cfcf51f3d80b3594c0f59b1" +version = "0.2.0" +source = "git+https://github.com/ruma/ruma?rev=08fbace#08fbace022f732319b9c5d2b97954b935bf39bf2" dependencies = [ - "matches", + "js_int", "ruma-serde", "serde", "serde_json", @@ -1595,12 +1614,12 @@ dependencies = [ [[package]] name = "ruma-events" version = "0.21.3" -source = "git+https://github.com/ruma/ruma-events?rev=c1ee72d#c1ee72db0f3107a97f6a4273a0ea3fed5c4c30e2" +source = "git+https://github.com/ruma/ruma?rev=08fbace#08fbace022f732319b9c5d2b97954b935bf39bf2" dependencies = [ "js_int", "ruma-common", "ruma-events-macros", - "ruma-identifiers", + "ruma-identifiers 0.17.0 (git+https://github.com/ruma/ruma?rev=08fbace)", "ruma-serde", "serde", "serde_json", @@ -1610,7 +1629,7 @@ dependencies = [ [[package]] name = "ruma-events-macros" version = "0.21.3" -source = "git+https://github.com/ruma/ruma-events?rev=c1ee72d#c1ee72db0f3107a97f6a4273a0ea3fed5c4c30e2" +source = "git+https://github.com/ruma/ruma?rev=08fbace#08fbace022f732319b9c5d2b97954b935bf39bf2" dependencies = [ "proc-macro2", "quote", @@ -1620,13 +1639,13 @@ dependencies = [ [[package]] name = "ruma-federation-api" version = "0.0.2" -source = "git+https://github.com/timokoesters/ruma#5a30f9cfc6c168f25cfcf51f3d80b3594c0f59b1" +source = "git+https://github.com/ruma/ruma?rev=08fbace#08fbace022f732319b9c5d2b97954b935bf39bf2" dependencies = [ "js_int", - "matches", "ruma-api", + "ruma-common", "ruma-events", - "ruma-identifiers", + "ruma-identifiers 0.17.0 (git+https://github.com/ruma/ruma?rev=08fbace)", "ruma-serde", "serde", "serde_json", @@ -1634,31 +1653,51 @@ dependencies = [ [[package]] name = "ruma-identifiers" -version = "0.16.2" -source = "git+https://github.com/timokoesters/ruma#5a30f9cfc6c168f25cfcf51f3d80b3594c0f59b1" +version = "0.17.0" +source = "git+https://github.com/ruma/ruma?rev=08fbace#08fbace022f732319b9c5d2b97954b935bf39bf2" dependencies = [ "rand", "serde", "strum", ] +[[package]] +name = "ruma-identifiers" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7046d6ff26cf4f5b8bc77af68527544c61e32cab5810c40035c6491c08da0d3" +dependencies = [ + "serde", + "strum", +] + +[[package]] +name = "ruma-identifiers-macros" +version = "0.17.0" +source = "git+https://github.com/ruma/ruma?rev=08fbace#08fbace022f732319b9c5d2b97954b935bf39bf2" +dependencies = [ + "proc-macro2", + "quote", + "ruma-identifiers 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)", + "syn", +] + [[package]] name = "ruma-serde" version = "0.2.2" -source = "git+https://github.com/timokoesters/ruma#5a30f9cfc6c168f25cfcf51f3d80b3594c0f59b1" +source = "git+https://github.com/ruma/ruma?rev=08fbace#08fbace022f732319b9c5d2b97954b935bf39bf2" dependencies = [ - "dtoa", + "form_urlencoded", "itoa", "js_int", "serde", "serde_json", - "url", ] [[package]] name = "ruma-signatures" version = "0.6.0-dev.1" -source = "git+https://github.com/timokoesters/ruma#5a30f9cfc6c168f25cfcf51f3d80b3594c0f59b1" +source = "git+https://github.com/ruma/ruma?rev=08fbace#08fbace022f732319b9c5d2b97954b935bf39bf2" dependencies = [ "base64 0.12.3", "ring", @@ -1734,12 +1773,6 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "scoped-tls" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "332ffa32bf586782a3efaeb58f127980944bbc8c4d6913a86107ac2a5ab24b28" - [[package]] name = "scopeguard" version = "1.1.0" @@ -1816,9 +1849,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.55" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec2c5d7e739bc07a3e73381a39d61fdb5f671c60c1df26a130690665803d8226" +checksum = "3433e879a558dde8b5e8feb2a04899cf34fdde1fafb894687e52105fc1162ac3" dependencies = [ "itoa", "ryu", @@ -1845,14 +1878,15 @@ checksum = "2579985fda508104f7587689507983eadd6a6e84dd35d6d115361f530916fa0d" [[package]] name = "sha2" -version = "0.8.2" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a256f46ea78a0c0d9ff00077504903ac881a1dafdc20da66545699e7776b3e69" +checksum = "2933378ddfeda7ea26f48c555bdad8bb446bf8a3d17832dc83e380d444cfb8c1" dependencies = [ "block-buffer", + "cfg-if", + "cpuid-bool", "digest", - "fake-simd", - "opaque-debug", + "opaque-debug 0.3.0", ] [[package]] @@ -1873,10 +1907,11 @@ checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" [[package]] name = "sled" -version = "0.32.0" +version = "0.32.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdad3dc85d888056d3bd9954ffdf22d8a22701b6cd3aca4f6df4c436111898c4" +checksum = "7e3dbbb8ee10611bd1d020767c27599ccbbf8365f7e0ed7e54429cc8b9433ad8" dependencies = [ + "array-init", "backtrace", "crc32fast", "crossbeam-epoch", @@ -1890,9 +1925,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.4.0" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7cb5678e1615754284ec264d9bb5b4c27d2018577fd90ac0ceb578591ed5ee4" +checksum = "3757cb9d89161a2f24e1cf78efa0c1fcff485d18e3f55e0aa3480824ddaa0f3f" [[package]] name = "socket2" @@ -1997,12 +2032,6 @@ dependencies = [ "syn", ] -[[package]] -name = "subtle" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d67a5a62ba6e01cb2192ff309324cb4875d0c451d55fe2319433abe7a05a8ee" - [[package]] name = "subtle" version = "2.2.3" @@ -2011,9 +2040,9 @@ checksum = "502d53007c02d7605a05df1c1a73ee436952781653da5d0bf57ad608f66932c1" [[package]] name = "syn" -version = "1.0.33" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8d5d96e8cbb005d6959f119f773bfaebb5684296108fb32600c00cde305b2cd" +checksum = "fb7f4c519df8c117855e19dd8cc851e89eb746fe7a73f0157e0d95fdec5369b0" dependencies = [ "proc-macro2", "quote", @@ -2110,9 +2139,9 @@ checksum = "53953d2d3a5ad81d9f844a32f14ebb121f50b650cd59d0ee2a07cf13c617efed" [[package]] name = "tokio" -version = "0.2.21" +version = "0.2.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d099fa27b9702bed751524694adbe393e18b36b204da91eb1cbbbbb4a5ee2d58" +checksum = "5d34ca54d84bf2b5b4d7d31e901a8464f7b60ac145a284fba25ceb801f2ddccd" dependencies = [ "bytes", "fnv", @@ -2194,10 +2223,30 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e987b6bf443f4b5b3b6f38704195592cca41c5bb7aedd3c3693c7081f8289860" [[package]] -name = "try-lock" -version = "0.2.2" +name = "tracing" +version = "0.1.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e604eb7b43c06650e854be16a2a03155743d3752dd1c943f6829e26b7a36e382" +checksum = "dbdf4ccd1652592b01286a5dbe1e2a77d78afaa34beadd9872a5f7396f92aaa9" +dependencies = [ + "cfg-if", + "log", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94ae75f0d28ae10786f3b1895c55fe72e79928fd5ccdebb5438c75e93fec178f" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "try-lock" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" [[package]] name = "typenum" @@ -2246,12 +2295,12 @@ checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" [[package]] name = "universal-hash" -version = "0.3.0" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df0c900f2f9b4116803415878ff48b63da9edb268668e08cf9292d7503114a01" +checksum = "8326b2c654932e3e4f9196e69d08fdf7cfd718e1dc6f66b347e6024a0c961402" dependencies = [ "generic-array", - "subtle 2.2.3", + "subtle", ] [[package]] @@ -2301,9 +2350,9 @@ checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" [[package]] name = "wasm-bindgen" -version = "0.2.63" +version = "0.2.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c2dc4aa152834bc334f506c1a06b866416a8b6697d5c9f75b9a689c8486def0" +checksum = "f3edbcc9536ab7eababcc6d2374a0b7bfe13a2b6d562c5e07f370456b1a8f33d" dependencies = [ "cfg-if", "serde", @@ -2313,9 +2362,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.63" +version = "0.2.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded84f06e0ed21499f6184df0e0cb3494727b0c5da89534e0fcc55c51d812101" +checksum = "89ed2fb8c84bfad20ea66b26a3743f3e7ba8735a69fe7d95118c33ec8fc1244d" dependencies = [ "bumpalo", "lazy_static", @@ -2328,9 +2377,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.13" +version = "0.4.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64487204d863f109eb77e8462189d111f27cb5712cc9fdb3461297a76963a2f6" +checksum = "41ad6e4e8b2b7f8c90b6e09a9b590ea15cb0d1dbe28502b5a405cd95d1981671" dependencies = [ "cfg-if", "js-sys", @@ -2340,9 +2389,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.63" +version = "0.2.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "838e423688dac18d73e31edce74ddfac468e37b1506ad163ffaf0a46f703ffe3" +checksum = "eb071268b031a64d92fc6cf691715ca5a40950694d8f683c5bb43db7c730929e" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -2350,9 +2399,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.63" +version = "0.2.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3156052d8ec77142051a533cdd686cba889537b213f948cd1d20869926e68e92" +checksum = "cf592c807080719d1ff2f245a687cbadb3ed28b2077ed7084b47aba8b691f2c6" dependencies = [ "proc-macro2", "quote", @@ -2363,15 +2412,15 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.63" +version = "0.2.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9ba19973a58daf4db6f352eda73dc0e289493cd29fb2632eb172085b6521acd" +checksum = "72b6c0220ded549d63860c78c38f3bcc558d1ca3f4efa74942c536ddbbb55e87" [[package]] name = "web-sys" -version = "0.3.40" +version = "0.3.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b72fe77fd39e4bd3eaa4412fd299a0be6b3dfe9d2597e2f1c20beb968f41d17" +checksum = "8be2398f326b7ba09815d0b403095f34dd708579220d099caae89be0b32137b2" dependencies = [ "js-sys", "wasm-bindgen", @@ -2445,9 +2494,3 @@ name = "yansi" version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9fc79f4a1e39857fc00c3f662cbf2651c771f00e9c15fe2abc341806bd46bd71" - -[[package]] -name = "zeroize" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3cbac2ed2ba24cc90f5e06485ac8c7c1e5449fe8911aef4d8877218af021a5b8" diff --git a/Cargo.toml b/Cargo.toml index 0ca3ac3..e0f246e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,18 +27,4 @@ reqwest = "0.10.6" base64 = "0.12.1" thiserror = "1.0.19" image = { version = "0.23.4", default-features = false, features = ["jpeg", "png", "gif"] } - -[dependencies.ruma] -git = "https://github.com/timokoesters/ruma" -#rev = "baa87104569b45dc07a9a7a16d3c7592ab8f4d6b" -#path = "../ruma/ruma" -features = ["rand", "client-api", "federation-api"] - -# These are required only until ruma-events and ruma-federation-api are merged into ruma/ruma -[patch.crates-io] -ruma-common = { git = "https://github.com/timokoesters/ruma" } -ruma-serde = { git = "https://github.com/timokoesters/ruma" } -ruma-identifiers = { git = "https://github.com/timokoesters/ruma" } -#ruma-common = { path = "../ruma/ruma-common" } -#ruma-serde = { path = "../ruma/ruma-serde" } -#ruma-identifiers = { path = "../ruma/ruma-identifiers" } +ruma = { git = "https://github.com/ruma/ruma", features = ["rand", "client-api", "federation-api", "unstable-pre-spec", "unstable-synapse-quirks"], rev = "08fbace" } diff --git a/src/client_server.rs b/src/client_server.rs index f4a34b2..9676f7b 100644 --- a/src/client_server.rs +++ b/src/client_server.rs @@ -60,12 +60,12 @@ use ruma::{ unversioned::get_supported_versions, }, events::{ - collections::only::Event as EduEvent, room::{ canonical_alias, guest_access, history_visibility, join_rules, member, name, redaction, topic, }, - EventJson, EventType, + AnyBasicEvent, AnyEphemeralRoomEvent, AnyEvent, AnySyncEphemeralRoomEvent, EventJson, + EventType, }, identifiers::{RoomAliasId, RoomId, RoomVersionId, UserId}, }; @@ -169,14 +169,14 @@ pub fn register_route( if let Some(auth) = &body.auth { let (worked, uiaainfo) = db.uiaa - .try_auth(&user_id, "", auth, &uiaainfo, &db.users, &db.globals)?; + .try_auth(&user_id, "".into(), auth, &uiaainfo, &db.users, &db.globals)?; if !worked { return Err(Error::Uiaa(uiaainfo)); } // Success! } else { uiaainfo.session = Some(utils::random_string(SESSION_ID_LENGTH)); - db.uiaa.create(&user_id, "", &uiaainfo)?; + db.uiaa.create(&user_id, "".into(), &uiaainfo)?; return Err(Error::Uiaa(uiaainfo)); } @@ -189,7 +189,7 @@ pub fn register_route( let device_id = body .device_id .clone() - .unwrap_or_else(|| utils::random_string(DEVICE_ID_LENGTH)); + .unwrap_or_else(|| utils::random_string(DEVICE_ID_LENGTH).into()); // Generate new token for the device let token = utils::random_string(TOKEN_LENGTH); @@ -221,7 +221,7 @@ pub fn register_route( Ok(register::Response { access_token: Some(token), user_id, - device_id: Some(device_id), + device_id: Some(device_id.into()), } .into()) } @@ -269,7 +269,7 @@ pub fn login_route( .body .device_id .clone() - .unwrap_or_else(|| utils::random_string(DEVICE_ID_LENGTH)); + .unwrap_or_else(|| utils::random_string(DEVICE_ID_LENGTH).into()); // Generate a new token for the device let token = utils::random_string(TOKEN_LENGTH); @@ -286,7 +286,7 @@ pub fn login_route( user_id, access_token: token, home_server: Some(db.globals.server_name().to_owned()), - device_id, + device_id: device_id.into(), well_known: None, } .into()) @@ -300,7 +300,7 @@ pub fn logout_route( let user_id = body.user_id.as_ref().expect("user is authenticated"); let device_id = body.device_id.as_ref().expect("user is authenticated"); - db.users.remove_device(&user_id, &device_id)?; + db.users.remove_device(&user_id, device_id)?; Ok(logout::Response.into()) } @@ -340,14 +340,9 @@ pub fn change_password_route( }; if let Some(auth) = &body.auth { - let (worked, uiaainfo) = db.uiaa.try_auth( - &user_id, - &device_id, - auth, - &uiaainfo, - &db.users, - &db.globals, - )?; + let (worked, uiaainfo) = + db.uiaa + .try_auth(&user_id, device_id, auth, &uiaainfo, &db.users, &db.globals)?; if !worked { return Err(Error::Uiaa(uiaainfo)); } @@ -452,11 +447,11 @@ pub fn deactivate_route( pub fn get_capabilities_route() -> ConduitResult { let mut available = BTreeMap::new(); available.insert( - RoomVersionId::version_5(), + RoomVersionId::Version5, get_capabilities::RoomVersionStability::Stable, ); available.insert( - RoomVersionId::version_6(), + RoomVersionId::Version6, get_capabilities::RoomVersionStability::Stable, ); @@ -480,7 +475,7 @@ pub fn get_pushrules_all_route( ) -> ConduitResult { let user_id = body.user_id.as_ref().expect("user is authenticated"); - if let EduEvent::PushRules(pushrules) = db + if let AnyEvent::Basic(AnyBasicEvent::PushRules(pushrules)) = db .account_data .get(None, &user_id, &EventType::PushRules)? .ok_or(Error::BadRequest( @@ -594,7 +589,7 @@ pub fn get_global_account_data_route( ) -> ConduitResult { let user_id = body.user_id.as_ref().expect("user is authenticated"); - let data = db + let event = db .account_data .get( None, @@ -603,6 +598,9 @@ pub fn get_global_account_data_route( )? .ok_or(Error::BadRequest(ErrorKind::NotFound, "Data not found."))?; + let data = serde_json::from_str(event.json().get()) + .map_err(|_| Error::bad_database("Invalid account data event in db."))?; + Ok(get_global_account_data::Response { account_data: data }.into()) } @@ -888,7 +886,7 @@ pub fn get_keys_route( device_display_name: metadata.display_name, }); - container.insert(device_id.to_owned(), keys); + container.insert(device_id, keys); } } device_keys.insert(user_id.clone(), container); @@ -1099,7 +1097,7 @@ pub fn set_read_marker_route( content: ruma::events::fully_read::FullyReadEventContent { event_id: body.fully_read.clone(), }, - room_id: Some(body.room_id.clone()), + room_id: body.room_id.clone(), }) .expect("we just created a valid event") .as_object_mut() @@ -1135,10 +1133,12 @@ pub fn set_read_marker_route( db.rooms.edus.roomlatest_update( &user_id, &body.room_id, - EduEvent::Receipt(ruma::events::receipt::ReceiptEvent { - content: receipt_content, - room_id: None, // None because it can be inferred - }), + AnyEvent::Ephemeral(AnyEphemeralRoomEvent::Receipt( + ruma::events::receipt::ReceiptEvent { + content: ruma::events::receipt::ReceiptEventContent(receipt_content), + room_id: body.room_id.clone(), + }, + )), &db.globals, )?; } @@ -1181,8 +1181,7 @@ pub fn create_room_route( ) -> ConduitResult { let user_id = body.user_id.as_ref().expect("user is authenticated"); - let room_id = RoomId::new(db.globals.server_name()) - .map_err(|_| Error::bad_database("Server name is invalid."))?; + let room_id = RoomId::new(db.globals.server_name()); let alias = body .room_alias_name @@ -1203,21 +1202,20 @@ pub fn create_room_route( } })?; + let mut content = ruma::events::room::create::CreateEventContent::new(user_id.clone()); + content.federate = body.creation_content.as_ref().map_or(true, |c| c.federate); + content.predecessor = body + .creation_content + .as_ref() + .and_then(|c| c.predecessor.clone()); + content.room_version = RoomVersionId::Version6; + // 1. The room create event db.rooms.append_pdu( room_id.clone(), user_id.clone(), EventType::RoomCreate, - serde_json::to_value(ruma::events::room::create::CreateEventContent { - creator: user_id.clone(), - federate: body.creation_content.as_ref().map_or(true, |c| c.federate), - predecessor: body - .creation_content - .as_ref() - .and_then(|c| c.predecessor.clone()), - room_version: RoomVersionId::version_6(), - }) - .expect("event is valid, we just created it"), + serde_json::to_value(content).expect("event is valid, we just created it"), None, Some("".to_owned()), None, @@ -1296,15 +1294,14 @@ pub fn create_room_route( user_id.clone(), EventType::RoomJoinRules, match preset { - create_room::RoomPreset::PublicChat => { - serde_json::to_value(join_rules::JoinRulesEventContent { - join_rule: join_rules::JoinRule::Public, - }) - .expect("event is valid, we just created it") - } - _ => serde_json::to_value(join_rules::JoinRulesEventContent { - join_rule: join_rules::JoinRule::Invite, - }) + create_room::RoomPreset::PublicChat => serde_json::to_value( + join_rules::JoinRulesEventContent::new(join_rules::JoinRule::Public), + ) + .expect("event is valid, we just created it"), + // according to spec "invite" is the default + _ => serde_json::to_value(join_rules::JoinRulesEventContent::new( + join_rules::JoinRule::Invite, + )) .expect("event is valid, we just created it"), }, None, @@ -1318,9 +1315,9 @@ pub fn create_room_route( room_id.clone(), user_id.clone(), EventType::RoomHistoryVisibility, - serde_json::to_value(history_visibility::HistoryVisibilityEventContent { - history_visibility: history_visibility::HistoryVisibility::Shared, - }) + serde_json::to_value(history_visibility::HistoryVisibilityEventContent::new( + history_visibility::HistoryVisibility::Shared, + )) .expect("event is valid, we just created it"), None, Some("".to_owned()), @@ -1334,15 +1331,13 @@ pub fn create_room_route( user_id.clone(), EventType::RoomGuestAccess, match preset { - create_room::RoomPreset::PublicChat => { - serde_json::to_value(guest_access::GuestAccessEventContent { - guest_access: guest_access::GuestAccess::Forbidden, - }) - .expect("event is valid, we just created it") - } - _ => serde_json::to_value(guest_access::GuestAccessEventContent { - guest_access: guest_access::GuestAccess::CanJoin, - }) + create_room::RoomPreset::PublicChat => serde_json::to_value( + guest_access::GuestAccessEventContent::new(guest_access::GuestAccess::Forbidden), + ) + .expect("event is valid, we just created it"), + _ => serde_json::to_value(guest_access::GuestAccessEventContent::new( + guest_access::GuestAccess::CanJoin, + )) .expect("event is valid, we just created it"), }, None, @@ -1533,7 +1528,7 @@ pub fn get_alias_route( Ok(get_alias::Response { room_id, - servers: vec![db.globals.server_name().to_owned()], + servers: vec![db.globals.server_name().to_string()], } .into()) } @@ -2521,7 +2516,7 @@ pub fn sync_route( let room_events = pdus .into_iter() - .map(|pdu| pdu.to_room_event()) + .map(|pdu| pdu.to_sync_room_event()) .collect::>(); let mut edus = db @@ -2539,7 +2534,7 @@ pub fn sync_route( { edus.push( serde_json::from_str( - &serde_json::to_string(&EduEvent::Typing( + &serde_json::to_string(&AnySyncEphemeralRoomEvent::Typing( db.rooms.edus.roomactives_all(&room_id)?, )) .expect("event is valid, we just created it"), @@ -2554,8 +2549,12 @@ pub fn sync_route( .account_data .changes_since(Some(&room_id), &user_id, since)? .into_iter() - .map(|(_, v)| v) - .collect(), + .filter_map(|(_, v)| { + serde_json::from_str(v.json().get()) + .map_err(|_| Error::bad_database("Invalid account event in database.")) + .ok() + }) + .collect::>(), }, summary: sync_events::RoomSummary { heroes, @@ -2567,11 +2566,7 @@ pub fn sync_route( notification_count, }, timeline: sync_events::Timeline { - limited: if limited || joined_since_last_sync { - Some(true) - } else { - None - }, + limited: limited || joined_since_last_sync, prev_batch, events: room_events, }, @@ -2581,7 +2576,7 @@ pub fn sync_route( db.rooms .room_state_full(&room_id)? .into_iter() - .map(|(_, pdu)| pdu.to_state_event()) + .map(|(_, pdu)| pdu.to_sync_state_event()) .collect() } else { Vec::new() @@ -2601,7 +2596,7 @@ pub fn sync_route( let pdus = db.rooms.pdus_since(&user_id, &room_id, since)?; let room_events = pdus .filter_map(|pdu| pdu.ok()) // Filter out buggy events - .map(|pdu| pdu.to_room_event()) + .map(|pdu| pdu.to_sync_room_event()) .collect(); // TODO: Only until leave point @@ -2620,7 +2615,7 @@ pub fn sync_route( { edus.push( serde_json::from_str( - &serde_json::to_string(&EduEvent::Typing( + &serde_json::to_string(&AnySyncEphemeralRoomEvent::Typing( db.rooms.edus.roomactives_all(&room_id)?, )) .expect("event is valid, we just created it"), @@ -2632,7 +2627,7 @@ pub fn sync_route( let left_room = sync_events::LeftRoom { account_data: sync_events::AccountData { events: Vec::new() }, timeline: sync_events::Timeline { - limited: Some(false), + limited: false, prev_batch: Some(next_batch.clone()), events: room_events, }, @@ -2696,8 +2691,12 @@ pub fn sync_route( .account_data .changes_since(None, &user_id, since)? .into_iter() - .map(|(_, v)| v) - .collect(), + .filter_map(|(_, v)| { + serde_json::from_str(v.json().get()) + .map_err(|_| Error::bad_database("Invalid account event in database.")) + .ok() + }) + .collect::>(), }, device_lists: sync_events::DeviceLists { changed: if since != 0 { @@ -2839,17 +2838,17 @@ pub fn get_message_events_route( .clone() .parse() .map_err(|_| Error::BadRequest(ErrorKind::InvalidParam, "Invalid `from` value."))?; + let limit = body + .limit + .try_into() + .map_or(Ok::<_, Error>(10_usize), |l: u32| Ok(l as usize))?; match body.dir { get_message_events::Direction::Forward => { let events_after = db .rooms .pdus_after(&user_id, &body.room_id, from) // Use limit or else 10 - .take(body.limit.map_or(Ok::<_, Error>(10_usize), |l| { - Ok(u32::try_from(l).map_err(|_| { - Error::BadRequest(ErrorKind::InvalidParam, "Limit value is invalid.") - })? as usize) - })?) + .take(limit) .filter_map(|r| r.ok()) // Filter out buggy events .collect::>(); @@ -2880,11 +2879,7 @@ pub fn get_message_events_route( .rooms .pdus_until(&user_id, &body.room_id, from) // Use limit or else 10 - .take(body.limit.map_or(Ok::<_, Error>(10_usize), |l| { - Ok(u32::try_from(l).map_err(|_| { - Error::BadRequest(ErrorKind::InvalidParam, "Limit value is invalid.") - })? as usize) - })?) + .take(limit) .filter_map(|r| r.ok()) // Filter out buggy events .collect::>(); diff --git a/src/database/account_data.rs b/src/database/account_data.rs index befd937..3b64ba7 100644 --- a/src/database/account_data.rs +++ b/src/database/account_data.rs @@ -1,7 +1,7 @@ use crate::{utils, Error, Result}; use ruma::{ api::client::error::ErrorKind, - events::{collections::only::Event as EduEvent, EventJson, EventType}, + events::{AnyEvent as EduEvent, EventJson, EventType}, identifiers::{RoomId, UserId}, }; use std::{collections::HashMap, convert::TryFrom}; diff --git a/src/database/globals.rs b/src/database/globals.rs index a767d8a..d59e1c3 100644 --- a/src/database/globals.rs +++ b/src/database/globals.rs @@ -1,12 +1,14 @@ -use crate::{utils, Error, Result}; +use std::convert::TryInto; +use crate::{utils, Error, Result}; +use ruma::identifiers::ServerName; pub const COUNTER: &str = "c"; pub struct Globals { pub(super) globals: sled::Tree, keypair: ruma::signatures::Ed25519KeyPair, reqwest_client: reqwest::Client, - server_name: String, + server_name: Box, registration_disabled: bool, } @@ -27,7 +29,9 @@ impl Globals { server_name: config .get_str("server_name") .unwrap_or("localhost") - .to_owned(), + .to_string() + .try_into() + .map_err(|_| Error::BadConfig("Invalid server name found."))?, registration_disabled: config.get_bool("registration_disabled").unwrap_or(false), }) } @@ -59,8 +63,8 @@ impl Globals { }) } - pub fn server_name(&self) -> &str { - &self.server_name + pub fn server_name(&self) -> &ServerName { + self.server_name.as_ref() } pub fn registration_disabled(&self) -> bool { diff --git a/src/database/key_backups.rs b/src/database/key_backups.rs index 991931b..eb31b8d 100644 --- a/src/database/key_backups.rs +++ b/src/database/key_backups.rs @@ -2,7 +2,7 @@ use crate::{utils, Error, Result}; use ruma::{ api::client::{ error::ErrorKind, - r0::backup::{get_backup_keys::Sessions, BackupAlgorithm, KeyData}, + r0::backup::{BackupAlgorithm, KeyData, Sessions}, }, identifiers::{RoomId, UserId}, }; diff --git a/src/database/rooms.rs b/src/database/rooms.rs index b7f7221..7e6036d 100644 --- a/src/database/rooms.rs +++ b/src/database/rooms.rs @@ -529,7 +529,7 @@ impl Rooms { auth_events: Vec::new(), redacts: redacts.clone(), unsigned, - hashes: ruma::api::federation::EventHash { + hashes: ruma::events::pdu::EventHash { sha256: "aaa".to_owned(), }, signatures: HashMap::new(), @@ -547,7 +547,7 @@ impl Rooms { let mut pdu_json = serde_json::to_value(&pdu).expect("event is valid, we just created it"); ruma::signatures::hash_and_sign_event( - globals.server_name(), + globals.server_name().as_str(), globals.keypair(), &mut pdu_json, ) diff --git a/src/database/rooms/edus.rs b/src/database/rooms/edus.rs index 645ccb0..b96f1b1 100644 --- a/src/database/rooms/edus.rs +++ b/src/database/rooms/edus.rs @@ -1,6 +1,6 @@ use crate::{utils, Error, Result}; use ruma::{ - events::{collections::only::Event as EduEvent, EventJson}, + events::{AnyEvent as EduEvent, EventJson, SyncEphemeralRoomEvent}, identifiers::{RoomId, UserId}, }; use std::convert::TryFrom; @@ -61,7 +61,8 @@ impl RoomEdus { &self, room_id: &RoomId, since: u64, - ) -> Result>>> { + ) -> Result>>> + { let mut prefix = room_id.to_string().as_bytes().to_vec(); prefix.push(0xff); @@ -208,8 +209,10 @@ impl RoomEdus { .unwrap_or(0)) } - /// Returns an iterator over all active events (e.g. typing notifications). - pub fn roomactives_all(&self, room_id: &RoomId) -> Result { + pub fn roomactives_all( + &self, + room_id: &RoomId, + ) -> Result> { let mut prefix = room_id.to_string().as_bytes().to_vec(); prefix.push(0xff); @@ -233,9 +236,8 @@ impl RoomEdus { user_ids.push(user_id?); } - Ok(ruma::events::typing::TypingEvent { + Ok(SyncEphemeralRoomEvent { content: ruma::events::typing::TypingEventContent { user_ids }, - room_id: None, // Can be inferred }) } diff --git a/src/database/uiaa.rs b/src/database/uiaa.rs index 1272d5f..d490499 100644 --- a/src/database/uiaa.rs +++ b/src/database/uiaa.rs @@ -4,7 +4,7 @@ use ruma::{ error::ErrorKind, r0::uiaa::{AuthData, UiaaInfo}, }, - identifiers::UserId, + identifiers::{DeviceId, UserId}, }; pub struct Uiaa { @@ -13,14 +13,19 @@ pub struct Uiaa { impl Uiaa { /// Creates a new Uiaa session. Make sure the session token is unique. - pub fn create(&self, user_id: &UserId, device_id: &str, uiaainfo: &UiaaInfo) -> Result<()> { + pub fn create( + &self, + user_id: &UserId, + device_id: &DeviceId, + uiaainfo: &UiaaInfo, + ) -> Result<()> { self.update_uiaa_session(user_id, device_id, Some(uiaainfo)) } pub fn try_auth( &self, user_id: &UserId, - device_id: &str, + device_id: &DeviceId, auth: &AuthData, uiaainfo: &UiaaInfo, users: &super::users::Users, @@ -130,7 +135,7 @@ impl Uiaa { // UIAA was successful! Remove this session and return true self.update_uiaa_session(user_id, device_id, None)?; - return Ok((true, uiaainfo)); + Ok((true, uiaainfo)) } else { panic!("FallbackAcknowledgement is not supported yet"); } @@ -139,12 +144,12 @@ impl Uiaa { fn update_uiaa_session( &self, user_id: &UserId, - device_id: &str, + device_id: &DeviceId, uiaainfo: Option<&UiaaInfo>, ) -> Result<()> { let mut userdeviceid = user_id.to_string().as_bytes().to_vec(); userdeviceid.push(0xff); - userdeviceid.extend_from_slice(device_id.as_bytes()); + userdeviceid.extend_from_slice(device_id.as_str().as_bytes()); if let Some(uiaainfo) = uiaainfo { self.userdeviceid_uiaainfo.insert( @@ -161,12 +166,12 @@ impl Uiaa { fn get_uiaa_session( &self, user_id: &UserId, - device_id: &str, + device_id: &DeviceId, session: &str, ) -> Result { let mut userdeviceid = user_id.to_string().as_bytes().to_vec(); userdeviceid.push(0xff); - userdeviceid.extend_from_slice(device_id.as_bytes()); + userdeviceid.extend_from_slice(device_id.as_str().as_bytes()); let uiaainfo = serde_json::from_slice::( &self diff --git a/src/database/users.rs b/src/database/users.rs index 2ccf59a..3a02a9d 100644 --- a/src/database/users.rs +++ b/src/database/users.rs @@ -8,8 +8,8 @@ use ruma::{ keys::{AlgorithmAndDeviceId, CrossSigningKey, DeviceKeys, KeyAlgorithm, OneTimeKey}, }, }, - events::{to_device::AnyToDeviceEvent, EventJson, EventType}, - identifiers::UserId, + events::{AnyToDeviceEvent, EventJson, EventType}, + identifiers::{DeviceId, UserId}, }; use std::{collections::BTreeMap, convert::TryFrom, time::SystemTime}; @@ -168,7 +168,7 @@ impl Users { pub fn create_device( &self, user_id: &UserId, - device_id: &str, + device_id: &DeviceId, token: &str, initial_device_display_name: Option, ) -> Result<()> { @@ -177,12 +177,12 @@ impl Users { let mut userdeviceid = user_id.to_string().as_bytes().to_vec(); userdeviceid.push(0xff); - userdeviceid.extend_from_slice(device_id.as_bytes()); + userdeviceid.extend_from_slice(device_id.as_str().as_bytes()); self.userdeviceid_metadata.insert( userdeviceid, serde_json::to_string(&Device { - device_id: device_id.to_owned(), + device_id: device_id.into(), display_name: initial_device_display_name, last_seen_ip: None, // TODO last_seen_ts: Some(SystemTime::now()), @@ -191,16 +191,16 @@ impl Users { .as_bytes(), )?; - self.set_token(user_id, device_id, token)?; + self.set_token(user_id, &device_id, token)?; Ok(()) } /// Removes a device from a user. - pub fn remove_device(&self, user_id: &UserId, device_id: &str) -> Result<()> { + pub fn remove_device(&self, user_id: &UserId, device_id: &DeviceId) -> Result<()> { let mut userdeviceid = user_id.to_string().as_bytes().to_vec(); userdeviceid.push(0xff); - userdeviceid.extend_from_slice(device_id.as_bytes()); + userdeviceid.extend_from_slice(device_id.as_str().as_bytes()); // Remove tokens if let Some(old_token) = self.userdeviceid_token.remove(&userdeviceid)? { @@ -223,7 +223,7 @@ impl Users { } /// Returns an iterator over all device ids of this user. - pub fn all_device_ids(&self, user_id: &UserId) -> impl Iterator> { + pub fn all_device_ids(&self, user_id: &UserId) -> impl Iterator>> { let mut prefix = user_id.to_string().as_bytes().to_vec(); prefix.push(0xff); // All devices have metadata @@ -237,17 +237,16 @@ impl Users { .next() .ok_or_else(|| Error::bad_database("UserDevice ID in db is invalid."))?, ) - .map_err(|_| { - Error::bad_database("Device ID in userdeviceid_metadata is invalid.") - })?) + .map_err(|_| Error::bad_database("Device ID in userdeviceid_metadata is invalid."))? + .into()) }) } /// Replaces the access token of one device. - fn set_token(&self, user_id: &UserId, device_id: &str, token: &str) -> Result<()> { + fn set_token(&self, user_id: &UserId, device_id: &DeviceId, token: &str) -> Result<()> { let mut userdeviceid = user_id.to_string().as_bytes().to_vec(); userdeviceid.push(0xff); - userdeviceid.extend_from_slice(device_id.as_bytes()); + userdeviceid.extend_from_slice(device_id.as_str().as_bytes()); // All devices have metadata assert!(self.userdeviceid_metadata.get(&userdeviceid)?.is_some()); @@ -268,13 +267,13 @@ impl Users { pub fn add_one_time_key( &self, user_id: &UserId, - device_id: &str, + device_id: &DeviceId, one_time_key_key: &AlgorithmAndDeviceId, one_time_key_value: &OneTimeKey, ) -> Result<()> { let mut key = user_id.to_string().as_bytes().to_vec(); key.push(0xff); - key.extend_from_slice(device_id.as_bytes()); + key.extend_from_slice(device_id.as_str().as_bytes()); // All devices have metadata // Only existing devices should be able to call this. @@ -301,12 +300,12 @@ impl Users { pub fn take_one_time_key( &self, user_id: &UserId, - device_id: &str, + device_id: &DeviceId, key_algorithm: &KeyAlgorithm, ) -> Result> { let mut prefix = user_id.to_string().as_bytes().to_vec(); prefix.push(0xff); - prefix.extend_from_slice(device_id.as_bytes()); + prefix.extend_from_slice(device_id.as_str().as_bytes()); prefix.push(0xff); prefix.push(b'"'); // Annoying quotation mark prefix.extend_from_slice(key_algorithm.to_string().as_bytes()); @@ -337,11 +336,11 @@ impl Users { pub fn count_one_time_keys( &self, user_id: &UserId, - device_id: &str, + device_id: &DeviceId, ) -> Result> { let mut userdeviceid = user_id.to_string().as_bytes().to_vec(); userdeviceid.push(0xff); - userdeviceid.extend_from_slice(device_id.as_bytes()); + userdeviceid.extend_from_slice(device_id.as_str().as_bytes()); let mut counts = BTreeMap::new(); @@ -370,13 +369,13 @@ impl Users { pub fn add_device_keys( &self, user_id: &UserId, - device_id: &str, + device_id: &DeviceId, device_keys: &DeviceKeys, globals: &super::globals::Globals, ) -> Result<()> { let mut userdeviceid = user_id.to_string().as_bytes().to_vec(); userdeviceid.push(0xff); - userdeviceid.extend_from_slice(device_id.as_bytes()); + userdeviceid.extend_from_slice(device_id.as_str().as_bytes()); self.keyid_key.insert( &userdeviceid, @@ -550,10 +549,14 @@ impl Users { }) } - pub fn get_device_keys(&self, user_id: &UserId, device_id: &str) -> Result> { + pub fn get_device_keys( + &self, + user_id: &UserId, + device_id: &DeviceId, + ) -> Result> { let mut key = user_id.to_string().as_bytes().to_vec(); key.push(0xff); - key.extend_from_slice(device_id.as_bytes()); + key.extend_from_slice(device_id.as_str().as_bytes()); self.keyid_key.get(key)?.map_or(Ok(None), |bytes| { Ok(Some(serde_json::from_slice(&bytes).map_err(|_| { @@ -633,14 +636,14 @@ impl Users { &self, sender: &UserId, target_user_id: &UserId, - target_device_id: &str, + target_device_id: &DeviceId, event_type: &EventType, content: serde_json::Value, globals: &super::globals::Globals, ) -> Result<()> { let mut key = target_user_id.to_string().as_bytes().to_vec(); key.push(0xff); - key.extend_from_slice(target_device_id.as_bytes()); + key.extend_from_slice(target_device_id.as_str().as_bytes()); key.push(0xff); key.extend_from_slice(&globals.next_count()?.to_be_bytes()); @@ -660,14 +663,14 @@ impl Users { pub fn take_to_device_events( &self, user_id: &UserId, - device_id: &str, + device_id: &DeviceId, max: usize, ) -> Result>> { let mut events = Vec::new(); let mut prefix = user_id.to_string().as_bytes().to_vec(); prefix.push(0xff); - prefix.extend_from_slice(device_id.as_bytes()); + prefix.extend_from_slice(device_id.as_str().as_bytes()); prefix.push(0xff); for result in self.todeviceid_events.scan_prefix(&prefix).take(max) { @@ -685,12 +688,12 @@ impl Users { pub fn update_device_metadata( &self, user_id: &UserId, - device_id: &str, + device_id: &DeviceId, device: &Device, ) -> Result<()> { let mut userdeviceid = user_id.to_string().as_bytes().to_vec(); userdeviceid.push(0xff); - userdeviceid.extend_from_slice(device_id.as_bytes()); + userdeviceid.extend_from_slice(device_id.as_str().as_bytes()); // Only existing devices should be able to call this. assert!(self.userdeviceid_metadata.get(&userdeviceid)?.is_some()); @@ -706,10 +709,14 @@ impl Users { } /// Get device metadata. - pub fn get_device_metadata(&self, user_id: &UserId, device_id: &str) -> Result> { + pub fn get_device_metadata( + &self, + user_id: &UserId, + device_id: &DeviceId, + ) -> Result> { let mut userdeviceid = user_id.to_string().as_bytes().to_vec(); userdeviceid.push(0xff); - userdeviceid.extend_from_slice(device_id.as_bytes()); + userdeviceid.extend_from_slice(device_id.as_str().as_bytes()); self.userdeviceid_metadata .get(&userdeviceid)? diff --git a/src/pdu.rs b/src/pdu.rs index 8a5858e..0db77a1 100644 --- a/src/pdu.rs +++ b/src/pdu.rs @@ -1,14 +1,12 @@ use crate::{Error, Result}; use js_int::UInt; use ruma::{ - api::federation::EventHash, events::{ - collections::all::{RoomEvent, StateEvent}, - room::member::MemberEvent, - stripped::AnyStrippedStateEvent, - EventJson, EventType, + pdu::EventHash, room::member::MemberEventContent, AnyRoomEvent, AnyStateEvent, + AnyStrippedStateEvent, AnySyncRoomEvent, AnySyncStateEvent, EventJson, EventType, + StateEvent, }, - identifiers::{EventId, RoomId, UserId}, + identifiers::{EventId, RoomId, ServerName, UserId}, }; use serde::{Deserialize, Serialize}; use serde_json::json; @@ -19,7 +17,7 @@ pub struct PduEvent { pub event_id: EventId, pub room_id: RoomId, pub sender: UserId, - pub origin: String, + pub origin: Box, pub origin_server_ts: UInt, #[serde(rename = "type")] pub kind: EventType, @@ -81,24 +79,40 @@ impl PduEvent { Ok(()) } - pub fn to_room_event(&self) -> EventJson { + pub fn to_sync_room_event(&self) -> EventJson { let json = serde_json::to_string(&self).expect("PDUs are always valid"); - serde_json::from_str::>(&json) - .expect("EventJson::from_str always works") + serde_json::from_str::(&json) + .map(EventJson::from) + .expect("AnySyncRoomEvent can always be built from a full PDU event") } - pub fn to_state_event(&self) -> EventJson { + pub fn to_room_event(&self) -> EventJson { let json = serde_json::to_string(&self).expect("PDUs are always valid"); - serde_json::from_str::>(&json) - .expect("EventJson::from_str always works") + serde_json::from_str::(&json) + .map(EventJson::from) + .expect("AnyRoomEvent can always be built from a full PDU event") + } + pub fn to_state_event(&self) -> EventJson { + let json = serde_json::to_string(&self).expect("PDUs are always valid"); + serde_json::from_str::(&json) + .map(EventJson::from) + .expect("AnyStateEvent can always be built from a full PDU event") + } + pub fn to_sync_state_event(&self) -> EventJson { + let json = serde_json::to_string(&self).expect("PDUs are always valid"); + serde_json::from_str::(&json) + .map(EventJson::from) + .expect("AnySyncStateEvent can always be built from a full PDU event") } pub fn to_stripped_state_event(&self) -> EventJson { let json = serde_json::to_string(&self).expect("PDUs are always valid"); - serde_json::from_str::>(&json) - .expect("EventJson::from_str always works") + serde_json::from_str::(&json) + .map(EventJson::from) + .expect("AnyStrippedStateEvent can always be built from a full PDU event") } - pub fn to_member_event(&self) -> EventJson { + pub fn to_member_event(&self) -> EventJson> { let json = serde_json::to_string(&self).expect("PDUs are always valid"); - serde_json::from_str::>(&json) - .expect("EventJson::from_str always works") + serde_json::from_str::>(&json) + .map(EventJson::from) + .expect("StateEvent can always be built from a full PDU event") } } diff --git a/src/push_rules.rs b/src/push_rules.rs index 90e9243..5bc0d74 100644 --- a/src/push_rules.rs +++ b/src/push_rules.rs @@ -1,45 +1,47 @@ +use js_int::uint; use ruma::{ - events::push_rules::{ConditionalPushRule, PatternedPushRule, PushCondition, Ruleset}, identifiers::UserId, - push::{Action, Tweak}, + push::{ + Action, ConditionalPushRule, ConditionalPushRuleInit, PatternedPushRule, + PatternedPushRuleInit, PushCondition, RoomMemberCountIs, Ruleset, Tweak, + }, }; pub fn default_pushrules(user_id: &UserId) -> Ruleset { - Ruleset { - content: vec![contains_user_name_rule(&user_id)], - override_: vec![ - master_rule(), - suppress_notices_rule(), - invite_for_me_rule(), - member_event_rule(), - contains_display_name_rule(), - tombstone_rule(), - roomnotif_rule(), - ], - room: vec![], - sender: vec![], - underride: vec![ - call_rule(), - encrypted_room_one_to_one_rule(), - room_one_to_one_rule(), - message_rule(), - encrypted_rule(), - ], - } + let mut rules = Ruleset::default(); + rules.content = vec![contains_user_name_rule(&user_id)]; + rules.override_ = vec![ + master_rule(), + suppress_notices_rule(), + invite_for_me_rule(), + member_event_rule(), + contains_display_name_rule(), + tombstone_rule(), + roomnotif_rule(), + ]; + rules.underride = vec![ + call_rule(), + encrypted_room_one_to_one_rule(), + room_one_to_one_rule(), + message_rule(), + encrypted_rule(), + ]; + rules } pub fn master_rule() -> ConditionalPushRule { - ConditionalPushRule { + ConditionalPushRuleInit { actions: vec![Action::DontNotify], default: true, enabled: false, rule_id: ".m.rule.master".to_owned(), conditions: vec![], } + .into() } pub fn suppress_notices_rule() -> ConditionalPushRule { - ConditionalPushRule { + ConditionalPushRuleInit { actions: vec![Action::DontNotify], default: true, enabled: true, @@ -49,10 +51,11 @@ pub fn suppress_notices_rule() -> ConditionalPushRule { pattern: "m.notice".to_owned(), }], } + .into() } pub fn invite_for_me_rule() -> ConditionalPushRule { - ConditionalPushRule { + ConditionalPushRuleInit { actions: vec![ Action::Notify, Action::SetTweak(Tweak::Sound("default".to_owned())), @@ -66,10 +69,11 @@ pub fn invite_for_me_rule() -> ConditionalPushRule { pattern: "m.invite".to_owned(), }], } + .into() } pub fn member_event_rule() -> ConditionalPushRule { - ConditionalPushRule { + ConditionalPushRuleInit { actions: vec![Action::DontNotify], default: true, enabled: true, @@ -79,10 +83,11 @@ pub fn member_event_rule() -> ConditionalPushRule { pattern: "type".to_owned(), }], } + .into() } pub fn contains_display_name_rule() -> ConditionalPushRule { - ConditionalPushRule { + ConditionalPushRuleInit { actions: vec![ Action::Notify, Action::SetTweak(Tweak::Sound("default".to_owned())), @@ -93,10 +98,11 @@ pub fn contains_display_name_rule() -> ConditionalPushRule { rule_id: ".m.rule.contains_display_name".to_owned(), conditions: vec![PushCondition::ContainsDisplayName], } + .into() } pub fn tombstone_rule() -> ConditionalPushRule { - ConditionalPushRule { + ConditionalPushRuleInit { actions: vec![Action::Notify, Action::SetTweak(Tweak::Highlight(true))], default: true, enabled: true, @@ -112,10 +118,11 @@ pub fn tombstone_rule() -> ConditionalPushRule { }, ], } + .into() } pub fn roomnotif_rule() -> ConditionalPushRule { - ConditionalPushRule { + ConditionalPushRuleInit { actions: vec![Action::Notify, Action::SetTweak(Tweak::Highlight(true))], default: true, enabled: true, @@ -130,10 +137,11 @@ pub fn roomnotif_rule() -> ConditionalPushRule { }, ], } + .into() } pub fn contains_user_name_rule(user_id: &UserId) -> PatternedPushRule { - PatternedPushRule { + PatternedPushRuleInit { actions: vec![ Action::Notify, Action::SetTweak(Tweak::Sound("default".to_owned())), @@ -144,10 +152,11 @@ pub fn contains_user_name_rule(user_id: &UserId) -> PatternedPushRule { rule_id: ".m.rule.contains_user_name".to_owned(), pattern: user_id.localpart().to_owned(), } + .into() } pub fn call_rule() -> ConditionalPushRule { - ConditionalPushRule { + ConditionalPushRuleInit { actions: vec![ Action::Notify, Action::SetTweak(Tweak::Sound("ring".to_owned())), @@ -161,10 +170,11 @@ pub fn call_rule() -> ConditionalPushRule { pattern: "m.call.invite".to_owned(), }], } + .into() } pub fn encrypted_room_one_to_one_rule() -> ConditionalPushRule { - ConditionalPushRule { + ConditionalPushRuleInit { actions: vec![ Action::Notify, Action::SetTweak(Tweak::Sound("default".to_owned())), @@ -174,17 +184,20 @@ pub fn encrypted_room_one_to_one_rule() -> ConditionalPushRule { enabled: true, rule_id: ".m.rule.encrypted_room_one_to_one".to_owned(), conditions: vec![ - PushCondition::RoomMemberCount { is: "2".to_owned() }, + PushCondition::RoomMemberCount { + is: RoomMemberCountIs::from(uint!(2)..), + }, PushCondition::EventMatch { key: "type".to_owned(), pattern: "m.room.encrypted".to_owned(), }, ], } + .into() } pub fn room_one_to_one_rule() -> ConditionalPushRule { - ConditionalPushRule { + ConditionalPushRuleInit { actions: vec![ Action::Notify, Action::SetTweak(Tweak::Sound("default".to_owned())), @@ -194,17 +207,20 @@ pub fn room_one_to_one_rule() -> ConditionalPushRule { enabled: true, rule_id: ".m.rule.room_one_to_one".to_owned(), conditions: vec![ - PushCondition::RoomMemberCount { is: "2".to_owned() }, + PushCondition::RoomMemberCount { + is: RoomMemberCountIs::from(uint!(2)..), + }, PushCondition::EventMatch { key: "type".to_owned(), pattern: "m.room.message".to_owned(), }, ], } + .into() } pub fn message_rule() -> ConditionalPushRule { - ConditionalPushRule { + ConditionalPushRuleInit { actions: vec![Action::Notify, Action::SetTweak(Tweak::Highlight(false))], default: true, enabled: true, @@ -214,10 +230,11 @@ pub fn message_rule() -> ConditionalPushRule { pattern: "m.room.message".to_owned(), }], } + .into() } pub fn encrypted_rule() -> ConditionalPushRule { - ConditionalPushRule { + ConditionalPushRuleInit { actions: vec![Action::Notify, Action::SetTweak(Tweak::Highlight(false))], default: true, enabled: true, @@ -227,4 +244,5 @@ pub fn encrypted_rule() -> ConditionalPushRule { pattern: "m.room.encrypted".to_owned(), }], } + .into() } diff --git a/src/ruma_wrapper.rs b/src/ruma_wrapper.rs index 48f5487..cd2d21e 100644 --- a/src/ruma_wrapper.rs +++ b/src/ruma_wrapper.rs @@ -7,7 +7,10 @@ use rocket::{ Outcome::*, Request, State, }; -use ruma::{api::Endpoint, identifiers::UserId}; +use ruma::{ + api::Endpoint, + identifiers::{DeviceId, UserId}, +}; use std::{convert::TryInto, io::Cursor, ops::Deref}; use tokio::io::AsyncReadExt; @@ -18,7 +21,7 @@ const MESSAGE_LIMIT: u64 = 20 * 1024 * 1024; // 20 MB pub struct Ruma { pub body: T, pub user_id: Option, - pub device_id: Option, + pub device_id: Option>, pub json_body: Option>, // This is None when body is not a valid string } @@ -63,7 +66,7 @@ impl<'a, T: Endpoint> FromTransformedData<'a> for Ruma { match db.users.find_from_token(&token).unwrap() { // TODO: M_UNKNOWN_TOKEN None => return Failure((Status::Unauthorized, ())), - Some((user_id, device_id)) => (Some(user_id), Some(device_id)), + Some((user_id, device_id)) => (Some(user_id), Some(device_id.into())), } } else { (None, None)