From 65643227131793a7b2c422bc16f8fa91103702ba Mon Sep 17 00:00:00 2001 From: Sandipsinh Rathod Date: Sat, 29 Jun 2024 11:58:47 +0530 Subject: [PATCH 1/6] chore: switch to `rsa` --- .gitignore | 1 - CHANGELOG.md | 24 -- Cargo.lock | 552 +++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 23 +- LICENSE.md | 2 +- README.md | 54 ++--- lint.sh | 50 ++++ src/keystore.rs | 50 ++++ src/lib.rs | 11 +- src/privkey.rs | 150 +++++------- src/pubkey.rs | 90 ++++---- src/tests.rs | 21 -- tests/test_wasm.rs | 19 ++ tests/tests.rs | 19 ++ 14 files changed, 820 insertions(+), 246 deletions(-) delete mode 100644 CHANGELOG.md create mode 100644 Cargo.lock create mode 100755 lint.sh create mode 100644 src/keystore.rs delete mode 100644 src/tests.rs create mode 100644 tests/test_wasm.rs create mode 100644 tests/tests.rs diff --git a/.gitignore b/.gitignore index 4fffb2f..ea8c4bf 100755 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1 @@ /target -/Cargo.lock diff --git a/CHANGELOG.md b/CHANGELOG.md deleted file mode 100644 index 3db25b7..0000000 --- a/CHANGELOG.md +++ /dev/null @@ -1,24 +0,0 @@ -# 0.1.0 -* Initial release -# 0.2.0 -* some bug fixes and introduction to so-called [double encryption](https://www.mindupstream.com/ssdd/zot/zotcrypto/posts/encrypto-rsa#doubleenc) and [double decryption methods](https://www.mindupstream.com/ssdd/zot/zotcrypto/posts/encrypto-rsa#doubledec) -# 0.2.1 -* minor bug fixed -# 1.2.1 -* Renamed some functions and changed functionality (see [README](README.md)) -# 2.0.0 -* Major bug fixes (anyone was able to decrypt with any private key) -# 3.0.0 -* Made ZotPublicKey and ZotPrivateKey structs public -* Fixed readme -# 3.1.0 -* Added `get_private_key(&self)` function which returns ZotPrivateKey struct. -# 3.1.1 -* Change input type from string to bytes -* Tested with corresponding Java dependency -# 3.1.2 -* Added encryption methods to ZotPublicKey struct itself. -# 3.1.3 -* Some bug fixes -# 3.1.4 -* Fixed bitlength issue. (It used to generate the modulo 2x the entered bit-length) \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..0d61f76 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,552 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "anyhow" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "base64ct" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" + +[[package]] +name = "bumpalo" +version = "3.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "console_error_panic_hook" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a06aeb73f470f66dcdbf7223caeebb85984942f22f1adb2a088cf9668146bbbc" +dependencies = [ + "cfg-if", + "wasm-bindgen", +] + +[[package]] +name = "const-oid" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "der" +version = "0.7.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" +dependencies = [ + "const-oid", + "pem-rfc7468", + "zeroize", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "const-oid", + "crypto-common", +] + +[[package]] +name = "encrypto_rsa" +version = "5.0.0" +dependencies = [ + "anyhow", + "base64", + "getrandom", + "rand", + "rsa", + "serde_json", + "wasm-bindgen-test", +] + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "wasi", + "wasm-bindgen", +] + +[[package]] +name = "itoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "js-sys" +version = "0.3.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" +dependencies = [ + "spin", +] + +[[package]] +name = "libc" +version = "0.2.155" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" + +[[package]] +name = "libm" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" + +[[package]] +name = "log" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "num-bigint-dig" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc84195820f291c7697304f3cbdadd1cb7199c0efc917ff5eafd71225c136151" +dependencies = [ + "byteorder", + "lazy_static", + "libm", + "num-integer", + "num-iter", + "num-traits", + "rand", + "serde", + "smallvec", + "zeroize", +] + +[[package]] +name = "num-integer" +version = "0.1.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-iter" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1429034a0490724d0075ebb2bc9e875d6503c3cf69e235a8941aa757d83ef5bf" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", + "libm", +] + +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "pem-rfc7468" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88b39c9bfcfc231068454382784bb460aae594343fb030d46e9f50a645418412" +dependencies = [ + "base64ct", +] + +[[package]] +name = "pkcs1" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8ffb9f10fa047879315e6625af03c164b16962a5368d724ed16323b68ace47f" +dependencies = [ + "der", + "pkcs8", + "spki", +] + +[[package]] +name = "pkcs8" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" +dependencies = [ + "der", + "spki", +] + +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + +[[package]] +name = "proc-macro2" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "rsa" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d0e5124fcb30e76a7e79bfee683a2746db83784b86289f6251b54b7950a0dfc" +dependencies = [ + "const-oid", + "digest", + "num-bigint-dig", + "num-integer", + "num-traits", + "pkcs1", + "pkcs8", + "rand_core", + "serde", + "signature", + "spki", + "subtle", + "zeroize", +] + +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + +[[package]] +name = "scoped-tls" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" + +[[package]] +name = "serde" +version = "1.0.203" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7253ab4de971e72fb7be983802300c30b5a7f0c2e56fab8abfc6a214307c0094" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.203" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.118" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d947f6b3163d8857ea16c4fa0dd4840d52f3041039a85decd46867eb1abef2e4" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "signature" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" +dependencies = [ + "digest", + "rand_core", +] + +[[package]] +name = "smallvec" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + +[[package]] +name = "spki" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" +dependencies = [ + "base64ct", + "der", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.68" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "901fa70d88b9d6c98022e23b4136f9f3e54e4662c3bc1bd1d84a42a9a0f0c1e9" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "typenum" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76bc14366121efc8dbb487ab05bcc9d346b3b5ec0eaa76e46594cabbe51762c0" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" + +[[package]] +name = "wasm-bindgen-test" +version = "0.3.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9bf62a58e0780af3e852044583deee40983e5886da43a271dd772379987667b" +dependencies = [ + "console_error_panic_hook", + "js-sys", + "scoped-tls", + "wasm-bindgen", + "wasm-bindgen-futures", + "wasm-bindgen-test-macro", +] + +[[package]] +name = "wasm-bindgen-test-macro" +version = "0.3.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7f89739351a2e03cb94beb799d47fb2cac01759b40ec441f7de39b00cbf7ef0" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "web-sys" +version = "0.3.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77afa9a11836342370f4817622a2f0f418b134426d91a82dfb48f532d2ec13ef" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "zeroize" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" diff --git a/Cargo.toml b/Cargo.toml index e5d040c..f8d664a 100755 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "encrypto_rsa" -version = "4.0.0" +version = "5.0.0" edition = "2021" description = "stunning-encrypto is cross platform end-to-end encryption dependency." homepage = "https://www.ssdd.dev/zot/crypto/rsa/rust" @@ -11,15 +11,12 @@ categories = ["cryptography"] license = "MIT" [dependencies] -num-primes = "0.3.0" -rand = "0.8.5" -num = { version = "0.4.1", default-features = false } -num-bigint = { version = "0.4.4", features = ["rand", "serde"] } -base64 = "0.21.3" -#serde = { version = "1.0.147", features = ["derive"] } -#serde_json = {version = "1.0.89"} -#rsa = "0.7.2" -#pem = "1.1.0" -#libaes = "0.6.4" -#num-traits = "0.2.15" -#num-integer = "0.1.45" +rand = { version = "0.8.5",features = ["getrandom"] } +getrandom = {version = "0.2.15",features = ["wasm-bindgen", "js"]} +base64 = "0.22.1" +anyhow = "1.0.86" +rsa = {version = "0.9.6", features = ["serde"]} +serde_json = "1.0.118" + +[dev-dependencies] +wasm-bindgen-test = "0.3.42" \ No newline at end of file diff --git a/LICENSE.md b/LICENSE.md index 8aa2645..e70a359 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,6 +1,6 @@ MIT License -Copyright (c) [year] [fullname] +Copyright (c) 2024 Sandipsinh Rathod Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 21236a9..8d0c412 100644 --- a/README.md +++ b/README.md @@ -3,20 +3,20 @@ ![Crates Downloads](https://img.shields.io/crates/d/encrypto_rsa) # About Project -End to End encryption (RSA) for multiple languages (cross-platform) with [double encryption](https://www.ssdd.dev/ssdd/zot/crypto/posts/rsa#doubleenc) and [double decryption methods](https://www.ssdd.dev/ssdd/zot/crypto/posts/rsa#doubledec) +End to End NO STD, WASM supported, platform independent RSA encryption and decryption library for High Level Usage | Icon | Item | |:----:|:-----------------------------:| | 🥳 | [**Upcoming**](#Upcoming) | | ⚖️ | [**License**](#License) | -| 📝 | [**ChangeLog**](CHANGELOG.md) | # Usage (rust) ## Implementation ### Cargo -`encrypto_rsa =` [latest](https://crates.io/crates/encrypto_rsa) - +```shell +cargo add encrypto_rsa +``` ## RSA @@ -26,42 +26,26 @@ End to End encryption (RSA) for multiple languages (cross-platform) with [double ## You can try: ```rust - let mut x = Vec::new(); - - let encrypto = EncryptoRSA::init(512); - let encrypto1 = EncryptoRSA::init(512); - let msg = b"abc".as_slice(); - - let enc = encrypto.encrypt(msg, EncryptoRSA::desterilize_pub_key(encrypto1.get_sterilized_pub_key())).unwrap(); - let dec = encrypto1.decrypt(enc.as_bytes()); - x.push(dec); - - let enc = encrypto.encrypt_with_pkcsv1_15(msg, EncryptoRSA::desterilize_pub_key(encrypto1.get_sterilized_pub_key())).unwrap(); - let dec = encrypto1.decrypt_with_pkcsv1_15(enc.as_bytes()); - x.push(dec); - - let enc = encrypto.double_encrypt(msg, EncryptoRSA::desterilize_pub_key(encrypto1.get_sterilized_pub_key())).unwrap(); - let dec = encrypto1.double_decrypt(enc.as_bytes(), encrypto.get_public_key()); - x.push(dec); - - let enc = encrypto.double_encrypt_with_pkcsv1_15(msg, encrypto1.pbl.clone()).unwrap(); - let dec = encrypto1.double_decrypt_with_pkcsv1_15(enc, encrypto.pbl.clone()); - x.push(dec); - - for f in x.iter() { - assert_eq!(&msg.to_vec(), f); - } +use encrypto_rsa::keystore::EncryptoRSA; +fn main() { + use encrypto_rsa::EncryptoRSA; + let mut key_store = EncryptoRSA::init(2048).unwrap(); + let msg = "Alo"; + let encrypted = key_store.encrypt(msg).unwrap(); + let decrypted = key_store.decrypt(&encrypted).unwrap(); + assert_eq!(msg.as_bytes(), decrypted.as_slice()); +} ``` -### Please raise an issue [here](https://github.com/zotcrypto/encrypto-rsa-rust/issues) if the documentation isn't uploaded in long time +### Please raise an issue [here](https://github.com/zotcrypto/encrypto-rsa-rust/issues) for bug/feature report or documentation error ## Upcoming -| Supported Languages | Status | -|---------------------|-----------------------------------------------------------------------------------------------------------| -| Flutter | Completed and available [here](https://github.com/ssddcodes/stunning-encrypto/edit/encrypto/tree/flutter) | -| Java | Completed and available [here](https://github.com/ssddcodes/stunning-encrypto/) | -| JavaScript | Completed and available [here](https://github.com/ssddcodes/stunning-encrypto/edit/encrypto/tree/js) | +| Supported Languages | Status | +|---------------------|--------| +| Flutter | WIP | +| Java | WIP | +| JavaScript | WIP | * Amazing encrypto with prevention against man in the middle attacks and AES-CBC with RSA key exchange for multiple language diff --git a/lint.sh b/lint.sh new file mode 100755 index 0000000..d72f983 --- /dev/null +++ b/lint.sh @@ -0,0 +1,50 @@ +#!/bin/bash + +run_cargo_fmt() { + MODE=$1 + if [ "$MODE" == "check" ]; then + cargo fmt --all -- --check + else + cargo fmt --all + fi + return $? +} + +run_cargo_clippy() { + MODE=$1 + CMD="cargo clippy --all --all-targets --all-features" + if [ "$MODE" == "fix" ]; then + $CMD --fix --allow-staged --allow-dirty + fi + CMD="$CMD -- -D warnings" + $CMD + return $? +} + +# Extract the mode from the argument +if [[ $1 == "--mode="* ]]; then + MODE=${1#--mode=} +else + echo "Please specify a mode with --mode=check or --mode=fix" + exit 1 +fi + +# Run commands based on mode +case $MODE in + check|fix) + run_cargo_fmt $MODE + FMT_EXIT_CODE=$? + run_cargo_clippy $MODE + CLIPPY_EXIT_CODE=$? + + ;; + *) + echo "Invalid mode. Please use --mode=check or --mode=fix" + exit 1 + ;; +esac + +# If any command failed, exit with a non-zero status code +if [ $FMT_EXIT_CODE -ne 0 ] || [ $CLIPPY_EXIT_CODE -ne 0 ]; then + exit 1 +fi \ No newline at end of file diff --git a/src/keystore.rs b/src/keystore.rs new file mode 100644 index 0000000..dbf199f --- /dev/null +++ b/src/keystore.rs @@ -0,0 +1,50 @@ +use crate::privkey::ZotPrivateKey; +use crate::pubkey::ZotPublicKey; +use alloc::string::String; +use alloc::vec::Vec; + +#[derive(Debug, Clone, PartialEq)] +pub struct EncryptoRSA { + private_key: ZotPrivateKey, + public_key: ZotPublicKey, +} + +impl EncryptoRSA { + pub fn init(key_len: usize) -> anyhow::Result { + let private_key = ZotPrivateKey::init(key_len)?; + let public_key = private_key.to_public_key(); + Ok(Self { + private_key, + public_key, + }) + } + pub fn encrypt>(&mut self, msg: T) -> anyhow::Result { + self.public_key.encrypt(msg) + } + pub fn decrypt>(&mut self, msg: T) -> anyhow::Result> { + self.private_key.decrypt(msg) + } + pub fn pub_key(&self) -> &ZotPublicKey { + &self.public_key + } + pub fn serialize(&self) -> anyhow::Result { + self.private_key.serialize() + } + pub fn deserialize(serialized: &str) -> anyhow::Result { + let private_key = ZotPrivateKey::deserialize(serialized)?; + let public_key = private_key.to_public_key(); + Ok(Self { + private_key, + public_key, + }) + } +} + +impl TryFrom<&str> for EncryptoRSA { + type Error = anyhow::Error; + + fn try_from(value: &str) -> Result { + let key_store = Self::deserialize(value)?; + Ok(key_store) + } +} diff --git a/src/lib.rs b/src/lib.rs index 4f9b751..164e2df 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,10 +1,11 @@ #![no_std] extern crate alloc; -mod privkey; -mod pubkey; -mod tests; +use base64::engine::GeneralPurpose; -// type Result = std::result::Result>; -type Bytes = [u8]; +pub mod keystore; +pub mod privkey; +pub mod pubkey; +// entire lib will use the standard base64 engine +pub(crate) const B64_ENGINE: GeneralPurpose = base64::engine::general_purpose::STANDARD; diff --git a/src/privkey.rs b/src/privkey.rs index 933cb74..6e0627e 100644 --- a/src/privkey.rs +++ b/src/privkey.rs @@ -1,119 +1,75 @@ use alloc::string::String; -use alloc::vec; use alloc::vec::Vec; -use core::ops::Mul; -use base64::{Engine}; -use num::{One, Zero}; -use num::traits::FromBytes; -use num_bigint::{BigInt, BigUint, ToBigInt}; -use num_primes::Generator; -use crate::Bytes; + +use base64::Engine; +use rand::rngs::OsRng; +use rsa::rand_core::CryptoRngCore; +use rsa::traits::PaddingScheme; +use rsa::{Pkcs1v15Encrypt, RsaPrivateKey}; + use crate::pubkey::ZotPublicKey; +use crate::B64_ENGINE; -/// Struct to store private key -#[derive(Debug, Default, Clone)] +#[derive(Debug, Clone, PartialEq, Eq)] pub struct ZotPrivateKey { - d: BigUint, - p: BigUint, - q: BigUint, - on: BigUint, - pubkey: ZotPublicKey, + pub(crate) private_key: RsaPrivateKey, } + +// TODO: impl TryFrom<&str> for ZotPrivateKey impl ZotPrivateKey { - pub fn init(key_len: usize) -> Self { - let sz = key_len >> 1; - let pb = Generator::new_prime(sz).to_bytes_le(); - let qb = Generator::new_prime(sz).to_bytes_le(); - let p = BigUint::from_bytes_le(&*pb); - let q = BigUint::from_bytes_le(&*qb); - drop(pb); - drop(qb); - let n = (&p).mul(&q); - let e = BigUint::from(65537u32); - let bone = BigUint::one(); - let on = (&p - &bone).mul(&q - bone); - let d = modinv(e.to_bigint().unwrap(), on.to_bigint().unwrap()).unwrap(); - assert_eq!(&d * &e % &on, BigUint::one()); - let pubkey = ZotPublicKey::init(n,e, key_len); - Self { - d, - p, - q, - on, - pubkey, - } + pub fn init(key_len: usize) -> anyhow::Result { + let mut rng = OsRng; + let key = Self::init_rng(&mut rng, key_len)?; + Ok(key) } - pub fn get_pub_key(&self) -> &ZotPublicKey{ - &self.pubkey + pub fn init_rng( + rng: &mut R, + key_len: usize, + ) -> anyhow::Result { + let private_key = RsaPrivateKey::new(rng, key_len)?; + Ok(Self { private_key }) } - pub fn get_sharable_pub_key(&self) -> String { - self.pubkey.enc_pk() - } - pub fn decode_shared_pub_key(b64: String) -> ZotPublicKey { - // let dec = hex::decode(b64).unwrap(); - let dec = base64::engine::general_purpose::STANDARD_NO_PAD.decode(b64).unwrap(); - let mut e = vec![]; - let keylen = *dec.last().unwrap() as usize; - let mut n = vec![0;keylen]; - for i in 0..keylen { - let cur = dec.get(i).unwrap(); - n[i] = *cur; - } - let lmo = dec.len()-1; - for i in keylen..lmo { - let cur = dec.get(i).unwrap(); - e.push(*cur); - } - let n = BigUint::from_le_bytes(&*n); - let e = BigUint::from_le_bytes(&*e); - ZotPublicKey::init(n,e,keylen) + + pub fn decrypt>(&mut self, msg: T) -> anyhow::Result> { + self.decrypt_with_padding(msg, Pkcs1v15Encrypt) } - pub fn enc_priv(&self, msg: &Bytes) -> Option { - let len = msg.len(); - if len > 24 || len > (self.pubkey.get_keylen()>>3) { - return None; - } - let bi = BigUint::from_bytes_le(msg); - let bi = bi.modpow(&self.d,&self.pubkey.n); - let b64 = base64::engine::general_purpose::STANDARD_NO_PAD.encode(bi.to_bytes_le()); - Some(b64) + pub fn decrypt_with_padding, P: PaddingScheme>( + &mut self, + msg: T, + padding: P, + ) -> anyhow::Result> { + let dec = B64_ENGINE.decode(msg)?; + let result = self.private_key.decrypt(padding, dec.as_ref())?; + Ok(result) } - pub fn dec_priv(&self, msg: &Bytes) -> Option> { - let dec = match base64::engine::general_purpose::STANDARD_NO_PAD.decode(msg){ - Ok(v) => v, - Err(_) => return None - }; - let bi = BigUint::from_bytes_le(&*dec); - drop(dec); - let bi = bi.modpow(&self.d,&self.pubkey.n); - Some(bi.to_bytes_le()) + pub fn to_public_key(&self) -> ZotPublicKey { + ZotPublicKey::init(self) } - pub fn enc_public(&self, msg: &Bytes) -> Option { - self.pubkey.encrypt(msg) + pub fn serialize(&self) -> anyhow::Result { + Ok(serde_json::to_string(&self.private_key)?) } - - pub fn dec_public(&self, msg: &Bytes) -> Option> { - self.pubkey.decrypt(msg) + pub fn deserialize(serialized: &str) -> anyhow::Result { + let private_key = serde_json::from_str(serialized)?; + Ok(Self { private_key }) } } -fn egcd(a: BigInt, b: BigInt) -> (BigInt, BigInt, BigInt) { - if a == BigInt::zero() { - (b, BigInt::zero(), BigInt::one()) - } else { - let (g, x, y) = egcd(b.clone() % a.clone(), a.clone()); - (g, y - (b / a) * x.clone(), x) +impl TryFrom<&str> for ZotPrivateKey { + type Error = anyhow::Error; + + fn try_from(value: &str) -> Result { + let private_key = Self::deserialize(value)?; + Ok(private_key) } } -/// Returns modulo inverse -pub fn modinv(a: BigInt, m: BigInt) -> Option { - let (g, x, _) = egcd(a, m.clone()); - if g != BigInt::one() { - None - } else { - Some(((x % m.clone() + m.clone()) % m).to_biguint().unwrap()) +impl TryInto for ZotPrivateKey { + type Error = anyhow::Error; + + fn try_into(self) -> Result { + let serialized = self.serialize()?; + Ok(serialized) } -} \ No newline at end of file +} diff --git a/src/pubkey.rs b/src/pubkey.rs index 1138c2a..bff074f 100644 --- a/src/pubkey.rs +++ b/src/pubkey.rs @@ -1,62 +1,54 @@ use alloc::string::String; -use alloc::vec; -use alloc::vec::Vec; -use base64::{Engine}; -use num_bigint::BigUint; -use crate::Bytes; + +use base64::Engine; +use rand::rngs::OsRng; +use rsa::traits::PaddingScheme; +use rsa::{Pkcs1v15Encrypt, RsaPublicKey}; + +use crate::privkey::ZotPrivateKey; +use crate::B64_ENGINE; /// Struct to store public key -#[derive(Debug, Default, Clone)] +#[derive(Debug, Clone)] pub struct ZotPublicKey { - pub n: BigUint, - e: BigUint, - keylen: usize + public_key: RsaPublicKey, + rng: OsRng, +} + +impl PartialEq for ZotPublicKey { + fn eq(&self, other: &Self) -> bool { + self.public_key == other.public_key + } } impl ZotPublicKey { - pub fn init(n: BigUint, e: BigUint, keylen: usize) -> Self{ - Self{ - n, - e, - keylen, + pub fn init(priv_key: &ZotPrivateKey) -> Self { + Self { + public_key: priv_key.private_key.to_public_key(), + rng: OsRng, } } - pub fn encrypt(&self, msg: &Bytes) -> Option{ - let len = msg.len(); - if len > 24 || len > (self.keylen>>3) { - return None; - } - let bi = BigUint::from_bytes_le(msg); - let bi = bi.modpow(&self.e,&self.n); - let b64 = base64::engine::general_purpose::STANDARD_NO_PAD.encode(bi.to_bytes_le()); - Some(b64) + pub fn encrypt>(&mut self, msg: T) -> anyhow::Result { + self.encrypt_with_padding(msg, Pkcs1v15Encrypt) } - pub fn decrypt(&self, msg: &Bytes) -> Option> { - let dec = match base64::engine::general_purpose::STANDARD_NO_PAD.decode(msg) { - Ok(v) => { - v - } - Err(_) => { - return None; - } - }; - let bi = BigUint::from_bytes_le(&*dec); - drop(dec); - let bi = bi.modpow(&self.e,&self.n); - Some(bi.to_bytes_le()) + pub fn encrypt_with_padding, P: PaddingScheme>( + &mut self, + msg: T, + padding: P, + ) -> anyhow::Result { + let enc = self + .public_key + .encrypt(&mut self.rng, padding, msg.as_ref())?; + Ok(B64_ENGINE.encode(enc)) } - pub fn enc_pk(&self) -> String { - let mut nb = self.n.to_bytes_le(); - let nbl = nb.len(); - let mut s: Vec = vec![]; - s.append(&mut nb); - s.append(&mut self.e.to_bytes_le()); - s.push(nbl as u8); - // let b64 = hex::encode(s); - let b64 = base64::engine::general_purpose::STANDARD_NO_PAD.encode(&*s); - b64 + pub fn serialize(&self) -> anyhow::Result { + Ok(serde_json::to_string(&self.public_key)?) } - pub fn get_keylen(&self) -> &usize { - &self.keylen + pub fn deserialize(serialized: &str) -> anyhow::Result { + let public_key = serde_json::from_str(serialized)?; + Ok(Self { + public_key, + rng: OsRng, + }) } -} \ No newline at end of file +} diff --git a/src/tests.rs b/src/tests.rs deleted file mode 100644 index 7a77608..0000000 --- a/src/tests.rs +++ /dev/null @@ -1,21 +0,0 @@ -mod tests { - #[test] - fn genkey() { - // let privk = ZotPrivateKey::init(512); - // let ec = privk.get_sharable_pub_key(); - // println!("{}",ec); - // // let d = &privk.d; - // let pk = privk.get_pub_key(); - // // let n = &privk.on; - // // let e = modinv(d.to_bigint().unwrap(), n.to_bigint().unwrap()).unwrap(); - // let dc = ZotPrivateKey::decode_shared_pub_key(ec); - // assert_eq!(dc.n, pk.n); - // assert_eq!(dc.e, pk.e); - // // assert_eq!(privk.pubkey.e, e); - // let enc = privk.enc_priv("alo".as_bytes()).unwrap(); - // println!("{}",enc); - // let dec = privk.dec_public(enc.as_bytes()).unwrap(); - // println!("{}", String::from_utf8(dec).unwrap()); - // println!("{:?}", Verification::is_prime(&num_primes::BigUint::from_bytes_le(&*privk.q.to_bytes_le()))); - } -} \ No newline at end of file diff --git a/tests/test_wasm.rs b/tests/test_wasm.rs new file mode 100644 index 0000000..1cc01aa --- /dev/null +++ b/tests/test_wasm.rs @@ -0,0 +1,19 @@ +mod tests_wasm { + use encrypto_rsa::keystore::EncryptoRSA; + + #[wasm_bindgen_test::wasm_bindgen_test] + fn test_key_store() { + let mut key_store = EncryptoRSA::init(2048).unwrap(); + let msg = "Hello, world!"; + let encrypted = key_store.encrypt(msg).unwrap(); + let decrypted = key_store.decrypt(&encrypted).unwrap(); + assert_eq!(msg.as_bytes(), decrypted.as_slice()); + } + #[wasm_bindgen_test::wasm_bindgen_test] + fn test_serde_key_store() { + let key_store = EncryptoRSA::init(2048).unwrap(); + let serialized = key_store.serialize().unwrap(); + let deserialized = EncryptoRSA::try_from(serialized.as_str()).unwrap(); + assert_eq!(key_store, deserialized); + } +} diff --git a/tests/tests.rs b/tests/tests.rs new file mode 100644 index 0000000..ee6b4c4 --- /dev/null +++ b/tests/tests.rs @@ -0,0 +1,19 @@ +mod tests { + use encrypto_rsa::keystore::EncryptoRSA; + + #[test] + fn test_key_store() { + let mut key_store = EncryptoRSA::init(2048).unwrap(); + let msg = "Hello, world!"; + let encrypted = key_store.encrypt(msg).unwrap(); + let decrypted = key_store.decrypt(&encrypted).unwrap(); + assert_eq!(msg.as_bytes(), decrypted.as_slice()); + } + #[test] + fn test_serde_key_store() { + let key_store = EncryptoRSA::init(2048).unwrap(); + let serialized = key_store.serialize().unwrap(); + let deserialized = EncryptoRSA::try_from(serialized.as_str()).unwrap(); + assert_eq!(key_store, deserialized); + } +} From 60263b85164a7e5e6c5f30c66b0f5111cf766c57 Mon Sep 17 00:00:00 2001 From: Sandipsinh Rathod Date: Sat, 29 Jun 2024 12:18:47 +0530 Subject: [PATCH 2/6] add ci --- .github/pull_request_template.md | 13 +++ .github/workflows/ci.yml | 111 ++++++++++++++++++++++ .github/workflows/devskim.yml | 6 +- .github/workflows/linter.yml | 35 +++++++ .github/workflows/pr-title-convention.yml | 17 ++++ .prettierignore | 3 + .prettierrc | 7 ++ README.md | 16 ++-- lint.sh | 17 +++- 9 files changed, 214 insertions(+), 11 deletions(-) create mode 100644 .github/pull_request_template.md create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/linter.yml create mode 100644 .github/workflows/pr-title-convention.yml create mode 100644 .prettierignore create mode 100644 .prettierrc diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000..2ea538c --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,13 @@ +**Summary:** +_Briefly describe the changes made in this PR._ + +**Issue Reference(s):** +Fixes #... _(Replace "..." with the issue number)_ + +**Build & Testing:** + +- [ ] I ran `cargo test --all-features --workspace` successfully. + +**Checklist:** + +- [ ] PR follows the naming convention of `(): ` diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..eada472 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,111 @@ +name: Build + +on: + push: + branches: + - main + pull_request: + branches: [main] + types: [opened, reopened, synchronize] +permissions: + contents: read + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + +jobs: + test_cf: + name: Run Tests (WASM) + runs-on: ubuntu-latest + defaults: + run: + working-directory: ./lms-wasm + + steps: + - uses: actions/checkout@v4 + + - name: Install Rust + uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + target: wasm32-unknown-unknown + + - name: Build WASM + run: cargo check --lib --target wasm32-unknown-unknown + working-directory: ./lms-wasm + - name: Install Node.js + uses: actions/setup-node@v4 + with: + node-version: "20.11.0" + + - name: Package Install + run: npm install + + - name: Test CF + run: npm test + + test: + name: Run Tests on ${{ matrix.build }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + build: + [linux-x64-gnu, linux-x64-musl, linux-arm64-gnu, linux-arm64-musl, linux-ia32-gnu, darwin-arm64, darwin-x64] + include: + - build: linux-x64-gnu + os: ubuntu-latest + target: x86_64-unknown-linux-gnu + + - build: linux-x64-musl + os: ubuntu-latest + target: x86_64-unknown-linux-musl + + - build: linux-arm64-gnu + os: ubuntu-latest + target: aarch64-unknown-linux-gnu + + - build: linux-arm64-musl + os: ubuntu-latest + target: aarch64-unknown-linux-musl + + - build: linux-ia32-gnu + os: ubuntu-latest + target: i686-unknown-linux-gnu + + - build: darwin-arm64 + os: macos-latest + target: aarch64-apple-darwin + + - build: darwin-x64 + os: macos-latest + target: x86_64-apple-darwin + steps: + - uses: actions/checkout@v4 + - uses: taiki-e/install-action@cargo-llvm-cov + + - name: Install Node.js + uses: actions/setup-node@v4 + with: + node-version: "20.11.0" + - name: Install Prettier + run: npm i -g prettier + + - name: Install Stable Toolchain + uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + target: ${{ matrix.target }} + + - name: Run Cargo Test + run: cargo llvm-cov --all-features --workspace --exclude lms-wasm --exclude lms-autogen --lcov --output-path lcov.info + + - name: Upload Coverage to Codecov + if: matrix.build == 'linux-x64-gnu' + uses: Wandalen/wretry.action@v2 + with: + action: codecov/codecov-action@v4 + attempt_limit: 3 + attempt_delay: 10000 + with: | + token: ${{ secrets.CODECOV_TOKEN }} + files: lcov.info + fail_ci_if_error: true diff --git a/.github/workflows/devskim.yml b/.github/workflows/devskim.yml index 5f842ae..71f0160 100644 --- a/.github/workflows/devskim.yml +++ b/.github/workflows/devskim.yml @@ -7,11 +7,11 @@ name: DevSkim on: push: - branches: [ "main" ] + branches: ["main"] pull_request: - branches: [ "main" ] + branches: ["main"] schedule: - - cron: '27 4 * * 5' + - cron: "27 4 * * 5" jobs: lint: diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml new file mode 100644 index 0000000..68b8611 --- /dev/null +++ b/.github/workflows/linter.yml @@ -0,0 +1,35 @@ +name: linter.ci + +on: + push: + branches: + - main + pull_request: + branches: [main] + types: [opened, reopened, synchronize, labeled] +permissions: + contents: read + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + lint: + name: Run Formatter and Lint Check + runs-on: ubuntu-latest + permissions: + pull-requests: write + contents: write + steps: + - uses: actions/checkout@v4 + - name: Install Node.js + uses: actions/setup-node@v4 + with: + node-version: "20.11.0" + - name: Install Prettier + run: npm install --global prettier + - name: Install Stable Toolchain + uses: actions-rust-lang/setup-rust-toolchain@v1 + - name: Run Lint Script + run: ./lint.sh --mode=check diff --git a/.github/workflows/pr-title-convention.yml b/.github/workflows/pr-title-convention.yml new file mode 100644 index 0000000..87574ee --- /dev/null +++ b/.github/workflows/pr-title-convention.yml @@ -0,0 +1,17 @@ +name: PR Title Validation + +on: + pull_request_target: + types: [opened, reopened, synchronize, edited] + +permissions: + pull-requests: read + +jobs: + title-check: + name: Check PR Title + runs-on: ubuntu-latest + steps: + - uses: amannn/action-semantic-pull-request@v5 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..b0d494c --- /dev/null +++ b/.prettierignore @@ -0,0 +1,3 @@ +target/ +generated/ +*.schema.json \ No newline at end of file diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..b798edb --- /dev/null +++ b/.prettierrc @@ -0,0 +1,7 @@ +{ + "semi": false, + "singleQuote": false, + "printWidth": 120, + "tabWidth": 2, + "bracketSpacing": false +} diff --git a/README.md b/README.md index 8d0c412..0487cb5 100644 --- a/README.md +++ b/README.md @@ -3,24 +3,26 @@ ![Crates Downloads](https://img.shields.io/crates/d/encrypto_rsa) # About Project + End to End NO STD, WASM supported, platform independent RSA encryption and decryption library for High Level Usage -| Icon | Item | -|:----:|:-----------------------------:| -| 🥳 | [**Upcoming**](#Upcoming) | -| ⚖️ | [**License**](#License) | +| Icon | Item | +| :--: | :-----------------------: | +| 🥳 | [**Upcoming**](#Upcoming) | +| ⚖️ | [**License**](#License) | # Usage (rust) ## Implementation + ### Cargo + ```shell cargo add encrypto_rsa ``` ## RSA - ### Documentation will be published soon at our [website](https://www.ssdd.dev/zot/crypto/rsa/rust) ## You can try: @@ -42,12 +44,12 @@ fn main() { ## Upcoming | Supported Languages | Status | -|---------------------|--------| +| ------------------- | ------ | | Flutter | WIP | | Java | WIP | | JavaScript | WIP | -* Amazing encrypto with prevention against man in the middle attacks and AES-CBC with RSA key exchange for multiple language +- Amazing encrypto with prevention against man in the middle attacks and AES-CBC with RSA key exchange for multiple language ## License diff --git a/lint.sh b/lint.sh index d72f983..1413440 100755 --- a/lint.sh +++ b/lint.sh @@ -21,6 +21,19 @@ run_cargo_clippy() { return $? } + +FILE_TYPES="{yml,json,md,ts,js}" + +run_prettier() { + MODE=$1 + if [ "$MODE" == "check" ]; then + prettier -c .prettierrc --check "**/*.$FILE_TYPES" + else + prettier -c .prettierrc --write "**/*.$FILE_TYPES" + fi + return $? +} + # Extract the mode from the argument if [[ $1 == "--mode="* ]]; then MODE=${1#--mode=} @@ -36,6 +49,8 @@ case $MODE in FMT_EXIT_CODE=$? run_cargo_clippy $MODE CLIPPY_EXIT_CODE=$? + run_prettier $MODE + PRETTIER_EXIT_CODE=$? ;; *) @@ -45,6 +60,6 @@ case $MODE in esac # If any command failed, exit with a non-zero status code -if [ $FMT_EXIT_CODE -ne 0 ] || [ $CLIPPY_EXIT_CODE -ne 0 ]; then +if [ $FMT_EXIT_CODE -ne 0 ] || [ $CLIPPY_EXIT_CODE -ne 0 ] || [ $PRETTIER_EXIT_CODE -ne 0 ]; then exit 1 fi \ No newline at end of file From f40db427920b9c7be76ba69cf5fc8ba652aa5055 Mon Sep 17 00:00:00 2001 From: Sandipsinh Rathod <zotbysandip@gmail.com> Date: Sat, 29 Jun 2024 12:25:27 +0530 Subject: [PATCH 3/6] test: fix wasm tests --- .github/workflows/ci.yml | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index eada472..ec2ecd5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,9 +17,6 @@ jobs: test_cf: name: Run Tests (WASM) runs-on: ubuntu-latest - defaults: - run: - working-directory: ./lms-wasm steps: - uses: actions/checkout@v4 @@ -29,19 +26,10 @@ jobs: with: target: wasm32-unknown-unknown - - name: Build WASM - run: cargo check --lib --target wasm32-unknown-unknown - working-directory: ./lms-wasm - - name: Install Node.js - uses: actions/setup-node@v4 - with: - node-version: "20.11.0" - - - name: Package Install - run: npm install - - - name: Test CF - run: npm test + - name: Test WASM + run: | + cargo install wasm-bindgen-cli --vers "0.2.92" + wasm-pack test --node test: name: Run Tests on ${{ matrix.build }} From 2c1ad573487b29d14b1736d375e83d6f770b858c Mon Sep 17 00:00:00 2001 From: Sandipsinh Rathod <zotbysandip@gmail.com> Date: Sat, 29 Jun 2024 12:29:52 +0530 Subject: [PATCH 4/6] remove unwanted npm installation --- .github/workflows/ci.yml | 7 ------- .idea/encrypto_rust.iml | 1 + 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ec2ecd5..186cbcb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -71,13 +71,6 @@ jobs: - uses: actions/checkout@v4 - uses: taiki-e/install-action@cargo-llvm-cov - - name: Install Node.js - uses: actions/setup-node@v4 - with: - node-version: "20.11.0" - - name: Install Prettier - run: npm i -g prettier - - name: Install Stable Toolchain uses: actions-rust-lang/setup-rust-toolchain@v1 with: diff --git a/.idea/encrypto_rust.iml b/.idea/encrypto_rust.iml index c254557..457e3e6 100755 --- a/.idea/encrypto_rust.iml +++ b/.idea/encrypto_rust.iml @@ -3,6 +3,7 @@ <component name="NewModuleRootManager"> <content url="file://$MODULE_DIR$"> <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> + <sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" /> <excludeFolder url="file://$MODULE_DIR$/target" /> </content> <orderEntry type="inheritedJdk" /> From 07dfd98a9194c223ffc836b116000d7e45c35a7d Mon Sep 17 00:00:00 2001 From: Sandipsinh Rathod <zotbysandip@gmail.com> Date: Sat, 29 Jun 2024 12:32:00 +0530 Subject: [PATCH 5/6] fix: install wasmpack not found --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 186cbcb..7ad2ece 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,7 +28,7 @@ jobs: - name: Test WASM run: | - cargo install wasm-bindgen-cli --vers "0.2.92" + cargo install wasm-pack wasm-pack test --node test: From c4ad736cedf33b0f876ca289089f109ad6a94329 Mon Sep 17 00:00:00 2001 From: Sandipsinh Rathod <zotbysandip@gmail.com> Date: Sat, 29 Jun 2024 12:38:31 +0530 Subject: [PATCH 6/6] add codecov badge --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 0487cb5..f82d27f 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,4 @@ +[![codecov](https://codecov.io/github/zotcrypto/encrypto-rsa-rust/graph/badge.svg?token=WTW4S5NPQO)](https://codecov.io/github/zotcrypto/encrypto-rsa-rust) ![Visitor Badge](https://visitor-badge.laobi.icu/badge?page_id=encrypto-rsa) ![Crates Badge](https://img.shields.io/crates/v/encrypto_rsa) ![Crates Downloads](https://img.shields.io/crates/d/encrypto_rsa)