@wildboar/pki-stub
Version:
X.510 PKI-Stub ASN.1 data structures in TypeScript
183 lines • 6.27 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports._encode_Extension = exports._decode_Extension = exports._extension_additions_list_spec_for_Extension = exports._root_component_type_list_2_spec_for_Extension = exports._root_component_type_list_1_spec_for_Extension = exports.Extension = void 0;
/* eslint-disable */
const asn1_ts_1 = require("asn1-ts");
const $ = require("asn1-ts/dist/node/functional");
/* START_OF_SYMBOL_DEFINITION Extension */
/**
* @summary Extension
* @description
*
* ### ASN.1 Definition:
*
* ```asn1
* Extension ::= SEQUENCE {
* extnId EXTENSION.&id({ExtensionSet}),
* critical BOOLEAN DEFAULT FALSE,
* extnValue OCTET STRING
* (CONTAINING EXTENSION.&ExtnType({ExtensionSet}{@extnId})
* ENCODED BY der),
* ... }
* ```
*
* @class
*/
class Extension {
constructor(
/**
* @summary `extnId`.
* @public
* @readonly
*/
extnId,
/**
* @summary `critical`.
* @public
* @readonly
*/
critical,
/**
* @summary `extnValue`.
* @public
* @readonly
*/
extnValue,
/**
* @summary Extensions that are not recognized.
* @public
* @readonly
*/
_unrecognizedExtensionsList = []) {
this.extnId = extnId;
this.critical = critical;
this.extnValue = extnValue;
this._unrecognizedExtensionsList = _unrecognizedExtensionsList;
}
/**
* @summary Restructures an object into a Extension
* @description
*
* This takes an `object` and converts it to a `Extension`.
*
* @public
* @static
* @method
* @param {Object} _o An object having all of the keys and values of a `Extension`.
* @returns {Extension}
*/
static _from_object(_o) {
return new Extension(_o.extnId, _o.critical, _o.extnValue, _o._unrecognizedExtensionsList);
}
/**
* @summary Getter that returns the default value for `critical`.
* @public
* @static
* @method
*/
static get _default_value_for_critical() {
return false;
}
valueElement() {
const el = new asn1_ts_1.DERElement();
el.fromBytes(this.extnValue);
return el;
}
}
exports.Extension = Extension;
/* END_OF_SYMBOL_DEFINITION Extension */
/* START_OF_SYMBOL_DEFINITION _root_component_type_list_1_spec_for_Extension */
/**
* @summary The Leading Root Component Types of Extension
* @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
*/
exports._root_component_type_list_1_spec_for_Extension = [
new $.ComponentSpec("extnId", false, $.hasTag(asn1_ts_1.ASN1TagClass.universal, 6), undefined, undefined),
new $.ComponentSpec("critical", true, $.hasTag(asn1_ts_1.ASN1TagClass.universal, 1), undefined, undefined),
new $.ComponentSpec("extnValue", false, $.hasTag(asn1_ts_1.ASN1TagClass.universal, 4), undefined, undefined),
];
/* END_OF_SYMBOL_DEFINITION _root_component_type_list_1_spec_for_Extension */
/* START_OF_SYMBOL_DEFINITION _root_component_type_list_2_spec_for_Extension */
/**
* @summary The Trailing Root Component Types of Extension
* @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
*/
exports._root_component_type_list_2_spec_for_Extension = [];
/* END_OF_SYMBOL_DEFINITION _root_component_type_list_2_spec_for_Extension */
/* START_OF_SYMBOL_DEFINITION _extension_additions_list_spec_for_Extension */
/**
* @summary The Extension Addition Component Types of Extension
* @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
*/
exports._extension_additions_list_spec_for_Extension = [];
/* END_OF_SYMBOL_DEFINITION _extension_additions_list_spec_for_Extension */
/* START_OF_SYMBOL_DEFINITION _decode_Extension */
/**
* @summary Decodes an ASN.1 element into a(n) Extension
* @function
* @param {_Element} el The element being decoded.
* @returns {Extension} The decoded data structure.
*/
function _decode_Extension(el) {
/* START_OF_SEQUENCE_COMPONENT_DECLARATIONS */
let extnId;
let critical = Extension._default_value_for_critical;
let extnValue;
let _unrecognizedExtensionsList = [];
/* END_OF_SEQUENCE_COMPONENT_DECLARATIONS */
/* START_OF_CALLBACKS_MAP */
const callbacks = {
extnId: (_el) => {
extnId = $._decodeObjectIdentifier(_el);
},
critical: (_el) => {
critical = $._decodeBoolean(_el);
},
extnValue: (_el) => {
extnValue = $._decodeOctetString(_el);
},
};
/* END_OF_CALLBACKS_MAP */
$._parse_sequence(el, callbacks, exports._root_component_type_list_1_spec_for_Extension, exports._extension_additions_list_spec_for_Extension, exports._root_component_type_list_2_spec_for_Extension, (ext) => {
_unrecognizedExtensionsList.push(ext);
});
return new Extension(
/* SEQUENCE_CONSTRUCTOR_CALL */ extnId, critical, extnValue, _unrecognizedExtensionsList);
}
exports._decode_Extension = _decode_Extension;
/* END_OF_SYMBOL_DEFINITION _decode_Extension */
/* START_OF_SYMBOL_DEFINITION _encode_Extension */
/**
* @summary Encodes a(n) Extension into an ASN.1 Element.
* @function
* @param {value} el The element being decoded.
* @param elGetter A function that can be used to get new ASN.1 elements.
* @returns {_Element} The Extension, encoded as an ASN.1 Element.
*/
function _encode_Extension(value, elGetter) {
const components = [
/* REQUIRED */ $._encodeObjectIdentifier(value.extnId, $.BER),
];
if (value.critical) {
components.push($._encodeBoolean(value.critical, $.BER));
}
components.push($._encodeOctetString(value.extnValue, $.BER));
components.push(...value._unrecognizedExtensionsList);
return $._encodeSequence(components, $.BER);
}
exports._encode_Extension = _encode_Extension;
/* END_OF_SYMBOL_DEFINITION _encode_Extension */
/* eslint-enable */
//# sourceMappingURL=Extension.ta.js.map