encodeName
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
ResultError— If a value exceeds its RFC 5280 A.1 bound, an ordered attribute value is empty, a field key is unsupported, or a country code is not two characters. An input with no attributes encodes an empty Name (30 00) rather than throwing.
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