UNPKG

asn1-ts

Version:

ASN.1 encoding and decoding, including BER, CER, and DER.

14 lines (13 loc) 616 B
import isObjectDescriptorCharacter from "../../../validators/isObjectDescriptorCharacter.mjs"; import convertTextToBytes from "../../../utils/convertTextToBytes.mjs"; import { ASN1CharactersError } from "../../../errors.mjs"; export default function encodeObjectDescriptor(value) { const bytes = convertTextToBytes(value); for (const char of bytes) { if (!isObjectDescriptorCharacter(char)) { throw new ASN1CharactersError("ObjectDescriptor can only contain characters between 0x20 and 0x7E. " + `Encountered character code ${char}.`); } } return bytes; }