@wildboar/pki-stub
Version:
X.510 PKI-Stub ASN.1 data structures in TypeScript
177 lines • 6.17 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports._encode_Context = exports._decode_Context = exports._extension_additions_list_spec_for_Context = exports._root_component_type_list_2_spec_for_Context = exports._root_component_type_list_1_spec_for_Context = exports.Context = void 0;
/* eslint-disable */
const asn1_ts_1 = require("asn1-ts");
const $ = require("asn1-ts/dist/node/functional");
/* START_OF_SYMBOL_DEFINITION Context */
/**
* @summary Context
* @description
*
* ### ASN.1 Definition:
*
* ```asn1
* Context ::= SEQUENCE {
* contextType CONTEXT.&id({SupportedContexts}),
* contextValues
* SET SIZE (1..MAX) OF CONTEXT.&Type({SupportedContexts}{@contextType}),
* fallback BOOLEAN DEFAULT FALSE,
* ... }
* ```
*
* @class
*/
class Context {
constructor(
/**
* @summary `contextType`.
* @public
* @readonly
*/
contextType,
/**
* @summary `contextValues`.
* @public
* @readonly
*/
contextValues,
/**
* @summary `fallback`.
* @public
* @readonly
*/
fallback,
/**
* @summary Extensions that are not recognized.
* @public
* @readonly
*/
_unrecognizedExtensionsList = []) {
this.contextType = contextType;
this.contextValues = contextValues;
this.fallback = fallback;
this._unrecognizedExtensionsList = _unrecognizedExtensionsList;
}
/**
* @summary Restructures an object into a Context
* @description
*
* This takes an `object` and converts it to a `Context`.
*
* @public
* @static
* @method
* @param {Object} _o An object having all of the keys and values of a `Context`.
* @returns {Context}
*/
static _from_object(_o) {
return new Context(_o.contextType, _o.contextValues, _o.fallback, _o._unrecognizedExtensionsList);
}
/**
* @summary Getter that returns the default value for `fallback`.
* @public
* @static
* @method
*/
static get _default_value_for_fallback() {
return false;
}
}
exports.Context = Context;
/* END_OF_SYMBOL_DEFINITION Context */
/* START_OF_SYMBOL_DEFINITION _root_component_type_list_1_spec_for_Context */
/**
* @summary The Leading Root Component Types of Context
* @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_Context = [
new $.ComponentSpec("contextType", false, $.hasTag(asn1_ts_1.ASN1TagClass.universal, 6), undefined, undefined),
new $.ComponentSpec("contextValues", false, $.hasTag(asn1_ts_1.ASN1TagClass.universal, 17), undefined, undefined),
new $.ComponentSpec("fallback", true, $.hasTag(asn1_ts_1.ASN1TagClass.universal, 1), undefined, undefined),
];
/* END_OF_SYMBOL_DEFINITION _root_component_type_list_1_spec_for_Context */
/* START_OF_SYMBOL_DEFINITION _root_component_type_list_2_spec_for_Context */
/**
* @summary The Trailing Root Component Types of Context
* @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_Context = [];
/* END_OF_SYMBOL_DEFINITION _root_component_type_list_2_spec_for_Context */
/* START_OF_SYMBOL_DEFINITION _extension_additions_list_spec_for_Context */
/**
* @summary The Extension Addition Component Types of Context
* @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_Context = [];
/* END_OF_SYMBOL_DEFINITION _extension_additions_list_spec_for_Context */
/* START_OF_SYMBOL_DEFINITION _decode_Context */
/**
* @summary Decodes an ASN.1 element into a(n) Context
* @function
* @param {_Element} el The element being decoded.
* @returns {Context} The decoded data structure.
*/
function _decode_Context(el) {
/* START_OF_SEQUENCE_COMPONENT_DECLARATIONS */
let contextType;
let contextValues;
let fallback = Context._default_value_for_fallback;
let _unrecognizedExtensionsList = [];
/* END_OF_SEQUENCE_COMPONENT_DECLARATIONS */
/* START_OF_CALLBACKS_MAP */
const callbacks = {
contextType: (_el) => {
contextType = $._decodeObjectIdentifier(_el);
},
contextValues: (_el) => {
contextValues = $._decodeSetOf(() => $._decodeAny)(_el);
},
fallback: (_el) => {
fallback = $._decodeBoolean(_el);
},
};
/* END_OF_CALLBACKS_MAP */
$._parse_sequence(el, callbacks, exports._root_component_type_list_1_spec_for_Context, exports._extension_additions_list_spec_for_Context, exports._root_component_type_list_2_spec_for_Context, (ext) => {
_unrecognizedExtensionsList.push(ext);
});
return new Context(
/* SEQUENCE_CONSTRUCTOR_CALL */ contextType, contextValues, fallback, _unrecognizedExtensionsList);
}
exports._decode_Context = _decode_Context;
/* END_OF_SYMBOL_DEFINITION _decode_Context */
/* START_OF_SYMBOL_DEFINITION _encode_Context */
/**
* @summary Encodes a(n) Context 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 Context, encoded as an ASN.1 Element.
*/
function _encode_Context(value, elGetter) {
const components = [
/* REQUIRED */ $._encodeObjectIdentifier(value.contextType, $.BER),
/* REQUIRED */ $._encodeSetOf(() => $._encodeAny, $.BER)(value.contextValues, $.BER),
];
if (value.fallback) {
components.push($._encodeBoolean(value.fallback, $.BER));
}
components.push(...value._unrecognizedExtensionsList);
return $._encodeSequence(components, $.BER);
}
exports._encode_Context = _encode_Context;
/* END_OF_SYMBOL_DEFINITION _encode_Context */
/* eslint-enable */
//# sourceMappingURL=Context.ta.js.map