diff --git a/Cargo.lock b/Cargo.lock index 43d111d..533382c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,3 +1,26 @@ +[[package]] +name = "ansi_term" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "atty" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", + "termion 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "autocfg" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "bitflags" version = "1.0.4" @@ -5,12 +28,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "clap" -version = "2.32.0" +version = "2.33.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ + "ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", + "atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", - "textwrap 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", + "strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -27,72 +54,231 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] -name = "fuchsia-zircon" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", - "fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "fuchsia-zircon-sys" -version = "0.3.3" +name = "fuchsia-cprng" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "lazy_static" -version = "1.1.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "version_check 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", -] [[package]] name = "libc" -version = "0.2.43" +version = "0.2.55" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "numtoa" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "pwgenr" -version = "0.3.0" +version = "0.4.0" dependencies = [ - "clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)", + "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", "find_folder 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", - "unichars 0.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", + "unic-ucd-block 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "unic-ucd-name 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rand" -version = "0.5.5" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", - "fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_core 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_hc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_isaac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_jitter 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_os 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_pcg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rand_chacha" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rand_core" -version = "0.2.1" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rand_core" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "rand_hc" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rand_isaac" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rand_jitter" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rand_os" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rand_pcg" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rand_xorshift" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rdrand" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "redox_syscall" +version = "0.1.54" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "redox_termios" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "strsim" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "termion" +version = "1.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", + "numtoa 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "textwrap" -version = "0.10.0" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] -name = "unichars" -version = "0.0.2" +name = "unic-char-property" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "unic-char-range 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "unic-char-range" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "unic-common" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "unic-ucd-block" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "unic-char-property 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "unic-char-range 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "unic-ucd-version 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "unic-ucd-hangul" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "unic-ucd-version 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "unic-ucd-name" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "unic-char-property 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "unic-ucd-hangul 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "unic-ucd-version 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "unic-ucd-version" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "unic-common 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", +] [[package]] name = "unicode-width" @@ -100,13 +286,13 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] -name = "version_check" -version = "0.1.4" +name = "vec_map" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "winapi" -version = "0.3.5" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -124,20 +310,42 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" [metadata] +"checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" +"checksum atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9a7d5b8723950951411ee34d271d99dddcc2035a16ab25310ea2c8cfd4369652" +"checksum autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "0e49efa51329a5fd37e7c79db4621af617cd4e3e5bc224939808d076077077bf" "checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12" -"checksum clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b957d88f4b6a63b9d70d5f454ac8011819c6efa7727858f458ab71c756ce2d3e" +"checksum clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9" "checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" "checksum find_folder 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9f6d018fb95a0b59f854aed68ecd96ce2b80af7911b92b1fed3c4b1fa516b91b" -"checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" -"checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" -"checksum lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ca488b89a5657b0a2ecd45b95609b3e848cf1755da332a0da46e2b2b1cb371a7" -"checksum libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)" = "76e3a3ef172f1a0b9a9ff0dd1491ae5e6c948b94479a3021819ba7d860c8645d" -"checksum rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e464cd887e869cddcae8792a4ee31d23c7edd516700695608f5b98c67ee0131c" -"checksum rand_core 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "edecf0f94da5551fc9b492093e30b041a891657db7940ee221f9d2f66e82eef2" -"checksum textwrap 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "307686869c93e71f94da64286f9a9524c0f308a9e1c87a583de8e9c9039ad3f6" -"checksum unichars 0.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7b0eccb6815251914e96be582034145d89326e73d394d91330b693c3f1edfbd2" +"checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" +"checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14" +"checksum libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)" = "42914d39aad277d9e176efbdad68acb1d5443ab65afe0e0e4f0d49352a950880" +"checksum numtoa 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef" +"checksum rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca" +"checksum rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef" +"checksum rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" +"checksum rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d0e7a549d590831370895ab7ba4ea0c1b6b011d106b5ff2da6eee112615e6dc0" +"checksum rand_hc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4" +"checksum rand_isaac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08" +"checksum rand_jitter 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "1166d5c91dc97b88d1decc3285bb0a99ed84b05cfd0bc2341bdf2d43fc41e39b" +"checksum rand_os 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071" +"checksum rand_pcg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44" +"checksum rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c" +"checksum rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" +"checksum redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)" = "12229c14a0f65c4f1cb046a3b52047cdd9da1f4b30f8a39c5063c8bae515e252" +"checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" +"checksum strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" +"checksum termion 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dde0593aeb8d47accea5392b39350015b5eccb12c0d98044d856983d89548dea" +"checksum textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" +"checksum unic-char-property 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a8c57a407d9b6fa02b4795eb81c5b6652060a15a7903ea981f3d723e6c0be221" +"checksum unic-char-range 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0398022d5f700414f6b899e10b8348231abf9173fa93144cbc1a43b9793c1fbc" +"checksum unic-common 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "80d7ff825a6a654ee85a63e80f92f054f904f21e7d12da4e22f9834a4aaa35bc" +"checksum unic-ucd-block 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6b2a16f2d7ecd25325a1053ca5a66e7fa1b68911a65c5e97f8d2e1b236b6f1d7" +"checksum unic-ucd-hangul 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "eb1dc690e19010e1523edb9713224cba5ef55b54894fe33424439ec9a40c0054" +"checksum unic-ucd-name 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9c8fc55a45b2531089dc1773bf60c1f104b38e434b774ffc37b9c29a9b0f492e" +"checksum unic-ucd-version 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "96bd2f2237fe450fcd0a1d2f5f4e91711124f7857ba2e964247776ebeeb7b0c4" "checksum unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "882386231c45df4700b275c7ff55b6f3698780a650026380e72dabe76fa46526" -"checksum version_check 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "7716c242968ee87e5542f8021178248f267f295a5c4803beae8b8b7fd9bc6051" -"checksum winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "773ef9dcc5f24b7d850d0ff101e542ff24c3b090a9768e03ff889fdef41f00fd" +"checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" +"checksum winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "f10e386af2b13e47c89e7236a7a14a086791a2b88ebad6df9bf42040195cf770" "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/Cargo.toml b/Cargo.toml index 3716dda..ee7c095 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,13 +11,15 @@ license = "GPL-3.0" name = "pwgenr" readme = "README.md" repository = "https://gitlab.com/Sakuhl/pwgenr/" -version = "0.3.0" +version = "0.4.0" +edition = "2018" [dependencies] -clap = { version = "2.32", default-features = false } -lazy_static = "1.1" -rand = "0.5.5" -unichars = "^0.0" +clap = "2.33.0" +lazy_static = "1.3.0" +rand = "0.6.5" +unic-ucd-block = "0.9.0" +unic-ucd-name = "0.9.0" [dev-dependencies] find_folder = "0.3" diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..218e203 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1 @@ +hard_tabs = true diff --git a/src/cli.rs b/src/cli.rs index c3c398a..fd35e61 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -1,25 +1,83 @@ -use clap::{ App, Arg }; - -extern crate unichars; -use unichars::*; +use clap::{App, Arg}; +use unic_ucd_block::BlockIter; +use unic_ucd_name::Name; use std::collections::HashMap; lazy_static! { - pub static ref CATEGORIES: HashMap<&'static str, &'static [char]> = { - let mut map = HashMap::new(); - map.insert("ascii", ASCII); - map.insert("arrows", ARROWS); - map.insert("box", BOX); - map.insert("dingbat", DINGBAT); - map.insert("games", GAMES); - map.insert("math", MATH); - map.insert("symbols", SYMBOLS); - map.insert("tech", TECH); + pub static ref CATEGORIES: HashMap<&'static str, Vec> = { + let mut map: HashMap<&'static str, _> = HashMap::new(); + map.insert( + "ascii", + vec![ + '!', '"', '#', '$', '%', '&', '\'', '(', ')', '*', '+', ',', '-', '.', '/', '0', + '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@', + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', + 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\\', ']', '^', '_', '`', + 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', + 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', + ], + ); + map.insert( + "arrows", + get_blocks(&[ + "Arrows", + "Supplemental Arrows-A", + "Supplemental Arrows-B", + "Supplemental Arrows-C", + ]), + ); + map.insert( + "box", + get_blocks(&[ + "Box Drawing", + "Block Elements", + "Geometric Shapes", + "Geometric Shapes Extended", + ]), + ); + map.insert("dingbat", get_blocks(&["Dingbats"])); + map.insert( + "games", + get_blocks(&["Mahjong Tiles", "Domino Tiles", "Playing Cards"]), + ); + map.insert( + "math", + get_blocks(&[ + "Mathematical Operators", + "Supplemental Mathematical Operators", + "Miscellaneous Mathematical Symbols-A", + "Miscellaneous Mathematical Symbols-B", + ]), + ); + map.insert( + "symbols", + get_blocks(&[ + "Currency Symbols", + "General Punctuation", + "Letterlike Symbols", + "Number Forms", + "Miscellaneous Symbols", + ]), + ); + map.insert("tech", get_blocks(&["Miscellaneous Technical"])); map }; } +fn get_blocks(names: &[&'static str]) -> Vec { + let mut all = Vec::new(); + for &n in names { + debug_assert!(BlockIter::new().any(|b| b.name == n)); + } + for block in BlockIter::new().filter(|b| names.contains(&b.name)) { + for c in block.range.into_iter().filter(|&c| Name::of(c).is_some()) { + all.push(c); + } + } + all +} + fn is_int(s: String) -> Result<(), String> { s.parse::().map(|_| ()).map_err(|e| e.to_string()) } @@ -28,24 +86,32 @@ pub fn build_cli() -> App<'static, 'static> { App::new("pwgenr") .version(env!("CARGO_PKG_VERSION")) .author("Arne Keller ") - .arg(Arg::with_name("categories") - .short("c") - .takes_value(true) - .multiple(true) - .possible_values(&CATEGORIES.keys().cloned().collect::>()) - .help("Categories to be used")) - .arg(Arg::with_name("clipboard") - .short("b") - .long("clipboard") - .help("Copy first password to clipboard (requires xclip)")) - .arg(Arg::with_name("LENGTH") - .takes_value(true) - .validator(is_int) - .default_value("64") - .help("of the generated passwords")) - .arg(Arg::with_name("AMOUNT") - .takes_value(true) - .validator(is_int) - .default_value("12") - .help("of generated passwords")) -} \ No newline at end of file + .arg( + Arg::with_name("categories") + .short("c") + .takes_value(true) + .multiple(true) + .possible_values(&CATEGORIES.keys().cloned().collect::>()) + .help("Categories to be used"), + ) + .arg( + Arg::with_name("clipboard") + .short("b") + .long("clipboard") + .help("Copy first password to clipboard (requires xclip)"), + ) + .arg( + Arg::with_name("LENGTH") + .takes_value(true) + .validator(is_int) + .default_value("64") + .help("of the generated passwords"), + ) + .arg( + Arg::with_name("AMOUNT") + .takes_value(true) + .validator(is_int) + .default_value("12") + .help("of generated passwords"), + ) +} diff --git a/src/main.rs b/src/main.rs index 32dae1e..4178eec 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,20 +1,17 @@ -#[macro_use] extern crate lazy_static; -extern crate clap; +#[macro_use] +extern crate lazy_static; +use rand::rngs::OsRng; +use rand::seq::SliceRandom; -extern crate unichars; -use unichars::*; - -extern crate rand; -use rand::{ OsRng, Rng }; - -use std::process::{Command, exit, Stdio}; +use std::process::{exit, Command, Stdio}; mod cli; +use cli::CATEGORIES; fn gen_pw(alphabet: &[char], length: usize, rng: &mut OsRng) -> String { let mut buf = String::new(); for _ in 0..length { - let c = rng.choose(alphabet).unwrap(); + let c = alphabet.choose(rng).unwrap(); buf.push(*c); } buf @@ -23,8 +20,16 @@ fn gen_pw(alphabet: &[char], length: usize, rng: &mut OsRng) -> String { fn main() { let matches = cli::build_cli().get_matches(); - let length = matches.value_of("LENGTH").unwrap().parse::().unwrap(); - let amount = matches.value_of("AMOUNT").unwrap().parse::().unwrap(); + let length = matches + .value_of("LENGTH") + .unwrap() + .parse::() + .unwrap(); + let amount = matches + .value_of("AMOUNT") + .unwrap() + .parse::() + .unwrap(); let alphabet = if let Some(categories) = matches.values_of("categories") { let mut all = Vec::new(); @@ -34,19 +39,16 @@ fn main() { all } else { let mut all = Vec::new(); - all.extend(ARROWS); - all.extend(ASCII); - all.extend(BOX); - all.extend(DINGBAT); - all.extend(ENCLOSED); - all.extend(GAMES); - all.extend(MATH); - all.extend(SYMBOLS); - all.extend(TECH); + for c in CATEGORIES.values() { + all.extend(c); + } all }; - let mut rng = OsRng::new().unwrap_or_else(|_| { eprintln!("error: could not create CSPRNG"); exit(71) }); + let mut rng = OsRng::new().unwrap_or_else(|_| { + eprintln!("error: could not create CSPRNG"); + exit(71) + }); for i in 0..amount { let pw = gen_pw(&alphabet, length, &mut rng); @@ -59,25 +61,34 @@ fn main() { } } - fn to_clip(value: &str) { use std::io::*; Command::new("xclip") .arg("-selection") .arg("clipboard") .stdin(Stdio::piped()) - .spawn().map_err(|e| { - eprintln!("error: could not run xclip ({:?})", e); exit(1) - }).map(|child| { - child.stdin.or_else(|| { - eprintln!("error: could not open stdin of xclip"); exit(1) - }).map(|mut outstdin| { - let mut writer = BufWriter::new(&mut outstdin); - writer.write_all(value.as_bytes()).unwrap_or_else(|e| { - eprintln!("error: could not write to stdin of xclip ({:?})", e); exit(1) - }); + .spawn() + .map_err(|e| { + eprintln!("error: could not run xclip ({:?})", e); + exit(1) }) - }).unwrap_or_else(|e| { - eprintln!("error: {:?}", e); exit(1) - }); + .map(|child| { + child + .stdin + .or_else(|| { + eprintln!("error: could not open stdin of xclip"); + exit(1) + }) + .map(|mut outstdin| { + let mut writer = BufWriter::new(&mut outstdin); + writer.write_all(value.as_bytes()).unwrap_or_else(|e| { + eprintln!("error: could not write to stdin of xclip ({:?})", e); + exit(1) + }); + }) + }) + .unwrap_or_else(|e| { + eprintln!("error: {:?}", e); + exit(1) + }); } diff --git a/tests/all.rs b/tests/all.rs deleted file mode 100644 index bc2c64e..0000000 --- a/tests/all.rs +++ /dev/null @@ -1,71 +0,0 @@ -#[macro_use] extern crate lazy_static; -extern crate find_folder; -use find_folder::Search; - -extern crate unichars; -use unichars::*; - -lazy_static! { - static ref PATH: ::std::path::PathBuf = { Search::ParentsThenKids(3, 3).for_folder("target").unwrap().join(::std::path::Path::new("debug/pwgenr")) }; -} - -macro_rules! exe { - ($($arg:expr),*) => { - match ::std::process::Command::new(&*PATH) - // Start a repetition: - $( - // Each repeat will contain the following statement, with - // $arg replaced with the corresponding expression. - .arg($arg) - )* - .output() - .expect("failed to execute process") { - ::std::process::Output { status: _, stdout: out, stderr: err } => { - let out = String::from_utf8(out).unwrap(); - let err = String::from_utf8(err).unwrap(); - println!("out\n{}\nerr\n{}", out, err); - // skip last empty line - (out.rsplit('\n').skip(1).map(|x| x.to_string()).collect::>(), err) - } - } - } -} - -#[test] -fn length_amount() { - let (out, _) = exe!("19", "15"); - assert_eq!(out.len(), 15); - for line in &out { - assert_eq!(line.chars().count(), 19); - } -} - -#[test] -fn ascii() { - let (out, _) = exe!("-c", "ascii", "--", "1", "10"); - assert_eq!(out.len(), 10); - for line in &out { - assert_eq!(line.chars().count(), 1); - for c in line.chars() { - assert!(ASCII.contains(&c)); - } - } -} - -#[test] -fn categories() { - let (out, _) = exe!("-c", "box", "arrows", "--", "16", "20"); - assert_eq!(out.len(), 20); - for line in &out { - assert_eq!(line.chars().count(), 16); - for c in line.chars() { - assert!(BOX.contains(&c) || ARROWS.contains(&c)); - } - } -} - -#[test] -fn empty() { - let (out, _) = exe!("0", "0"); - assert_eq!(out.len(), 0); -}