[Top] [All Lists]

Re: [openpgp] User ID conventions (it's not really a RFC2822 name-addr)

2019-09-16 20:44:18
As usual, when you try to implement something, you find the missing
pieces. :P

On Mon 2019-09-16 18:35:07 -0400, Daniel Kahn Gillmor wrote:
    pgp-uid-prefix-char    = atext / specials

The above line appears in both proposals, but it contains a mistake.  It
should read instead:

     pgp-uid-prefix-char    = atext / specials / SPACE

The following python3 code implements proposal 2 using python's built-in
re module (i have not tested it with python2, given python2's clunky
unicode support).

    import re

    specials = r'[()<>\[\]:;@\\,."]'
    atext = "[-A-Za-z0-9!#$%&'*+/=?^_`{|}~\x80-\U0010ffff]"
    dot_atom_text = atext + r"+(?:\." + atext + "+)*"
    pgp_addr_spec = dot_atom_text + "@" + dot_atom_text
    pgp_uid_prefix_char = "(?:" + atext + "|" + specials + "| )"
    addr_spec_raw = "(?P<addr_spec_raw>" + pgp_addr_spec + ")"
    addr_spec_wrapped = pgp_uid_prefix_char + "*<(?P<addr_spec_wrapped>" + 
pgp_addr_spec + ")>"
    pgp_uid_convention = "^(?:" + addr_spec_raw + "|" + addr_spec_wrapped + ")$"

    pgp_uid_convention_re = re.compile(pgp_uid_convention, re.UNICODE)

    m =

If there's a resultant match object, then the pgp-addr-spec can be found
in either m["addr_spec_raw"] or m["addr_spec_wrapped"], depending on
whether there are angle-brackets involved or not.

Note the atext definition is the extended form of atext.

anyway, i hope this clarification is useful.


PS if the above is useful, anyone should feel free to reuse any of the
   above code in any context under any license.  If you do so, and you
   want to provide an attribution so that complaints can be directed
   properly, that's fine, but i have no need for credit if you don't
   want to bother.

Attachment: signature.asc
Description: PGP signature

openpgp mailing list