
; signed is the production that should match the OpenPGP clearsigned
; document
signed = cleartext-header
    1*(hash-header)
    CRLF
    cleartext
    signature

cleartext-header = %s"-----BEGIN PGP SIGNED MESSAGE-----" CRLF
    ; "-----BEGIN PGP SIGNED MESSAGE-----"

hash-header = %x48.61.73.68 ": " hash-alg *("," hash-alg) CRLF

hash-alg = token
    ; imported from RFC 2045; see RFC 4880 Section 10.3.3 for a pointer to the registry of valid values

;cleartext = 1*( UTF8-octets CRLF)
    ; dash-escaped per RFC 4880 Section 7.1

cleartext = *(*4%x2d [UTF8-char-not-dash *UTF8-char-not-cr] CRLF)
UTF8-char-not-dash = UTF8-1-not-dash / UTF8-2 / UTF8-3 / UTF8-4
UTF8-1-not-dash = %x00-2C / %x2E-7F
UTF8-char-not-cr = UTF8-1-not-cr / UTF8-2 / UTF8-3 / UTF8-4
UTF8-1-not-cr = %x00-0C / %x0E-7F

; UTF8 rules from RFC 3629
UTF8-octets = *( UTF8-char )
UTF8-char   = UTF8-1 / UTF8-2 / UTF8-3 / UTF8-4
UTF8-1      = %x00-7F
UTF8-2      = %xC2-DF UTF8-tail
UTF8-3      = %xE0 %xA0-BF UTF8-tail / %xE1-EC 2( UTF8-tail ) /
              %xED %x80-9F UTF8-tail / %xEE-EF 2( UTF8-tail )
UTF8-4      = %xF0 %x90-BF 2( UTF8-tail ) / %xF1-F3 3( UTF8-tail ) /
              %xF4 %x80-8F 2( UTF8-tail )
UTF8-tail   = %x80-BF

signature = armor-header armor-keys CRLF signature-data armor-tail

armor-header = "-----"
    %x42.45.47.49.4E.20.50.47.50.20.53.49.47.4E.41.54.55.52.45 "-----" CRLF
    ; "-----BEGIN PGP SIGNATURE-----"

armor-keys = *(token %x3A.20 *( VCHAR / WSP ) CRLF)
    ; Armor Header Keys from RFC 4880

armor-tail = "-----" %x45.4E.44.20.50.47.50.20.53.49.47.4E.41.54.55.52.45
    "-----" CRLF
    ; "-----END PGP SIGNATURE-----"

signature-data = 1*(1*(ALPHA / DIGIT / "=" / "+" / "/") CRLF)
    ; base64; see RFC 4648
    ; includes RFC 4880 checksum
ALPHA          =  %x41-5A / %x61-7A   ; A-Z / a-z

BIT            =  "0" / "1"

CHAR           =  %x01-7F
                       ; any 7-bit US-ASCII character,
                       ;  excluding NUL

CR             =  %x0D
                       ; carriage return

CRLF           =  CR LF
                       ; Internet standard newline

CTL            =  %x00-1F / %x7F
                       ; controls

DIGIT          =  %x30-39
                       ; 0-9

DQUOTE         =  %x22
                       ; " (Double Quote)

HEXDIG         =  DIGIT / "A" / "B" / "C" / "D" / "E" / "F"

HTAB           =  %x09
                       ; horizontal tab

LF             =  %x0A
                       ; linefeed

LWSP           =  *(WSP / CRLF WSP)
                       ; Use of this linear-white-space rule
                       ;  permits lines containing only white
                       ;  space that are no longer legal in
                       ;  mail headers and have caused
                       ;  interoperability problems in other
                       ;  contexts.
                       ; Do not use when defining mail
                       ;  headers and use with caution in
                       ;  other contexts.

OCTET          =  %x00-FF
                       ; 8 bits of data

SP             =  %x20

VCHAR          =  %x21-7E
                       ; visible (printing) characters

WSP            =  SP / HTAB
                       ; white space

token = 1*(ALPHA / DIGIT)
