encodeName
DER-encodes an X.509 Name.
Returns a DER SEQUENCE of RelativeDistinguishedNames (RDNs).
Each RDN emitted by this helper contains exactly one name attribute.
ts
function encodeName(
input: NameInput,
): Uint8ArrayParameters
input:NameInput— Name fields in convenience-object form or caller-ordered attribute form.
Returns — DER-encoded X.509 Name bytes.
Throws
Error— If the input produces no attributes, contains an unsupported field key, or uses an invalid country code.
See also
NameObjectinput emits populated fields in the canonical order fromNAME_OBJECT_ORDER.NameAttributearray input preserves caller-supplied ordering, but each entry still becomes its own single-attribute RDN.Attribute OIDs and ASN.1 string encodings come from
NAME_FIELD_DEFINITIONS.
Empty strings andundefinedfields are ignored when the input is aNameObject.
Examples
ts
const der = encodeName({ country: 'US', commonName: 'example.com' });
// emits two single-attribute RDNs: C=US, then CN=example.comts
const der = encodeName([
{ type: 'country', value: 'US' },
{ type: 'commonName', value: 'example.com' },
]);
// preserves caller order: C first, then CN