Skip to main content

3. ABNF

The ABNF [RFC5234] of the textual encoding is:

textualmsg = preeb *WSP eol
*eolWSP
base64text
posteb *WSP [eol]

preeb = "-----BEGIN " label "-----" ; unlike [RFC1421] (A)BNF,
; eol is not required (but
posteb = "-----END " label "-----" ; see [RFC1421], Section 4.4)

base64char = ALPHA / DIGIT / "+" / "/"

base64pad = "="

base64line = 1*base64char *WSP eol

base64finl = *base64char (base64pad *WSP eol base64pad /
*2base64pad) *WSP eol
; ...AB= <EOL> = <EOL> is not good, but is valid

base64text = *base64line base64finl
; we could also use <encbinbody> from RFC 1421, which requires
; 16 groups of 4 chars, which means exactly 64 chars per
; line, except the final line, but this is more accurate

labelchar = %x21-2C / %x2E-7E ; any printable character,
; except hyphen-minus

label = [ labelchar *( ["-" / SP] labelchar ) ] ; empty ok

eol = CRLF / CR / LF

eolWSP = WSP / CR / LF ; compare with LWSP

Figure 1: ABNF (Standard)

laxtextualmsg    = *W preeb
laxbase64text
posteb *W

W = WSP / CR / LF / %x0B / %x0C ; whitespace

laxbase64text = *(W / base64char) [base64pad *W [base64pad *W]]

Figure 2: ABNF (Lax)

stricttextualmsg = preeb eol
strictbase64text
posteb eol

strictbase64finl = *15(4base64char) (4base64char / 3base64char
base64pad / 2base64char 2base64pad) eol

base64fullline = 64base64char eol

strictbase64text = *base64fullline strictbase64finl

Figure 3: ABNF (Strict)

New implementations SHOULD emit the strict format (Figure 3) specified above. The choice of parsing strategy depends on the context of use.