@wildboar/pkcs
Version:
Public Key Cryptography Standard PDUs in TypeScript
155 lines • 6.09 kB
JavaScript
;
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.CMSContentTable = void 0;
/* eslint-disable */
const asn1_ts_1 = require("asn1-ts");
const $ = require("asn1-ts/dist/node/functional");
var CMSContentTable_osa_1 = require("../CryptographicMessageSyntax/CMSContentTable.osa");
Object.defineProperty(exports, "CMSContentTable", { enumerable: true, get: function () { return CMSContentTable_osa_1.CMSContentTable; } });
/* START_OF_SYMBOL_DEFINITION ContentInfo */
/**
* @summary ContentInfo
* @description
*
* ### ASN.1 Definition:
*
* ```asn1
* ContentInfo ::= SEQUENCE {
* content-type CMS-CONTENT-TYPE.&id({CMSContentTable}),
* pkcs7-content [0] CMS-CONTENT-TYPE.&Type({CMSContentTable})
* }
* ```
*
* @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", false, $.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) {
const sequence = el.sequence;
if (sequence.length < 2) {
throw new asn1_ts_1.ASN1ConstructionError("ContentInfo contained only " +
sequence.length.toString() +
" elements.");
}
sequence[0].name = "content-type";
sequence[1].name = "pkcs7-content";
let content_type;
let pkcs7_content;
content_type = $._decodeObjectIdentifier(sequence[0]);
pkcs7_content = $._decode_implicit(() => $._decodeAny)(sequence[1]);
return new ContentInfo(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),
/* REQUIRED */ $._encode_implicit(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