UNPKG

@wildboar/pkcs

Version:
154 lines (153 loc) 5.62 kB
/* eslint-disable */ import { ASN1TagClass as _TagClass, } from "@wildboar/asn1"; import * as $ from "@wildboar/asn1/functional"; import { _decode_CommonObjectAttributes, _encode_CommonObjectAttributes, } from "../PKCS-15/CommonObjectAttributes.ta.mjs"; /** * @summary PKCS15Object * @description * * ### ASN.1 Definition: * * ```asn1 * PKCS15Object {ClassAttributes, SubClassAttributes, TypeAttributes} ::= SEQUENCE { * commonObjectAttributes CommonObjectAttributes, * classAttributes ClassAttributes, * subClassAttributes [0] SubClassAttributes OPTIONAL, * typeAttributes [1] TypeAttributes * } * ``` * */ export class PKCS15Object { commonObjectAttributes; classAttributes; subClassAttributes; typeAttributes; constructor( /** * @summary `commonObjectAttributes`. * @public * @readonly */ commonObjectAttributes, /** * @summary `classAttributes`. * @public * @readonly */ classAttributes, /** * @summary `subClassAttributes`. * @public * @readonly */ subClassAttributes, /** * @summary `typeAttributes`. * @public * @readonly */ typeAttributes) { this.commonObjectAttributes = commonObjectAttributes; this.classAttributes = classAttributes; this.subClassAttributes = subClassAttributes; this.typeAttributes = typeAttributes; } /** * @summary Restructures an object into a PKCS15Object * @description * * This takes an `object` and converts it to a `PKCS15Object`. * * @public * @static * @method * @param {Object} _o An object having all of the keys and values of a `PKCS15Object`. * @returns {PKCS15Object} */ static _from_object(_o) { return new PKCS15Object(_o.commonObjectAttributes, _o.classAttributes, _o.subClassAttributes, _o.typeAttributes); } } /** * @summary The Leading Root Component Types of PKCS15Object * @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_PKCS15Object = [ new $.ComponentSpec("commonObjectAttributes", false, $.hasTag(_TagClass.universal, 16)), new $.ComponentSpec("classAttributes", false, $.hasAnyTag), new $.ComponentSpec("subClassAttributes", true, $.hasTag(_TagClass.context, 0)), new $.ComponentSpec("typeAttributes", false, $.hasTag(_TagClass.context, 1)), ]; /** * @summary The Trailing Root Component Types of PKCS15Object * @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_PKCS15Object = []; /** * @summary The Extension Addition Component Types of PKCS15Object * @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_PKCS15Object = []; /** * @summary Returns a function that will decode an ASN.1 element into a(n) PKCS15Object * @function * @param {_Element} el The element being decoded. * @returns A function that will decode an ASN.1 element. */ export function _get_decoder_for_PKCS15Object(_decode_ClassAttributes, _decode_SubClassAttributes, _decode_TypeAttributes) { return function (el) { let commonObjectAttributes; let classAttributes; let subClassAttributes; let typeAttributes; const callbacks = { commonObjectAttributes: (_el) => { commonObjectAttributes = _decode_CommonObjectAttributes(_el); }, classAttributes: (_el) => { classAttributes = _decode_ClassAttributes(_el); }, subClassAttributes: (_el) => { subClassAttributes = $._decode_implicit(() => _decode_SubClassAttributes)(_el); }, typeAttributes: (_el) => { typeAttributes = $._decode_implicit(() => _decode_TypeAttributes)(_el); }, }; $._parse_sequence(el, callbacks, _root_component_type_list_1_spec_for_PKCS15Object, _extension_additions_list_spec_for_PKCS15Object, _root_component_type_list_2_spec_for_PKCS15Object, undefined); return new PKCS15Object(commonObjectAttributes, classAttributes, subClassAttributes, typeAttributes); }; } /** * @summary Returns a function that will encode a(n) PKCS15Object into an ASN.1 Element. * @function * @returns A function that will encode a(n) PKCS15Object as an ASN.1 element. */ export function _get_encoder_for_PKCS15Object(_encode_ClassAttributes, _encode_SubClassAttributes, _encode_TypeAttributes) { return function (value, _elGetter) { return $._encodeSequence([] .concat([ /* REQUIRED */ _encode_CommonObjectAttributes(value.commonObjectAttributes, $.BER), /* REQUIRED */ _encode_ClassAttributes(value.classAttributes, $.BER), /* IF_ABSENT */ value.subClassAttributes === undefined ? undefined : $._encode_implicit(_TagClass.context, 0, () => _encode_SubClassAttributes, $.BER)(value.subClassAttributes, $.BER), /* REQUIRED */ $._encode_implicit(_TagClass.context, 1, () => _encode_TypeAttributes, $.BER)(value.typeAttributes, $.BER), ]) .filter((c) => !!c), $.BER); }; } /* eslint-enable */