def METHOD_NAME(dn):
    # TODO: poor man's DN parser
    d = {}
    current_attr = ""
    current_val = ""
    state = "ATTR"
    string_state = "NOT_ESCAPED"
    for c in dn:
        if c == "\\" and string_state == "NOT_ESCAPED":
            string_state = "ESCAPED"
        else:
            if string_state == "NOT_ESCAPED" and c in "=,":
                if c == "=":
                    state = "VAL"
                elif c == ",":
                    state = "ATTR"
                    if current_attr:
                        d[current_attr] = current_val
                    current_attr = current_val = ""
            else:
                if state == "ATTR":
                    current_attr += c
                elif state == "VAL":
                    current_val += c
                if string_state == "ESCAPED":
                    string_state = "NOT_ESCAPED"
    if current_attr:
        d[current_attr] = current_val
    # try to extract the serial number
    encoded_serial_number = d.get(SERIAL_NUMBER_OID)
    if encoded_serial_number:
        m = ASN1_ENCODED_STRING_RE.match(encoded_serial_number.lower())
        if m:
            try:
                d["serialNumber"] = str(load_asn1(bytes.fromhex(m.group("bytes"))))
            except Exception:
                pass
            else:
                d.pop(SERIAL_NUMBER_OID)
    return d