Mercurial > hgrepos > Python > apps > py-cutils
changeset 246:c29266444003
genpwd: Implement "uri"
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Sat, 08 Feb 2025 11:43:33 +0100 |
| parents | 35c06dcca856 |
| children | 435687f4e071 |
| files | cutils/genpwd.py |
| diffstat | 1 files changed, 22 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/cutils/genpwd.py Sat Feb 08 10:53:56 2025 +0100 +++ b/cutils/genpwd.py Sat Feb 08 11:43:33 2025 +0100 @@ -33,10 +33,19 @@ # WEB_CHARS = (b"ABCDEFGHIJKLMNOPQRSTUVWYXZabcdefghijklmnopqrstuvwxyz" b"0123456789-._") +# WEB_CHARS without visually similar characters (0O, 1lI) SAFE_WEB_CHARS = (b"ABCDEFGHJKLMNPQRSTUVWYXZabcdefghijkmnopqrstuvwxyz" b"23456789-._") -SAFE_WEB_CHARS_2 = b".-_" + SAFE_WEB_CHARS # prefer punctionation chars -# Most visible characters but no space +# SAFE_WEB_CHARS with preference to punctuation +SAFE_WEB_CHARS_2 = b".-_" + SAFE_WEB_CHARS +# Unreserved characters from URI but with sub-delims allowed +URI_CHARS = WEB_CHARS + b"~" + b"!$&'()*+,;=" +# URI_CHARS without visually similar characters +SAFE_URI_CHARS = SAFE_WEB_CHARS + b"~" + b"!$&'()*+,;=" +# Just like SAFE_URI_CHARS but prefers punctuation characters +SAFE_URI_CHARS_2 = (b"~" + b"!$&'()*+,;=" + SAFE_WEB_CHARS + + b"~" + b"!$&'()*+,;=") +# All visible characters from ASCII character set but no space FULL_ASCII = (b"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" b"abcdefghijklmnopqrstuvwxyz!#$%&/()*+-.,:;<=>?@^_`[\\]{|}'\"~") # @@ -70,10 +79,12 @@ " that is to be read from random sources instead of output bytes") aparser.add_argument( "--repertoire", "--type", "-t", - choices=("web", "safe-web", "safe-web-2", "ascii", "safe-ascii", + choices=("web", "safe-web", "safe-web-2", + "uri", "safe-uri", "safe-uri-2", + "ascii", "safe-ascii", "alnum", "safe-alnum", - "bin-base64", "bin-urlsafe-base64", "bin-base32", - "bin-ascii85", "bin-hex", ), + "bin-base64", "bin-urlsafe-base64", "bin-base32", "bin-hex", + "bin-ascii85",), default="safe-ascii", help=""" Select from a character repertoire. @@ -93,6 +104,12 @@ pwd = gen_from_repertoire(opts.req_length, SAFE_WEB_CHARS) elif opts.repertoire == "safe-web-2": pwd = gen_from_repertoire(opts.req_length, SAFE_WEB_CHARS_2) + elif opts.repertoire == "uri": + pwd = gen_from_repertoire(opts.req_length, URI_CHARS) + elif opts.repertoire == "safe-uri": + pwd = gen_from_repertoire(opts.req_length, SAFE_URI_CHARS) + elif opts.repertoire == "safe-uri-2": + pwd = gen_from_repertoire(opts.req_length, SAFE_URI_CHARS_2) elif opts.repertoire == "ascii": pwd = gen_from_repertoire(opts.req_length, FULL_ASCII) elif opts.repertoire == "safe-ascii":
