UNPKG

asn1-ts

Version:

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

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