diff options
author | Richard van der Hoff <1389908+richvdh@users.noreply.github.com> | 2021-05-12 15:04:51 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-12 15:04:51 +0100 |
commit | 7562d887e159f404c8d752271310f4432f246656 (patch) | |
tree | 0b59ec04cf218ef5dd3172642bdfc531bb3f187e /synapse/util | |
parent | Run cache_joined_hosts_for_event in background (#9951) (diff) | |
download | synapse-7562d887e159f404c8d752271310f4432f246656.tar.xz |
Change the format of access tokens away from macaroons (#5588)
Diffstat (limited to 'synapse/util')
-rw-r--r-- | synapse/util/stringutils.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/synapse/util/stringutils.py b/synapse/util/stringutils.py index cd82777f80..4f25cd1d26 100644 --- a/synapse/util/stringutils.py +++ b/synapse/util/stringutils.py @@ -220,3 +220,23 @@ def strtobool(val: str) -> bool: return False else: raise ValueError("invalid truth value %r" % (val,)) + + +_BASE62 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" + + +def base62_encode(num: int, minwidth: int = 1) -> str: + """Encode a number using base62 + + Args: + num: number to be encoded + minwidth: width to pad to, if the number is small + """ + res = "" + while num: + num, rem = divmod(num, 62) + res = _BASE62[rem] + res + + # pad to minimum width + pad = "0" * (minwidth - len(res)) + return pad + res |