# HG changeset patch # User Franz Glasner # Date 1739011413 -3600 # Node ID c2926644400358b297e0d1eab03f0c36c0de53e6 # Parent 35c06dcca8562272637af64e3680a11e94c0c160 genpwd: Implement "uri" diff -r 35c06dcca856 -r c29266444003 cutils/genpwd.py --- 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":