def asn1_build(node):
    """Build a DER-encoded ASN.1 data structure.

    @param node: (type, data) tuples comprising the ASN.1 structure
    @return: DER-encoded ASN.1 byte string
    """
    if node[0] == OCTET_STRING:
        return asn1_encode(OCTET_STRING, node[1])
    if node[0] == NULL:
        assert node[1] is None
        return asn1_encode(NULL, b'')
    elif node[0] == OBJECT_IDENTIFIER:
        return asn1_encode(OBJECT_IDENTIFIER, node[1])
    elif node[0] == SEQUENCE:
        r = bytearray()
        for x in node[1]:
            r += asn1_build(x)
        return asn1_encode(SEQUENCE, r)
    else:
        raise ASN1FormatError("Unexpected tag in template: %02x" % node[0])
Build a DER-encoded ASN.1 data structure.

    @param node: (type, data) tuples comprising the ASN.1 structure
    @return: DER-encoded ASN.1 byte string
    
python/dkim/asn1.py