UNPKG

@wildboar/pkcs

Version:
132 lines (131 loc) 4.3 kB
/* eslint-disable */ import { ASN1ConstructionError as _ConstructionError, ASN1TagClass as _TagClass, } from "@wildboar/asn1"; import * as $ from "@wildboar/asn1/functional"; /** * @summary ContentInfo * @description * * ### ASN.1 Definition: * * ```asn1 * ContentInfo ::= SEQUENCE { * content-type CMS-CONTENT-TYPE.&id({CMSContentTable}), * pkcs7-content [0] CMS-CONTENT-TYPE.&Type({CMSContentTable}) * } * ``` * */ export class ContentInfo { content_type; pkcs7_content; 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); } } /** * @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 */ export const _root_component_type_list_1_spec_for_ContentInfo = [ new $.ComponentSpec("content-type", false, $.hasTag(_TagClass.universal, 6)), new $.ComponentSpec("pkcs7-content", false, $.hasTag(_TagClass.context, 0)), ]; /** * @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 */ export const _root_component_type_list_2_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 */ export const _extension_additions_list_spec_for_ContentInfo = []; let _cached_decoder_for_ContentInfo = null; /** * @summary Decodes an ASN.1 element into a(n) ContentInfo * @function * @param {_Element} el The element being decoded. * @returns {ContentInfo} The decoded data structure. */ export 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 _ConstructionError("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); } let _cached_encoder_for_ContentInfo = null; /** * @summary Encodes a(n) ContentInfo 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 ContentInfo, encoded as an ASN.1 Element. */ export function _encode_ContentInfo(value, elGetter) { if (!_cached_encoder_for_ContentInfo) { _cached_encoder_for_ContentInfo = function (value) { return $._encodeSequence([] .concat([ /* REQUIRED */ $._encodeObjectIdentifier(value.content_type, $.BER), /* REQUIRED */ $._encode_implicit(_TagClass.context, 0, () => $._encodeAny, $.BER)(value.pkcs7_content, $.BER), ]) .filter((c) => !!c), $.BER); }; } return _cached_encoder_for_ContentInfo(value, elGetter); } /* eslint-enable */