Skip to content

Converts the yubikey-manager scancodes to valid regular expressions.

License

Notifications You must be signed in to change notification settings

piotrpdev/yubikey-scancode-regexp-gen

Repository files navigation

YubiKey Scancode RegExp Generator

Converts the yubikey-manager scancodes to valid[1] regular expressions.

Usage

The following script will generate regular expressions for all of the available scancodes in ./yubikey-manager/ykman/scancodes/ and write them to scancodes_regexp_file.txt.

git clone --recurse-submodules https://github.com/piotrpdev/yubikey-scancode-regexp-gen.git && \
cd yubikey-scancode-regexp-gen && \
python3 generator.py

Example console output

Warning

Don't use the output below, the generated file wil include important Unicode characters. The output is also generated based on the current version of the yubikey-manager scancodes, which can change.

$ python3 generator.py 
'bepo'     RegExp (Valid):     /[\ !"\#\$%'\(\)\*\+,\-\.\/0123456789:;=\?@ABCDEFGHIJKLMNOPQRSTUVWXYZ`abcdefghijklmnopqrstuvwxyz«°»ÀÇÈÉÊàçèéê]{1,38}$/
'de'       RegExp (Valid):     /[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!"\#\$%\&'\(\)\*\+,\-\.\/:;<=>\?\^_\ `§´ÄÖÜßäöü]{1,38}$/
'fr'       RegExp (Valid):     /[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\ !"\$%\&'\(\)\*\+,\-\.\/:;<=_£§°²µàçèéù]{1,38}$/
'it'       RegExp (Valid):     /[\ !"\#\$%\&'\(\)\*\+,\-\.\/0123456789:;<=>\?@ABCDEFGHIJKLMNOPQRSTUVWXYZ\\\^_`abcdefghijklmnopqrstuvwxyz\|£§°çèéàìòù]{1,38}$/
'modhex'   RegExp (Valid):     /[bcdefghijklnrtuvBCDEFGHIJKLNRTUV]{1,38}$/
'norman'   RegExp (Valid):     /[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!"\#\$%\&'`\(\)\*\+,\-\.\/:;<=>\?@\[\\\]\^_\{\}\|\~\ ]{1,38}$/
'uk'       RegExp (Valid):     /[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!\$%\&'`\(\)\*\+,\-\.\/:;<=>\?"\[\#\]\^_\{\}\~¬\ ]{1,38}$/
'us'       RegExp (Valid):     /[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!"\#\$%\&'`\(\)\*\+,\-\.\/:;<=>\?@\[\\\]\^_\{\}\|\~\ ]{1,38}$/

Notes

In the future, using Matthew Barnett’s excellent regex module instead of the built-in re module might be a better choice. The regex module is a drop-in replacement, provides full support for Perl-style regular expressions (PCRE), and has much better Unicode support[2].

Considering a YubiKey is usually configured using yubikey-manager (which is written in Python) using the built-in re module be fine.

As of me writing this (November 11, 2023), both modules generated the same output.

Footnotes

[1]: Valid by Python's standards, see relevant comments in generator.py.

[2]: https://stackoverflow.com/questions/7063420/perl-compatible-regular-expression-pcre-in-python

About

Converts the yubikey-manager scancodes to valid regular expressions.

Resources

License

Stars

Watchers

Forks

Languages