@wildboar/pkcs
Version:
Public Key Cryptography Standard PDUs in TypeScript
224 lines • 9.48 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports._encode_OneAsymmetricKey = exports._decode_OneAsymmetricKey = exports._extension_additions_list_spec_for_OneAsymmetricKey = exports._root_component_type_list_2_spec_for_OneAsymmetricKey = exports._root_component_type_list_1_spec_for_OneAsymmetricKey = exports.OneAsymmetricKey = void 0;
/* eslint-disable */
const asn1_ts_1 = require("asn1-ts");
const $ = require("asn1-ts/dist/node/functional");
const Attributes_ta_1 = require("../AsymmetricKeyPackageModuleV1/Attributes.ta");
const PrivateKey_ta_1 = require("../AsymmetricKeyPackageModuleV1/PrivateKey.ta");
const PrivateKeyAlgorithmIdentifier_ta_1 = require("../AsymmetricKeyPackageModuleV1/PrivateKeyAlgorithmIdentifier.ta");
const Version_ta_1 = require("../AsymmetricKeyPackageModuleV1/Version.ta");
const PublicKey_ta_1 = require("../AsymmetricKeyPackageModuleV1/PublicKey.ta");
/* START_OF_SYMBOL_DEFINITION OneAsymmetricKey */
/**
* @summary OneAsymmetricKey
* @description
*
* ### ASN.1 Definition:
*
* ```asn1
* OneAsymmetricKey ::= SEQUENCE {
* version Version,
* privateKeyAlgorithm PrivateKeyAlgorithmIdentifier,
* privateKey PrivateKey,
* attributes [0] Attributes OPTIONAL,
* ...,
* [[2: publicKey [1] PublicKey OPTIONAL ]],
* ...
* }
* ```
*
* @class
*/
class OneAsymmetricKey {
constructor(
/**
* @summary `version`.
* @public
* @readonly
*/
version,
/**
* @summary `privateKeyAlgorithm`.
* @public
* @readonly
*/
privateKeyAlgorithm,
/**
* @summary `privateKey`.
* @public
* @readonly
*/
privateKey,
/**
* @summary `attributes`.
* @public
* @readonly
*/
attributes,
/**
* @summary `publicKey`.
* @public
* @readonly
*/
publicKey,
/**
* @summary Extensions that are not recognized.
* @public
* @readonly
*/
_unrecognizedExtensionsList = []) {
this.version = version;
this.privateKeyAlgorithm = privateKeyAlgorithm;
this.privateKey = privateKey;
this.attributes = attributes;
this.publicKey = publicKey;
this._unrecognizedExtensionsList = _unrecognizedExtensionsList;
}
/**
* @summary Restructures an object into a OneAsymmetricKey
* @description
*
* This takes an `object` and converts it to a `OneAsymmetricKey`.
*
* @public
* @static
* @method
* @param {Object} _o An object having all of the keys and values of a `OneAsymmetricKey`.
* @returns {OneAsymmetricKey}
*/
static _from_object(_o) {
return new OneAsymmetricKey(_o.version, _o.privateKeyAlgorithm, _o.privateKey, _o.attributes, _o.publicKey, _o._unrecognizedExtensionsList);
}
}
exports.OneAsymmetricKey = OneAsymmetricKey;
/* END_OF_SYMBOL_DEFINITION OneAsymmetricKey */
/* START_OF_SYMBOL_DEFINITION _root_component_type_list_1_spec_for_OneAsymmetricKey */
/**
* @summary The Leading Root Component Types of OneAsymmetricKey
* @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_OneAsymmetricKey = [
new $.ComponentSpec("version", false, $.hasTag(asn1_ts_1.ASN1TagClass.universal, 2), undefined, undefined),
new $.ComponentSpec("privateKeyAlgorithm", false, $.hasTag(asn1_ts_1.ASN1TagClass.universal, 16), undefined, undefined),
new $.ComponentSpec("privateKey", false, $.hasTag(asn1_ts_1.ASN1TagClass.universal, 4), undefined, undefined),
new $.ComponentSpec("attributes", true, $.hasTag(asn1_ts_1.ASN1TagClass.context, 0), undefined, undefined),
];
/* END_OF_SYMBOL_DEFINITION _root_component_type_list_1_spec_for_OneAsymmetricKey */
/* START_OF_SYMBOL_DEFINITION _root_component_type_list_2_spec_for_OneAsymmetricKey */
/**
* @summary The Trailing Root Component Types of OneAsymmetricKey
* @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_OneAsymmetricKey = [];
/* END_OF_SYMBOL_DEFINITION _root_component_type_list_2_spec_for_OneAsymmetricKey */
/* START_OF_SYMBOL_DEFINITION _extension_additions_list_spec_for_OneAsymmetricKey */
/**
* @summary The Extension Addition Component Types of OneAsymmetricKey
* @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_OneAsymmetricKey = [
new $.ComponentSpec("publicKey", true, $.hasTag(asn1_ts_1.ASN1TagClass.context, 1), 0, 2),
];
/* END_OF_SYMBOL_DEFINITION _extension_additions_list_spec_for_OneAsymmetricKey */
/* START_OF_SYMBOL_DEFINITION _cached_decoder_for_OneAsymmetricKey */
let _cached_decoder_for_OneAsymmetricKey = null;
/* END_OF_SYMBOL_DEFINITION _cached_decoder_for_OneAsymmetricKey */
/* START_OF_SYMBOL_DEFINITION _decode_OneAsymmetricKey */
/**
* @summary Decodes an ASN.1 element into a(n) OneAsymmetricKey
* @function
* @param {_Element} el The element being decoded.
* @returns {OneAsymmetricKey} The decoded data structure.
*/
function _decode_OneAsymmetricKey(el) {
if (!_cached_decoder_for_OneAsymmetricKey) {
_cached_decoder_for_OneAsymmetricKey = function (el) {
/* START_OF_SEQUENCE_COMPONENT_DECLARATIONS */
let version;
let privateKeyAlgorithm;
let privateKey;
let attributes;
let publicKey;
let _unrecognizedExtensionsList = [];
/* END_OF_SEQUENCE_COMPONENT_DECLARATIONS */
/* START_OF_CALLBACKS_MAP */
const callbacks = {
version: (_el) => {
version = Version_ta_1._decode_Version(_el);
},
privateKeyAlgorithm: (_el) => {
privateKeyAlgorithm = PrivateKeyAlgorithmIdentifier_ta_1._decode_PrivateKeyAlgorithmIdentifier(_el);
},
privateKey: (_el) => {
privateKey = PrivateKey_ta_1._decode_PrivateKey(_el);
},
attributes: (_el) => {
attributes = $._decode_implicit(() => Attributes_ta_1._decode_Attributes)(_el);
},
publicKey: (_el) => {
publicKey = $._decode_implicit(() => PublicKey_ta_1._decode_PublicKey)(_el);
},
};
/* END_OF_CALLBACKS_MAP */
$._parse_sequence(el, callbacks, exports._root_component_type_list_1_spec_for_OneAsymmetricKey, exports._extension_additions_list_spec_for_OneAsymmetricKey, exports._root_component_type_list_2_spec_for_OneAsymmetricKey, (ext) => {
_unrecognizedExtensionsList.push(ext);
});
return new OneAsymmetricKey(
/* SEQUENCE_CONSTRUCTOR_CALL */ version, privateKeyAlgorithm, privateKey, attributes, publicKey, _unrecognizedExtensionsList);
};
}
return _cached_decoder_for_OneAsymmetricKey(el);
}
exports._decode_OneAsymmetricKey = _decode_OneAsymmetricKey;
/* END_OF_SYMBOL_DEFINITION _decode_OneAsymmetricKey */
/* START_OF_SYMBOL_DEFINITION _cached_encoder_for_OneAsymmetricKey */
let _cached_encoder_for_OneAsymmetricKey = null;
/* END_OF_SYMBOL_DEFINITION _cached_encoder_for_OneAsymmetricKey */
/* START_OF_SYMBOL_DEFINITION _encode_OneAsymmetricKey */
/**
* @summary Encodes a(n) OneAsymmetricKey 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 OneAsymmetricKey, encoded as an ASN.1 Element.
*/
function _encode_OneAsymmetricKey(value, elGetter) {
if (!_cached_encoder_for_OneAsymmetricKey) {
_cached_encoder_for_OneAsymmetricKey = function (value, elGetter) {
return $._encodeSequence([]
.concat([
/* REQUIRED */ Version_ta_1._encode_Version(value.version, $.BER),
/* REQUIRED */ PrivateKeyAlgorithmIdentifier_ta_1._encode_PrivateKeyAlgorithmIdentifier(value.privateKeyAlgorithm, $.BER),
/* REQUIRED */ PrivateKey_ta_1._encode_PrivateKey(value.privateKey, $.BER),
/* IF_ABSENT */ value.attributes === undefined
? undefined
: $._encode_implicit(asn1_ts_1.ASN1TagClass.context, 0, () => Attributes_ta_1._encode_Attributes, $.BER)(value.attributes, $.BER),
], [
/* IF_ABSENT */ value.publicKey === undefined
? undefined
: $._encode_implicit(asn1_ts_1.ASN1TagClass.context, 1, () => PublicKey_ta_1._encode_PublicKey, $.BER)(value.publicKey, $.BER),
], value._unrecognizedExtensionsList
? value._unrecognizedExtensionsList
: [])
.filter((c) => !!c), $.BER);
};
}
return _cached_encoder_for_OneAsymmetricKey(value, elGetter);
}
exports._encode_OneAsymmetricKey = _encode_OneAsymmetricKey;
/* END_OF_SYMBOL_DEFINITION _encode_OneAsymmetricKey */
/* eslint-enable */
//# sourceMappingURL=OneAsymmetricKey.ta.js.map