changeset 244:42f7ecd70ec1

genpwd: Renamed algorithms and changed restricted the WEB character repertoire to not use delims and sub-delims from URLs and URIs
author Franz Glasner <fzglas.hg@dom66.de>
date Sat, 08 Feb 2025 10:52:02 +0100
parents 86417af99561
children 35c06dcca856
files cutils/genpwd.py
diffstat 1 files changed, 14 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/cutils/genpwd.py	Sat Feb 08 10:39:49 2025 +0100
+++ b/cutils/genpwd.py	Sat Feb 08 10:52:02 2025 +0100
@@ -27,11 +27,15 @@
 from . import (__version__, __revision__)
 
 
+#
+# Unreserved characters according to RFC 1738 (URL) **and** RFC 3986 (URI)
+# No general delimiters and no sub-delimiters.
+#
 WEB_CHARS = (b"ABCDEFGHIJKLMNOPQRSTUVWYXZabcdefghijklmnopqrstuvwxyz"
-             b"0123456789.,-_;!()[]{}*")
-WEB_SAFE_CHARS = (b"ABCDEFGHJKLMNPQRSTUVWYXZabcdefghijkmnopqrstuvwxyz"
-                  b"23456789.,-_;!")
-WEB_SAFE2_CHARS = b".,-_;!" + WEB_SAFE_CHARS   # prefer punctionation chars
+             b"0123456789-._")
+SAFE_WEB_CHARS = (b"ABCDEFGHJKLMNPQRSTUVWYXZabcdefghijkmnopqrstuvwxyz"
+                  b"23456789-._")
+SAFE_WEB_CHARS_2 = b".-_" + SAFE_WEB_CHARS   # prefer punctionation chars
 # Most visible characters but no space
 FULL_ASCII = (b"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
               b"abcdefghijklmnopqrstuvwxyz!#$%&/()*+-.,:;<=>?@^_`[\\]{|}'\"~")
@@ -66,11 +70,11 @@
              " that is to be read from random sources instead of output bytes")
     aparser.add_argument(
         "--repertoire", "--type", "-t",
-        choices=("web", "web-safe", "web-safe2", "ascii", "safe-ascii",
+        choices=("web", "safe-web", "safe-web-2", "ascii", "safe-ascii",
                  "alnum", "safe-alnum",
                  "bin-base64", "bin-urlsafe-base64", "bin-base32",
                  "bin-ascii85", "bin-hex", ),
-        default="web-safe2",
+        default="safe-web-2",
         help="""
 Select from a character repertoire.
 All repertoires that start with "bin-" just encode the output of
@@ -85,10 +89,10 @@
 
     if opts.repertoire == "web":
         pwd = gen_from_repertoire(opts.req_length, WEB_CHARS)
-    elif opts.repertoire == "web-safe":
-        pwd = gen_from_repertoire(opts.req_length, WEB_SAFE_CHARS)
-    elif opts.repertoire == "web-safe2":
-        pwd = gen_from_repertoire(opts.req_length, WEB_SAFE2_CHARS)
+    elif opts.repertoire == "safe-web":
+        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 == "ascii":
         pwd = gen_from_repertoire(opts.req_length, FULL_ASCII)
     elif opts.repertoire == "safe-ascii":