UNPKG

asn1-ts

Version:

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

14 lines (13 loc) 577 B
import isNumericCharacter from "../../../validators/isNumericCharacter.mjs"; import convertTextToBytes from "../../../utils/convertTextToBytes.mjs"; import { ASN1CharactersError } from "../../../errors.mjs"; export default function encodeNumericString(value) { const bytes = convertTextToBytes(value); for (const char of bytes) { if (!isNumericCharacter(char)) { throw new ASN1CharactersError("NumericString can only contain characters 0 - 9 and space. " + `Encountered character code ${char}.`); } } return bytes; }