UNPKG

@wildboar/pkcs

Version:
166 lines (165 loc) 6.17 kB
/* eslint-disable */ import { ASN1TagClass as _TagClass, } from "@wildboar/asn1"; import * as $ from "@wildboar/asn1/functional"; import { _get_decoder_for_KeyInfo, _get_encoder_for_KeyInfo, } from "../PKCS-15/KeyInfo.ta.mjs"; import { _get_decoder_for_ObjectValue, _get_encoder_for_ObjectValue, } from "../PKCS-15/ObjectValue.ta.mjs"; import { _decode_PublicKeyOperations, _encode_PublicKeyOperations, } from "../PKCS-15/PublicKeyOperations.ta.mjs"; import { _decode_RSAPublicKeyChoice, _encode_RSAPublicKeyChoice, } from "../PKCS-15/RSAPublicKeyChoice.ta.mjs"; /** * @summary PublicRSAKeyAttributes * @description * * ### ASN.1 Definition: * * ```asn1 * PublicRSAKeyAttributes ::= SEQUENCE { * value ObjectValue {RSAPublicKeyChoice}, * modulusLength INTEGER, -- modulus length in bits, e.g. 1024 * keyInfo KeyInfo {NULL, PublicKeyOperations} OPTIONAL, * ... -- For future extensions * } * ``` * */ export class PublicRSAKeyAttributes { value; modulusLength; keyInfo; _unrecognizedExtensionsList; constructor( /** * @summary `value`. * @public * @readonly */ value, /** * @summary `modulusLength`. * @public * @readonly */ modulusLength, /** * @summary `keyInfo`. * @public * @readonly */ keyInfo, /** * @summary Extensions that are not recognized. * @public * @readonly */ _unrecognizedExtensionsList = []) { this.value = value; this.modulusLength = modulusLength; this.keyInfo = keyInfo; this._unrecognizedExtensionsList = _unrecognizedExtensionsList; } /** * @summary Restructures an object into a PublicRSAKeyAttributes * @description * * This takes an `object` and converts it to a `PublicRSAKeyAttributes`. * * @public * @static * @method * @param {Object} _o An object having all of the keys and values of a `PublicRSAKeyAttributes`. * @returns {PublicRSAKeyAttributes} */ static _from_object(_o) { return new PublicRSAKeyAttributes(_o.value, _o.modulusLength, _o.keyInfo, _o._unrecognizedExtensionsList); } } /** * @summary The Leading Root Component Types of PublicRSAKeyAttributes * @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_PublicRSAKeyAttributes = [ new $.ComponentSpec("value", false, $.hasAnyTag), new $.ComponentSpec("modulusLength", false, $.hasTag(_TagClass.universal, 2)), new $.ComponentSpec("keyInfo", true, $.hasAnyTag), ]; /** * @summary The Trailing Root Component Types of PublicRSAKeyAttributes * @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_PublicRSAKeyAttributes = []; /** * @summary The Extension Addition Component Types of PublicRSAKeyAttributes * @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_PublicRSAKeyAttributes = []; let _cached_decoder_for_PublicRSAKeyAttributes = null; /** * @summary Decodes an ASN.1 element into a(n) PublicRSAKeyAttributes * @function * @param {_Element} el The element being decoded. * @returns {PublicRSAKeyAttributes} The decoded data structure. */ export function _decode_PublicRSAKeyAttributes(el) { if (!_cached_decoder_for_PublicRSAKeyAttributes) { _cached_decoder_for_PublicRSAKeyAttributes = function (el) { let value; let modulusLength; let keyInfo; let _unrecognizedExtensionsList = []; const callbacks = { value: (_el) => { value = _get_decoder_for_ObjectValue(_decode_RSAPublicKeyChoice)(_el); }, modulusLength: (_el) => { modulusLength = $._decodeInteger(_el); }, keyInfo: (_el) => { keyInfo = _get_decoder_for_KeyInfo($._decodeNull, _decode_PublicKeyOperations)(_el); }, }; $._parse_sequence(el, callbacks, _root_component_type_list_1_spec_for_PublicRSAKeyAttributes, _extension_additions_list_spec_for_PublicRSAKeyAttributes, _root_component_type_list_2_spec_for_PublicRSAKeyAttributes, (ext) => { _unrecognizedExtensionsList.push(ext); }); return new PublicRSAKeyAttributes(value, modulusLength, keyInfo, _unrecognizedExtensionsList); }; } return _cached_decoder_for_PublicRSAKeyAttributes(el); } let _cached_encoder_for_PublicRSAKeyAttributes = null; /** * @summary Encodes a(n) PublicRSAKeyAttributes 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 PublicRSAKeyAttributes, encoded as an ASN.1 Element. */ export function _encode_PublicRSAKeyAttributes(value, elGetter) { if (!_cached_encoder_for_PublicRSAKeyAttributes) { _cached_encoder_for_PublicRSAKeyAttributes = function (value) { return $._encodeSequence([] .concat([ /* REQUIRED */ _get_encoder_for_ObjectValue(_encode_RSAPublicKeyChoice)(value.value, $.BER), /* REQUIRED */ $._encodeInteger(value.modulusLength, $.BER), /* IF_ABSENT */ value.keyInfo === undefined ? undefined : _get_encoder_for_KeyInfo($._encodeNull, _encode_PublicKeyOperations)(value.keyInfo, $.BER), ], value._unrecognizedExtensionsList ? value._unrecognizedExtensionsList : []) .filter((c) => !!c), $.BER); }; } return _cached_encoder_for_PublicRSAKeyAttributes(value, elGetter); } /* eslint-enable */