UNPKG

@wildboar/pkcs

Version:
165 lines 6.75 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports._encode_ContentInfo = exports._decode_ContentInfo = exports._extension_additions_list_spec_for_ContentInfo = exports._root_component_type_list_2_spec_for_ContentInfo = exports._root_component_type_list_1_spec_for_ContentInfo = exports.ContentInfo = exports.PKCS7ContentTable = void 0; /* eslint-disable */ const asn1_ts_1 = require("asn1-ts"); const $ = require("asn1-ts/dist/node/functional"); var PKCS7ContentTable_osa_1 = require("../PKCS7/PKCS7ContentTable.osa"); Object.defineProperty(exports, "PKCS7ContentTable", { enumerable: true, get: function () { return PKCS7ContentTable_osa_1.PKCS7ContentTable; } }); /* START_OF_SYMBOL_DEFINITION ContentInfo */ /** * @summary ContentInfo * @description * * NOTE: This was modified from the original definition in ITU X.420 to make * `pkcs7-content` explicitly encoded, because the ITU X.420 definition uses * implicit encoding, which conflicts with the authoritative IETF RFC version. * `pkcs7-content` was also made optional. * * ### ASN.1 Definition: * * ```asn1 * ContentInfo ::= SEQUENCE { * content-type PKCS7-CONTENT-TYPE.&id({PKCS7ContentTable}), * pkcs7-content [0] EXPLICIT PKCS7-CONTENT-TYPE.&Type({PKCS7ContentTable}) OPTIONAL * } * ``` * * @class */ class ContentInfo { constructor( /** * @summary `content_type`. * @public * @readonly */ content_type, /** * @summary `pkcs7_content`. * @public * @readonly */ pkcs7_content) { this.content_type = content_type; this.pkcs7_content = pkcs7_content; } /** * @summary Restructures an object into a ContentInfo * @description * * This takes an `object` and converts it to a `ContentInfo`. * * @public * @static * @method * @param {Object} _o An object having all of the keys and values of a `ContentInfo`. * @returns {ContentInfo} */ static _from_object(_o) { return new ContentInfo(_o.content_type, _o.pkcs7_content); } } exports.ContentInfo = ContentInfo; /* END_OF_SYMBOL_DEFINITION ContentInfo */ /* START_OF_SYMBOL_DEFINITION _root_component_type_list_1_spec_for_ContentInfo */ /** * @summary The Leading Root Component Types of ContentInfo * @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_ContentInfo = [ new $.ComponentSpec("content-type", false, $.hasTag(asn1_ts_1.ASN1TagClass.universal, 6), undefined, undefined), new $.ComponentSpec("pkcs7-content", true, $.hasTag(asn1_ts_1.ASN1TagClass.context, 0), undefined, undefined), ]; /* END_OF_SYMBOL_DEFINITION _root_component_type_list_1_spec_for_ContentInfo */ /* START_OF_SYMBOL_DEFINITION _root_component_type_list_2_spec_for_ContentInfo */ /** * @summary The Trailing Root Component Types of ContentInfo * @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_ContentInfo = []; /* END_OF_SYMBOL_DEFINITION _root_component_type_list_2_spec_for_ContentInfo */ /* START_OF_SYMBOL_DEFINITION _extension_additions_list_spec_for_ContentInfo */ /** * @summary The Extension Addition Component Types of ContentInfo * @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_ContentInfo = []; /* END_OF_SYMBOL_DEFINITION _extension_additions_list_spec_for_ContentInfo */ /* START_OF_SYMBOL_DEFINITION _cached_decoder_for_ContentInfo */ let _cached_decoder_for_ContentInfo = null; /* END_OF_SYMBOL_DEFINITION _cached_decoder_for_ContentInfo */ /* START_OF_SYMBOL_DEFINITION _decode_ContentInfo */ /** * @summary Decodes an ASN.1 element into a(n) ContentInfo * @function * @param {_Element} el The element being decoded. * @returns {ContentInfo} The decoded data structure. */ function _decode_ContentInfo(el) { if (!_cached_decoder_for_ContentInfo) { _cached_decoder_for_ContentInfo = function (el) { /* START_OF_SEQUENCE_COMPONENT_DECLARATIONS */ let content_type; let pkcs7_content; /* END_OF_SEQUENCE_COMPONENT_DECLARATIONS */ /* START_OF_CALLBACKS_MAP */ const callbacks = { "content-type": (_el) => { content_type = $._decodeObjectIdentifier(_el); }, "pkcs7-content": (_el) => { pkcs7_content = $._decode_explicit(() => $._decodeAny)(_el); }, }; /* END_OF_CALLBACKS_MAP */ $._parse_sequence(el, callbacks, exports._root_component_type_list_1_spec_for_ContentInfo, exports._extension_additions_list_spec_for_ContentInfo, exports._root_component_type_list_2_spec_for_ContentInfo, undefined); return new ContentInfo /* SEQUENCE_CONSTRUCTOR_CALL */(content_type, pkcs7_content); }; } return _cached_decoder_for_ContentInfo(el); } exports._decode_ContentInfo = _decode_ContentInfo; /* END_OF_SYMBOL_DEFINITION _decode_ContentInfo */ /* START_OF_SYMBOL_DEFINITION _cached_encoder_for_ContentInfo */ let _cached_encoder_for_ContentInfo = null; /* END_OF_SYMBOL_DEFINITION _cached_encoder_for_ContentInfo */ /* START_OF_SYMBOL_DEFINITION _encode_ContentInfo */ /** * @summary Encodes a(n) ContentInfo 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 ContentInfo, encoded as an ASN.1 Element. */ function _encode_ContentInfo(value, elGetter) { if (!_cached_encoder_for_ContentInfo) { _cached_encoder_for_ContentInfo = function (value, elGetter) { return $._encodeSequence([] .concat([ /* REQUIRED */ $._encodeObjectIdentifier(value.content_type, $.BER), /* IF_ABSENT */ value.pkcs7_content === undefined ? undefined : $._encode_explicit(asn1_ts_1.ASN1TagClass.context, 0, () => $._encodeAny, $.BER)(value.pkcs7_content, $.BER), ]) .filter((c) => !!c), $.BER); }; } return _cached_encoder_for_ContentInfo(value, elGetter); } exports._encode_ContentInfo = _encode_ContentInfo; /* END_OF_SYMBOL_DEFINITION _encode_ContentInfo */ /* eslint-enable */ //# sourceMappingURL=ContentInfo.ta.js.map