UNPKG

asn1-ts

Version:

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

15 lines (14 loc) 583 B
import * as errors from "../errors.mjs"; export default function datetimeComponentValidator(unitName, min, max) { return function (dataType, value) { if (!Number.isInteger(value)) { throw new errors.ASN1Error(`Non-integral ${unitName} supplied to ${dataType}.`); } if (value > max) { throw new errors.ASN1Error(`Encountered ${unitName} greater than ${max} in ${dataType}.`); } if (value < min) { throw new errors.ASN1Error(`Encountered ${unitName} less than ${min} in ${dataType}.`); } }; }