Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

GeneralName Constants

synta.general_name provides integer constants for the GeneralName CHOICE type (RFC 5280 §4.2.1.6). These are the tag_number values returned by Certificate.subject_alt_names() and synta.parse_general_names().

import synta.general_name as gn

Constants

ConstantValueGeneralName alternativeContent
OTHER_NAME0otherNameFull OtherNameValue TLV (constructed)
RFC822_NAME1rfc822NameRaw IA5String bytes (e-mail address)
DNS_NAME2dNSNameRaw IA5String bytes (DNS host name)
X400_ADDRESS3x400Address(rarely used)
DIRECTORY_NAME4directoryNameComplete Name SEQUENCE TLV — pass to parse_name_attrs()
EDI_PARTY_NAME5ediPartyName(rarely used)
URI6uniformResourceIdentifierRaw IA5String bytes (URI)
IP_ADDRESS7iPAddress4 bytes (IPv4) or 16 bytes (IPv6)
REGISTERED_ID8registeredIDRaw OID value bytes

parse_general_names

synta.parse_general_names(san_der: bytes) -> list[tuple[int, bytes]]

Parse a DER SEQUENCE OF GeneralName into (tag_number, content) pairs. Use the synta.general_name constants to dispatch on tag_number. This function is the low-level alternative to Certificate.subject_alt_names() — use it when you have raw extension value bytes from cert.get_extension_value_der(...).

parse_name_attrs

synta.parse_name_attrs(name_der: bytes) -> list[tuple[str, str]]

Walk a DER Name SEQUENCE and return (dotted_oid, value_str) pairs in traversal order. Pass DIRECTORY_NAME content bytes (a complete Name SEQUENCE TLV) to this function.

Typical dispatch pattern

import ipaddress
import synta
import synta.general_name as gn

for tag_num, content in cert.subject_alt_names():
    if tag_num == gn.DNS_NAME:
        print("DNS:", content.decode("ascii"))
    elif tag_num == gn.IP_ADDRESS:
        print("IP:", ipaddress.ip_address(content))
    elif tag_num == gn.RFC822_NAME:
        print("email:", content.decode("ascii"))
    elif tag_num == gn.URI:
        print("URI:", content.decode("ascii"))
    elif tag_num == gn.DIRECTORY_NAME:
        attrs = synta.parse_name_attrs(content)   # [(oid_str, value_str), …]
        print("DirName:", attrs)

The same constants apply when calling synta.parse_general_names(san_der) directly on raw extnValue bytes:

san_der = cert.get_extension_value_der(synta.oids.SUBJECT_ALT_NAME)
if san_der:
    for tag_num, content in synta.parse_general_names(san_der):
        if tag_num == gn.DNS_NAME:
            print("DNS:", content.decode("ascii"))

See also Certificate for subject_alt_names() and the Well-known OIDs page for synta.oids.SUBJECT_ALT_NAME and related constants.