@wildboar/pkcs
Version:
Public Key Cryptography Standard PDUs in TypeScript
134 lines (133 loc) • 4.75 kB
JavaScript
/* eslint-disable */
import { ASN1TagClass as _TagClass, } from "@wildboar/asn1";
import * as $ from "@wildboar/asn1/functional";
import { _decode_ContentType, _encode_ContentType, } from "../CryptographicMessageSyntax/ContentType.ta.mjs";
/**
* @summary EncapsulatedContentInfo
* @description
*
* ### ASN.1 Definition:
*
* ```asn1
* EncapsulatedContentInfo ::= SEQUENCE {
* eContentType ContentType,
* eContent [0] EXPLICIT OCTET STRING OPTIONAL
* }
* ```
*
*/
export class EncapsulatedContentInfo {
eContentType;
eContent;
constructor(
/**
* @summary `eContentType`.
* @public
* @readonly
*/
eContentType,
/**
* @summary `eContent`.
* @public
* @readonly
*/
eContent) {
this.eContentType = eContentType;
this.eContent = eContent;
}
/**
* @summary Restructures an object into a EncapsulatedContentInfo
* @description
*
* This takes an `object` and converts it to a `EncapsulatedContentInfo`.
*
* @public
* @static
* @method
* @param {Object} _o An object having all of the keys and values of a `EncapsulatedContentInfo`.
* @returns {EncapsulatedContentInfo}
*/
static _from_object(_o) {
return new EncapsulatedContentInfo(_o.eContentType, _o.eContent);
}
}
/**
* @summary The Leading Root Component Types of EncapsulatedContentInfo
* @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_EncapsulatedContentInfo = [
new $.ComponentSpec("eContentType", false, $.hasTag(_TagClass.universal, 6)),
new $.ComponentSpec("eContent", true, $.hasTag(_TagClass.context, 0)),
];
/**
* @summary The Trailing Root Component Types of EncapsulatedContentInfo
* @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_EncapsulatedContentInfo = [];
/**
* @summary The Extension Addition Component Types of EncapsulatedContentInfo
* @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_EncapsulatedContentInfo = [];
let _cached_decoder_for_EncapsulatedContentInfo = null;
/**
* @summary Decodes an ASN.1 element into a(n) EncapsulatedContentInfo
* @function
* @param {_Element} el The element being decoded.
* @returns {EncapsulatedContentInfo} The decoded data structure.
*/
export function _decode_EncapsulatedContentInfo(el) {
if (!_cached_decoder_for_EncapsulatedContentInfo) {
_cached_decoder_for_EncapsulatedContentInfo = function (el) {
let eContentType;
let eContent;
const callbacks = {
eContentType: (_el) => {
eContentType = _decode_ContentType(_el);
},
eContent: (_el) => {
eContent = $._decode_explicit(() => $._decodeOctetString)(_el);
},
};
$._parse_sequence(el, callbacks, _root_component_type_list_1_spec_for_EncapsulatedContentInfo, _extension_additions_list_spec_for_EncapsulatedContentInfo, _root_component_type_list_2_spec_for_EncapsulatedContentInfo, undefined);
return new EncapsulatedContentInfo(eContentType, eContent);
};
}
return _cached_decoder_for_EncapsulatedContentInfo(el);
}
let _cached_encoder_for_EncapsulatedContentInfo = null;
/**
* @summary Encodes a(n) EncapsulatedContentInfo 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 EncapsulatedContentInfo, encoded as an ASN.1 Element.
*/
export function _encode_EncapsulatedContentInfo(value, elGetter) {
if (!_cached_encoder_for_EncapsulatedContentInfo) {
_cached_encoder_for_EncapsulatedContentInfo = function (value) {
return $._encodeSequence([]
.concat([
/* REQUIRED */ _encode_ContentType(value.eContentType, $.BER),
/* IF_ABSENT */ value.eContent === undefined
? undefined
: $._encode_explicit(_TagClass.context, 0, () => $._encodeOctetString, $.BER)(value.eContent, $.BER),
])
.filter((c) => !!c), $.BER);
};
}
return _cached_encoder_for_EncapsulatedContentInfo(value, elGetter);
}
/* eslint-enable */