Regular expression for SSH public key

https://gitlab.com/sdalu/ssh-publickey/

1
2
3
4
5
6
7
    AUTHORIZED_KEY_REGEX =
        /(?:    (?<directives>(?:[!-~]|\s(?=.*"))+) \s+ )?   # Options
                (?<type>      [a-z0-9_-]+)          \s+      # Type
                (?<key>       [A-Za-z0-9+\/]+=*)             # Key
         (?:\s+ (?<comment>.*?)                     \s* )?   # Comments
         /x

1
2
3
4
5
    PUBKEY_OPENSSH_REGEX =
        /       (?<type>   [a-z0-9_-]+)             \s+      # Type
                (?<key>    [A-Za-z0-9+\/]+=*)                # Key
         (?:\s+ (?<comment>.*?)                     \s* )?   # Comments
         /x
1
2
3
4
5
6
7
8
9
    PUBKEY_RFC4716_REGEX =
        /----\sBEGIN\sSSH2\sPUBLIC\sKEY\s----\R
         (?<tags> (?:[^:\p{Space}\p{Cntrl}]{1,64}            # Tags
                     \s*:\s*
                     (?:[^\\\r\n]*\\\R)* [^\\\r\n]+\R)*)
         (?<key>  (?:[A-Za-z0-9+\/]+\R)*                     # Key
                  [A-Za-z0-9+\/]+=*\R)
         ----\sEND\sSSH2\sPUBLIC\sKEY\s----
         /xmu