gel-auth 0.1.7

Authentication and authorization for the Gel database.
Documentation
# Generates lists of stringprep tables that we can embed in Rust. The tables are
# generated as ranges which may be directly consulted or turned into roaring
# bitmaps as performance concerns dictate.

# Note that the saslprep is only ever used when passwords contain unicode
# characters and we skip all this overhead when passwords are pure ASCII.
import inspect
import stringprep

SASLPREP_PROHIBITED = (
    stringprep.in_table_a1,  # PostgreSQL treats this as prohibited
    stringprep.in_table_c12,
    stringprep.in_table_c21_c22,
    stringprep.in_table_c3,
    stringprep.in_table_c4,
    stringprep.in_table_c5,
    stringprep.in_table_c6,
    stringprep.in_table_c7,
    stringprep.in_table_c8,
    stringprep.in_table_c9,
)


def gen(name, f):
    r = None
    print()
    print(f"// {inspect.getsource(f).strip().replace('\n', '\n// ')}")
    print(f"super::stringprep::process_ranges!({name} =>")
    for c in range(0, 0x110000):
        c = chr(c)
        prohibited = f(c)
        if prohibited and r is None:
            r = ord(c)
        if not prohibited and r is not None:
            print(f"(0x{r:x}, 0x{ord(c):x})")
            r = None
    if r:
        print(f"0x{r:x}")
    print(");")


print("// Autogenerated by stringprep_table_prep.py: DO NOT EDIT")
gen("not_prohibited", lambda c: not any(
            in_prohibited_table(c)
            for in_prohibited_table in SASLPREP_PROHIBITED
        ))

gen("maps_to_space", lambda c: stringprep.in_table_c12(c))

gen("maps_to_nothing", lambda c: stringprep.in_table_b1(c))

gen("table_d1", lambda c: stringprep.in_table_d1(c))
gen("table_d2", lambda c: stringprep.in_table_d2(c))