UNPKG

@syncfusion/ej2-pdf

Version:

Feature-rich JavaScript PDF library with built-in support for loading and manipulating PDF document.

61 lines (60 loc) 2.12 kB
/** * Helper representing ASN.1 Time types (UTCTime/GeneralizedTime) and conversion utilities. * * @private */ var _PdfX509Time = /** @class */ (function () { function _PdfX509Time(time) { this._time = time; } /** * Extract a trimmed universal time string from the ASN.1 time element. * * @private * @returns {string} RFC-style time string or undefined when unavailable. */ _PdfX509Time.prototype._getUniversalTime = function () { if (this._time._getTagNumber() === 23) { var val = this._time._getValue(); // eslint-disable-line if (typeof val === 'string') { return val.trim(); } if (val instanceof Uint8Array) { var charCodes = []; for (var i = 0; i < val.length; i++) { charCodes.push(val[i]); } return String.fromCharCode.apply(null, charCodes).trim(); } } return undefined; }; /** * Convert the ASN.1 time element into a JavaScript `Date` object (UTC). * * @private * @returns {Date} Parsed Date object or undefined if parsing fails. */ _PdfX509Time.prototype._toDate = function () { var str = this._getUniversalTime(); if (str) { var m = str.match(/^(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})Z$/); if (!m) { m = str.match(/^(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})Z$/); } if (m) { var year = parseInt(m[1], 10); year += (year < 50) ? 2000 : 1900; var month = parseInt(m[2], 10) - 1; var day = parseInt(m[3], 10); var hour = parseInt(m[4], 10); var minute = parseInt(m[5], 10); var second = m.length > 6 && typeof m[6] !== 'undefined' ? parseInt(m[6], 10) : 0; return new Date(Date.UTC(year, month, day, hour, minute, second)); } } return undefined; }; return _PdfX509Time; }()); export { _PdfX509Time };