;;
;; DN productions from RFC 4514
;; 
distinguishedName = [ relativeDistinguishedName
    *( COMMA relativeDistinguishedName ) ]
relativeDistinguishedName = attributeTypeAndValue
    *( PLUS attributeTypeAndValue )
attributeTypeAndValue = attributeType EQUALS attributeValue
attributeType = descr / numericoid
attributeValue = string / hexstring

; The following characters are to be escaped when they appear
; in the value to be encoded: ESC, one of <escaped>, leading
; SHARP or SPACE, trailing SPACE, and NULL.
string =   [ ( leadchar / pair ) [ *( stringchar / pair )
   ( trailchar / pair ) ] ]

leadchar = LUTF1 / UTFMB
LUTF1 = %x01-1F / %x21 / %x24-2A / %x2D-3A /
   %x3D / %x3F-5B / %x5D-7F

trailchar  = TUTF1 / UTFMB
TUTF1 = %x01-1F / %x21 / %x23-2A / %x2D-3A /
   %x3D / %x3F-5B / %x5D-7F

stringchar = SUTF1 / UTFMB
SUTF1 = %x01-21 / %x23-2A / %x2D-3A /
   %x3D / %x3F-5B / %x5D-7F

pair = ESC ( ESC / special / hexpair )
special = escaped / SPACE / SHARP / EQUALS
escaped = DQUOTE / PLUS / COMMA / SEMI / LANGLE / RANGLE
hexstring = SHARP 1*hexpair
hexpair = HEX HEX

;; Common productions from RFC 4512
keystring = leadkeychar *keychar
leadkeychar = ALPHA
keychar = ALPHA / DIGIT / HYPHEN
number  = DIGIT / ( LDIGIT 1*DIGIT )

ALPHA   = %x41-5A / %x61-7A   ; "A"-"Z" / "a"-"z"
DIGIT   = %x30 / LDIGIT       ; "0"-"9"
LDIGIT  = %x31-39             ; "1"-"9"
HEX     = DIGIT / %x41-46 / %x61-66 ; "0"-"9" / "A"-"F" / "a"-"f"

SP      = 1*SPACE  ; one or more " "
WSP     = 0*SPACE  ; zero or more " "
NULL    = %x00 ; null (0)
SPACE   = %x20 ; space (" ")
DQUOTE  = %x22 ; quote (""")
SHARP   = %x23 ; octothorpe (or sharp sign) ("#")
DOLLAR  = %x24 ; dollar sign ("$")
SQUOTE  = %x27 ; single quote ("'")
LPAREN  = %x28 ; left paren ("(")
RPAREN  = %x29 ; right paren (")")
PLUS    = %x2B ; plus sign ("+")
COMMA   = %x2C ; comma (",")
HYPHEN  = %x2D ; hyphen ("-")
DOT     = %x2E ; period (".")
SEMI    = %x3B ; semicolon (";")
LANGLE  = %x3C ; left angle bracket ("<")
EQUALS  = %x3D ; equals sign ("=")
RANGLE  = %x3E ; right angle bracket (">")
ESC     = %x5C ; backslash ("\")
USCORE  = %x5F ; underscore ("_")
LCURLY  = %x7B ; left curly brace "{"
RCURLY  = %x7D ; right curly brace "}"

; Any UTF-8 [RFC3629] encoded Unicode [Unicode] character
UTF8    = UTF1 / UTFMB
UTFMB   = UTF2 / UTF3 / UTF4
UTF0    = %x80-BF
UTF1    = %x00-7F
UTF2    = %xC2-DF UTF0
UTF3    = %xE0 %xA0-BF UTF0 / %xE1-EC 2(UTF0) /
          %xED %x80-9F UTF0 / %xEE-EF 2(UTF0)
UTF4    = %xF0 %x90-BF 2(UTF0) / %xF1-F3 3(UTF0) /
          %xF4 %x80-8F 2(UTF0)

OCTET   = %x00-FF ; Any octet (8-bit data unit)

numericoid = number 1*( DOT number )

descr = keystring

oid = descr / numericoid

