@wildboar/pkcs
Version:
Public Key Cryptography Standard PDUs in TypeScript
149 lines (148 loc) • 5.6 kB
JavaScript
/* eslint-disable */
import { ASN1ConstructionError as _ConstructionError, ASN1TagClass as _TagClass, } from "@wildboar/asn1";
import * as $ from "@wildboar/asn1/functional";
import { _decode_ExtendedCertificateInfo, _encode_ExtendedCertificateInfo, } from "../CryptographicMessageSyntax/ExtendedCertificateInfo.ta.mjs";
import { _decode_Signature, _encode_Signature, } from "../CryptographicMessageSyntax/Signature.ta.mjs";
import { _decode_SignatureAlgorithmIdentifier, _encode_SignatureAlgorithmIdentifier, } from "../CryptographicMessageSyntax/SignatureAlgorithmIdentifier.ta.mjs";
/**
* @summary ExtendedCertificate
* @description
*
* ### ASN.1 Definition:
*
* ```asn1
* ExtendedCertificate ::= SEQUENCE {
* extendedCertificateInfo ExtendedCertificateInfo,
* signatureAlgorithm SignatureAlgorithmIdentifier,
* signature Signature
* }
* ```
*
*/
export class ExtendedCertificate {
extendedCertificateInfo;
signatureAlgorithm;
signature;
constructor(
/**
* @summary `extendedCertificateInfo`.
* @public
* @readonly
*/
extendedCertificateInfo,
/**
* @summary `signatureAlgorithm`.
* @public
* @readonly
*/
signatureAlgorithm,
/**
* @summary `signature`.
* @public
* @readonly
*/
signature) {
this.extendedCertificateInfo = extendedCertificateInfo;
this.signatureAlgorithm = signatureAlgorithm;
this.signature = signature;
}
/**
* @summary Restructures an object into a ExtendedCertificate
* @description
*
* This takes an `object` and converts it to a `ExtendedCertificate`.
*
* @public
* @static
* @method
* @param {Object} _o An object having all of the keys and values of a `ExtendedCertificate`.
* @returns {ExtendedCertificate}
*/
static _from_object(_o) {
return new ExtendedCertificate(_o.extendedCertificateInfo, _o.signatureAlgorithm, _o.signature);
}
}
/**
* @summary The Leading Root Component Types of ExtendedCertificate
* @description
*
* This is an array of `ComponentSpec`s that define how to decode the leading root component type list of a SET or SEQUENCE.
*
* @constant
*/
export const _root_component_type_list_1_spec_for_ExtendedCertificate = [
new $.ComponentSpec("extendedCertificateInfo", false, $.hasTag(_TagClass.universal, 16)),
new $.ComponentSpec("signatureAlgorithm", false, $.hasTag(_TagClass.universal, 16)),
new $.ComponentSpec("signature", false, $.hasTag(_TagClass.universal, 3)),
];
/**
* @summary The Trailing Root Component Types of ExtendedCertificate
* @description
*
* This is an array of `ComponentSpec`s that define how to decode the trailing root component type list of a SET or SEQUENCE.
*
* @constant
*/
export const _root_component_type_list_2_spec_for_ExtendedCertificate = [];
/**
* @summary The Extension Addition Component Types of ExtendedCertificate
* @description
*
* This is an array of `ComponentSpec`s that define how to decode the extension addition component type list of a SET or SEQUENCE.
*
* @constant
*/
export const _extension_additions_list_spec_for_ExtendedCertificate = [];
let _cached_decoder_for_ExtendedCertificate = null;
/**
* @summary Decodes an ASN.1 element into a(n) ExtendedCertificate
* @function
* @param {_Element} el The element being decoded.
* @returns {ExtendedCertificate} The decoded data structure.
*/
export function _decode_ExtendedCertificate(el) {
if (!_cached_decoder_for_ExtendedCertificate) {
_cached_decoder_for_ExtendedCertificate = function (el) {
const sequence = el.sequence;
if (sequence.length < 3) {
throw new _ConstructionError("ExtendedCertificate contained only " +
sequence.length.toString() +
" elements.");
}
sequence[0].name = "extendedCertificateInfo";
sequence[1].name = "signatureAlgorithm";
sequence[2].name = "signature";
let extendedCertificateInfo;
let signatureAlgorithm;
let signature;
extendedCertificateInfo = _decode_ExtendedCertificateInfo(sequence[0]);
signatureAlgorithm = _decode_SignatureAlgorithmIdentifier(sequence[1]);
signature = _decode_Signature(sequence[2]);
return new ExtendedCertificate(extendedCertificateInfo, signatureAlgorithm, signature);
};
}
return _cached_decoder_for_ExtendedCertificate(el);
}
let _cached_encoder_for_ExtendedCertificate = null;
/**
* @summary Encodes a(n) ExtendedCertificate into an ASN.1 Element.
* @function
* @param value The element being encoded.
* @param elGetter A function that can be used to get new ASN.1 elements.
* @returns {_Element} The ExtendedCertificate, encoded as an ASN.1 Element.
*/
export function _encode_ExtendedCertificate(value, elGetter) {
if (!_cached_encoder_for_ExtendedCertificate) {
_cached_encoder_for_ExtendedCertificate = function (value) {
return $._encodeSequence([]
.concat([
/* REQUIRED */ _encode_ExtendedCertificateInfo(value.extendedCertificateInfo, $.BER),
/* REQUIRED */ _encode_SignatureAlgorithmIdentifier(value.signatureAlgorithm, $.BER),
/* REQUIRED */ _encode_Signature(value.signature, $.BER),
])
.filter((c) => !!c), $.BER);
};
}
return _cached_encoder_for_ExtendedCertificate(value, elGetter);
}
/* eslint-enable */