UNPKG

@syncfusion/ej2-pdf

Version:

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

87 lines (86 loc) 3.25 kB
import { _ConstructionType, _TagClassType, _UniversalType } from '../asn1/enumerator'; import { _PdfAbstractSyntaxElement } from '../asn1/abstract-syntax'; import { _PdfUniqueEncodingElement } from '../asn1/unique-encoding-element'; import { _PdfObjectIdentifier } from '../asn1/identifier-mapping'; /** * Represents algorithm identifier components parsed from ASN.1 AlgorithmIdentifier. * * @private */ var _PdfAlgorithms = /** @class */ (function () { function _PdfAlgorithms(element) { if (element) { this._element = element; var list = element._getSequence(); if (!list || list.length < 1 || list.length > 2) { throw new Error('Invalid Algorithm Identifier sequence length'); } var oidElement = list[0]; var oidBytes = oidElement._getValue(); this._objectID = new _PdfObjectIdentifier()._fromBytes(oidBytes); if (list.length === 2) { this._parameters = list[1]; this._parametersDefined = true; } else { this._parametersDefined = false; } } } /** * Normalize or construct a `_PdfAlgorithms` instance from an input value. * * @private * @param {any} obj - Candidate object or ASN.1 element to convert. * @returns {_PdfAlgorithms} The resolved algorithms instance or undefined. */ _PdfAlgorithms.prototype._getAlgorithms = function (obj) { if (obj instanceof _PdfAlgorithms) { return obj; } if (obj instanceof _PdfAbstractSyntaxElement) { return new _PdfAlgorithms(obj); } return undefined; }; /** * Return the DER/unique encoding bytes for the underlying element. * * @private * @returns {Uint8Array} The encoded bytes for the algorithm identifier. */ _PdfAlgorithms.prototype._uniqueEncoderEncode = function () { if (this._element) { return this._element._getValue(); // eslint-disable-line } throw new Error('Cannot DER encode: not a DER element'); }; /** * Create an ASN.1 NULL unique encoder element. * * @private * @returns {_PdfAbstractSyntaxElement} A DER NULL element. */ _PdfAlgorithms.prototype._getUniqueEncoderNull = function () { var derNull = new _PdfUniqueEncodingElement(); derNull._setTagNumber(5); derNull._tagClass = 0; derNull._setValue(new Uint8Array(0)); return derNull; }; /** * Build an abstract syntax element representing the AlgorithmIdentifier sequence. * * @private * @returns {_PdfUniqueEncodingElement} The constructed ASN.1 sequence element. */ _PdfAlgorithms.prototype._getAbstractSyntax = function () { var seq = new _PdfUniqueEncodingElement(_TagClassType.universal, _ConstructionType.constructed, _UniversalType.sequence); var oidElement = new _PdfUniqueEncodingElement(_TagClassType.universal, _ConstructionType.primitive, 6); var elements = [oidElement]; seq._setSequence(elements); return seq; }; return _PdfAlgorithms; }()); export { _PdfAlgorithms };