@syncfusion/ej2-pdf
Version:
Feature-rich JavaScript PDF library with built-in support for loading and manipulating PDF document.
50 lines (49 loc) • 1.97 kB
JavaScript
import { _PdfAlgorithms } from './x509-algorithm';
import { _PdfUniqueBitString } from './x509-bit-string-handler';
/**
* Container for public key information (AlgorithmIdentifier + public key BIT STRING).
*
* @private
*/
var _PdfPublicKeyInformation = /** @class */ (function () {
function _PdfPublicKeyInformation(algorithms, publicKey) {
if (algorithms && publicKey) {
this._algorithms = algorithms;
this._publicKey = publicKey;
}
}
/**
* Parse a SubjectPublicKeyInfo ASN.1 sequence into this helper.
*
* @private
* @param {_PdfAbstractSyntaxElement} abstractSyntaxSequence - ASN.1 sequence to parse.
* @returns {_PdfPublicKeyInformation} Parsed public key information instance.
*/
_PdfPublicKeyInformation.prototype._fromAbstractSyntax = function (abstractSyntaxSequence) {
var sequence = abstractSyntaxSequence._getSequence();
if (!Array.isArray(sequence) || sequence.length !== 2) {
throw new Error('Invalid length in sequence');
}
var algorithms = new _PdfAlgorithms()._getAlgorithms(sequence[0]);
var publicKey = new _PdfUniqueBitString()._fromAbstractSyntaxOctets(sequence[1]._getValue());
return new _PdfPublicKeyInformation(algorithms, publicKey);
};
/**
* Normalize an input into a `_PdfPublicKeyInformation` instance.
*
* @private
* @param {any} obj - Candidate object or ASN.1 element.
* @returns {_PdfPublicKeyInformation} The resolved public key information or undefined.
*/
_PdfPublicKeyInformation.prototype._getPublicKeyInformation = function (obj) {
if (obj instanceof _PdfPublicKeyInformation) {
return obj;
}
if (obj && obj._getSequence()) {
return this._fromAbstractSyntax(obj);
}
return undefined;
};
return _PdfPublicKeyInformation;
}());
export { _PdfPublicKeyInformation };