@wildboar/pkcs
Version:
Public Key Cryptography Standard PDUs in TypeScript
306 lines • 18.3 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports._encode_CommonKeyAttributes = exports._decode_CommonKeyAttributes = exports._extension_additions_list_spec_for_CommonKeyAttributes = exports._root_component_type_list_2_spec_for_CommonKeyAttributes = exports._root_component_type_list_1_spec_for_CommonKeyAttributes = exports.CommonKeyAttributes = exports._encode_Reference = exports._decode_Reference = exports._encode_KeyUsageFlags = exports._decode_KeyUsageFlags = exports.wrap = exports.verifyRecover = exports.verify = exports.unwrap = exports.signRecover = exports.sign = exports.nonRepudiation = exports.KeyUsageFlags_wrap = exports.KeyUsageFlags_verifyRecover = exports.KeyUsageFlags_verify = exports.KeyUsageFlags_unwrap = exports.KeyUsageFlags_signRecover = exports.KeyUsageFlags_sign = exports.KeyUsageFlags_nonRepudiation = exports.KeyUsageFlags_encrypt = exports.KeyUsageFlags_derive = exports.KeyUsageFlags_decrypt = exports.encrypt = exports.derive = exports.decrypt = exports._encode_KeyAccessFlags = exports._decode_KeyAccessFlags = exports.sensitive = exports.neverExtractable = exports.local = exports.KeyAccessFlags_sensitive = exports.KeyAccessFlags_neverExtractable = exports.KeyAccessFlags_local = exports.KeyAccessFlags_extractable = exports.KeyAccessFlags_alwaysSensitive = exports.extractable = exports.alwaysSensitive = exports._encode_Identifier = exports._decode_Identifier = void 0;
/* eslint-disable */
const asn1_ts_1 = require("asn1-ts");
const $ = require("asn1-ts/dist/node/functional");
const Identifier_ta_1 = require("../PKCS-15/Identifier.ta");
const KeyAccessFlags_ta_1 = require("../PKCS-15/KeyAccessFlags.ta");
const KeyUsageFlags_ta_1 = require("../PKCS-15/KeyUsageFlags.ta");
const Reference_ta_1 = require("../PKCS-15/Reference.ta");
var Identifier_ta_2 = require("../PKCS-15/Identifier.ta");
Object.defineProperty(exports, "_decode_Identifier", { enumerable: true, get: function () { return Identifier_ta_2._decode_Identifier; } });
Object.defineProperty(exports, "_encode_Identifier", { enumerable: true, get: function () { return Identifier_ta_2._encode_Identifier; } });
var KeyAccessFlags_ta_2 = require("../PKCS-15/KeyAccessFlags.ta");
Object.defineProperty(exports, "alwaysSensitive", { enumerable: true, get: function () { return KeyAccessFlags_ta_2.alwaysSensitive; } }); /* IMPORTED_SHORT_NAMED_BIT */
Object.defineProperty(exports, "extractable", { enumerable: true, get: function () { return KeyAccessFlags_ta_2.extractable; } }); /* IMPORTED_SHORT_NAMED_BIT */
Object.defineProperty(exports, "KeyAccessFlags_alwaysSensitive", { enumerable: true, get: function () { return KeyAccessFlags_ta_2.KeyAccessFlags_alwaysSensitive; } }); /* IMPORTED_LONG_NAMED_BIT */
Object.defineProperty(exports, "KeyAccessFlags_extractable", { enumerable: true, get: function () { return KeyAccessFlags_ta_2.KeyAccessFlags_extractable; } }); /* IMPORTED_LONG_NAMED_BIT */
Object.defineProperty(exports, "KeyAccessFlags_local", { enumerable: true, get: function () { return KeyAccessFlags_ta_2.KeyAccessFlags_local; } }); /* IMPORTED_LONG_NAMED_BIT */
Object.defineProperty(exports, "KeyAccessFlags_neverExtractable", { enumerable: true, get: function () { return KeyAccessFlags_ta_2.KeyAccessFlags_neverExtractable; } }); /* IMPORTED_LONG_NAMED_BIT */
Object.defineProperty(exports, "KeyAccessFlags_sensitive", { enumerable: true, get: function () { return KeyAccessFlags_ta_2.KeyAccessFlags_sensitive; } }); /* IMPORTED_LONG_NAMED_BIT */
Object.defineProperty(exports, "local", { enumerable: true, get: function () { return KeyAccessFlags_ta_2.local; } }); /* IMPORTED_SHORT_NAMED_BIT */
Object.defineProperty(exports, "neverExtractable", { enumerable: true, get: function () { return KeyAccessFlags_ta_2.neverExtractable; } }); /* IMPORTED_SHORT_NAMED_BIT */
Object.defineProperty(exports, "sensitive", { enumerable: true, get: function () { return KeyAccessFlags_ta_2.sensitive; } }); /* IMPORTED_SHORT_NAMED_BIT */
Object.defineProperty(exports, "_decode_KeyAccessFlags", { enumerable: true, get: function () { return KeyAccessFlags_ta_2._decode_KeyAccessFlags; } });
Object.defineProperty(exports, "_encode_KeyAccessFlags", { enumerable: true, get: function () { return KeyAccessFlags_ta_2._encode_KeyAccessFlags; } });
var KeyUsageFlags_ta_2 = require("../PKCS-15/KeyUsageFlags.ta");
Object.defineProperty(exports, "decrypt", { enumerable: true, get: function () { return KeyUsageFlags_ta_2.decrypt; } }); /* IMPORTED_SHORT_NAMED_BIT */
Object.defineProperty(exports, "derive", { enumerable: true, get: function () { return KeyUsageFlags_ta_2.derive; } }); /* IMPORTED_SHORT_NAMED_BIT */
Object.defineProperty(exports, "encrypt", { enumerable: true, get: function () { return KeyUsageFlags_ta_2.encrypt; } }); /* IMPORTED_SHORT_NAMED_BIT */
Object.defineProperty(exports, "KeyUsageFlags_decrypt", { enumerable: true, get: function () { return KeyUsageFlags_ta_2.KeyUsageFlags_decrypt; } }); /* IMPORTED_LONG_NAMED_BIT */
Object.defineProperty(exports, "KeyUsageFlags_derive", { enumerable: true, get: function () { return KeyUsageFlags_ta_2.KeyUsageFlags_derive; } }); /* IMPORTED_LONG_NAMED_BIT */
Object.defineProperty(exports, "KeyUsageFlags_encrypt", { enumerable: true, get: function () { return KeyUsageFlags_ta_2.KeyUsageFlags_encrypt; } }); /* IMPORTED_LONG_NAMED_BIT */
Object.defineProperty(exports, "KeyUsageFlags_nonRepudiation", { enumerable: true, get: function () { return KeyUsageFlags_ta_2.KeyUsageFlags_nonRepudiation; } }); /* IMPORTED_LONG_NAMED_BIT */
Object.defineProperty(exports, "KeyUsageFlags_sign", { enumerable: true, get: function () { return KeyUsageFlags_ta_2.KeyUsageFlags_sign; } }); /* IMPORTED_LONG_NAMED_BIT */
Object.defineProperty(exports, "KeyUsageFlags_signRecover", { enumerable: true, get: function () { return KeyUsageFlags_ta_2.KeyUsageFlags_signRecover; } }); /* IMPORTED_LONG_NAMED_BIT */
Object.defineProperty(exports, "KeyUsageFlags_unwrap", { enumerable: true, get: function () { return KeyUsageFlags_ta_2.KeyUsageFlags_unwrap; } }); /* IMPORTED_LONG_NAMED_BIT */
Object.defineProperty(exports, "KeyUsageFlags_verify", { enumerable: true, get: function () { return KeyUsageFlags_ta_2.KeyUsageFlags_verify; } }); /* IMPORTED_LONG_NAMED_BIT */
Object.defineProperty(exports, "KeyUsageFlags_verifyRecover", { enumerable: true, get: function () { return KeyUsageFlags_ta_2.KeyUsageFlags_verifyRecover; } }); /* IMPORTED_LONG_NAMED_BIT */
Object.defineProperty(exports, "KeyUsageFlags_wrap", { enumerable: true, get: function () { return KeyUsageFlags_ta_2.KeyUsageFlags_wrap; } }); /* IMPORTED_LONG_NAMED_BIT */
Object.defineProperty(exports, "nonRepudiation", { enumerable: true, get: function () { return KeyUsageFlags_ta_2.nonRepudiation; } }); /* IMPORTED_SHORT_NAMED_BIT */
Object.defineProperty(exports, "sign", { enumerable: true, get: function () { return KeyUsageFlags_ta_2.sign; } }); /* IMPORTED_SHORT_NAMED_BIT */
Object.defineProperty(exports, "signRecover", { enumerable: true, get: function () { return KeyUsageFlags_ta_2.signRecover; } }); /* IMPORTED_SHORT_NAMED_BIT */
Object.defineProperty(exports, "unwrap", { enumerable: true, get: function () { return KeyUsageFlags_ta_2.unwrap; } }); /* IMPORTED_SHORT_NAMED_BIT */
Object.defineProperty(exports, "verify", { enumerable: true, get: function () { return KeyUsageFlags_ta_2.verify; } }); /* IMPORTED_SHORT_NAMED_BIT */
Object.defineProperty(exports, "verifyRecover", { enumerable: true, get: function () { return KeyUsageFlags_ta_2.verifyRecover; } }); /* IMPORTED_SHORT_NAMED_BIT */
Object.defineProperty(exports, "wrap", { enumerable: true, get: function () { return KeyUsageFlags_ta_2.wrap; } }); /* IMPORTED_SHORT_NAMED_BIT */
Object.defineProperty(exports, "_decode_KeyUsageFlags", { enumerable: true, get: function () { return KeyUsageFlags_ta_2._decode_KeyUsageFlags; } });
Object.defineProperty(exports, "_encode_KeyUsageFlags", { enumerable: true, get: function () { return KeyUsageFlags_ta_2._encode_KeyUsageFlags; } });
var Reference_ta_2 = require("../PKCS-15/Reference.ta");
Object.defineProperty(exports, "_decode_Reference", { enumerable: true, get: function () { return Reference_ta_2._decode_Reference; } });
Object.defineProperty(exports, "_encode_Reference", { enumerable: true, get: function () { return Reference_ta_2._encode_Reference; } });
/* START_OF_SYMBOL_DEFINITION CommonKeyAttributes */
/**
* @summary CommonKeyAttributes
* @description
*
* ### ASN.1 Definition:
*
* ```asn1
* CommonKeyAttributes ::= SEQUENCE {
* iD Identifier,
* usage KeyUsageFlags,
* native BOOLEAN DEFAULT TRUE,
* accessFlags KeyAccessFlags OPTIONAL,
* keyReference Reference OPTIONAL,
* startDate GeneralizedTime OPTIONAL,
* endDate [0] GeneralizedTime OPTIONAL,
* ... -- For future extensions
* }
* ```
*
* @class
*/
class CommonKeyAttributes {
constructor(
/**
* @summary `iD`.
* @public
* @readonly
*/
iD,
/**
* @summary `usage`.
* @public
* @readonly
*/
usage,
/**
* @summary `native`.
* @public
* @readonly
*/
native,
/**
* @summary `accessFlags`.
* @public
* @readonly
*/
accessFlags,
/**
* @summary `keyReference`.
* @public
* @readonly
*/
keyReference,
/**
* @summary `startDate`.
* @public
* @readonly
*/
startDate,
/**
* @summary `endDate`.
* @public
* @readonly
*/
endDate,
/**
* @summary Extensions that are not recognized.
* @public
* @readonly
*/
_unrecognizedExtensionsList = []) {
this.iD = iD;
this.usage = usage;
this.native = native;
this.accessFlags = accessFlags;
this.keyReference = keyReference;
this.startDate = startDate;
this.endDate = endDate;
this._unrecognizedExtensionsList = _unrecognizedExtensionsList;
}
/**
* @summary Restructures an object into a CommonKeyAttributes
* @description
*
* This takes an `object` and converts it to a `CommonKeyAttributes`.
*
* @public
* @static
* @method
* @param {Object} _o An object having all of the keys and values of a `CommonKeyAttributes`.
* @returns {CommonKeyAttributes}
*/
static _from_object(_o) {
return new CommonKeyAttributes(_o.iD, _o.usage, _o.native, _o.accessFlags, _o.keyReference, _o.startDate, _o.endDate, _o._unrecognizedExtensionsList);
}
/**
* @summary Getter that returns the default value for `native`.
* @public
* @static
* @method
*/
static get _default_value_for_native() {
return false;
}
}
exports.CommonKeyAttributes = CommonKeyAttributes;
/* END_OF_SYMBOL_DEFINITION CommonKeyAttributes */
/* START_OF_SYMBOL_DEFINITION _root_component_type_list_1_spec_for_CommonKeyAttributes */
/**
* @summary The Leading Root Component Types of CommonKeyAttributes
* @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_CommonKeyAttributes = [
new $.ComponentSpec("iD", false, $.hasTag(asn1_ts_1.ASN1TagClass.universal, 4), undefined, undefined),
new $.ComponentSpec("usage", false, $.hasTag(asn1_ts_1.ASN1TagClass.universal, 3), undefined, undefined),
new $.ComponentSpec("native", true, $.hasTag(asn1_ts_1.ASN1TagClass.universal, 1), undefined, undefined),
new $.ComponentSpec("accessFlags", true, $.hasTag(asn1_ts_1.ASN1TagClass.universal, 3), undefined, undefined),
new $.ComponentSpec("keyReference", true, $.hasTag(asn1_ts_1.ASN1TagClass.universal, 2), undefined, undefined),
new $.ComponentSpec("startDate", true, $.hasTag(asn1_ts_1.ASN1TagClass.universal, 24), undefined, undefined),
new $.ComponentSpec("endDate", true, $.hasTag(asn1_ts_1.ASN1TagClass.context, 0), undefined, undefined),
];
/* END_OF_SYMBOL_DEFINITION _root_component_type_list_1_spec_for_CommonKeyAttributes */
/* START_OF_SYMBOL_DEFINITION _root_component_type_list_2_spec_for_CommonKeyAttributes */
/**
* @summary The Trailing Root Component Types of CommonKeyAttributes
* @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_CommonKeyAttributes = [];
/* END_OF_SYMBOL_DEFINITION _root_component_type_list_2_spec_for_CommonKeyAttributes */
/* START_OF_SYMBOL_DEFINITION _extension_additions_list_spec_for_CommonKeyAttributes */
/**
* @summary The Extension Addition Component Types of CommonKeyAttributes
* @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_CommonKeyAttributes = [];
/* END_OF_SYMBOL_DEFINITION _extension_additions_list_spec_for_CommonKeyAttributes */
/* START_OF_SYMBOL_DEFINITION _cached_decoder_for_CommonKeyAttributes */
let _cached_decoder_for_CommonKeyAttributes = null;
/* END_OF_SYMBOL_DEFINITION _cached_decoder_for_CommonKeyAttributes */
/* START_OF_SYMBOL_DEFINITION _decode_CommonKeyAttributes */
/**
* @summary Decodes an ASN.1 element into a(n) CommonKeyAttributes
* @function
* @param {_Element} el The element being decoded.
* @returns {CommonKeyAttributes} The decoded data structure.
*/
function _decode_CommonKeyAttributes(el) {
if (!_cached_decoder_for_CommonKeyAttributes) {
_cached_decoder_for_CommonKeyAttributes = function (el) {
/* START_OF_SEQUENCE_COMPONENT_DECLARATIONS */
let iD;
let usage;
let native = CommonKeyAttributes._default_value_for_native;
let accessFlags;
let keyReference;
let startDate;
let endDate;
let _unrecognizedExtensionsList = [];
/* END_OF_SEQUENCE_COMPONENT_DECLARATIONS */
/* START_OF_CALLBACKS_MAP */
const callbacks = {
iD: (_el) => {
iD = Identifier_ta_1._decode_Identifier(_el);
},
usage: (_el) => {
usage = KeyUsageFlags_ta_1._decode_KeyUsageFlags(_el);
},
native: (_el) => {
native = $._decodeBoolean(_el);
},
accessFlags: (_el) => {
accessFlags = KeyAccessFlags_ta_1._decode_KeyAccessFlags(_el);
},
keyReference: (_el) => {
keyReference = Reference_ta_1._decode_Reference(_el);
},
startDate: (_el) => {
startDate = $._decodeGeneralizedTime(_el);
},
endDate: (_el) => {
endDate = $._decode_implicit(() => $._decodeGeneralizedTime)(_el);
},
};
/* END_OF_CALLBACKS_MAP */
$._parse_sequence(el, callbacks, exports._root_component_type_list_1_spec_for_CommonKeyAttributes, exports._extension_additions_list_spec_for_CommonKeyAttributes, exports._root_component_type_list_2_spec_for_CommonKeyAttributes, (ext) => {
_unrecognizedExtensionsList.push(ext);
});
return new CommonKeyAttributes(
/* SEQUENCE_CONSTRUCTOR_CALL */ iD, usage, native, accessFlags, keyReference, startDate, endDate, _unrecognizedExtensionsList);
};
}
return _cached_decoder_for_CommonKeyAttributes(el);
}
exports._decode_CommonKeyAttributes = _decode_CommonKeyAttributes;
/* END_OF_SYMBOL_DEFINITION _decode_CommonKeyAttributes */
/* START_OF_SYMBOL_DEFINITION _cached_encoder_for_CommonKeyAttributes */
let _cached_encoder_for_CommonKeyAttributes = null;
/* END_OF_SYMBOL_DEFINITION _cached_encoder_for_CommonKeyAttributes */
/* START_OF_SYMBOL_DEFINITION _encode_CommonKeyAttributes */
/**
* @summary Encodes a(n) CommonKeyAttributes 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 CommonKeyAttributes, encoded as an ASN.1 Element.
*/
function _encode_CommonKeyAttributes(value, elGetter) {
if (!_cached_encoder_for_CommonKeyAttributes) {
_cached_encoder_for_CommonKeyAttributes = function (value, elGetter) {
return $._encodeSequence([]
.concat([
/* REQUIRED */ Identifier_ta_1._encode_Identifier(value.iD, $.BER),
/* REQUIRED */ KeyUsageFlags_ta_1._encode_KeyUsageFlags(value.usage, $.BER),
/* IF_DEFAULT */ value.native === undefined ||
$.deepEq(value.native, CommonKeyAttributes._default_value_for_native)
? undefined
: $._encodeBoolean(value.native, $.BER),
/* IF_ABSENT */ value.accessFlags === undefined
? undefined
: KeyAccessFlags_ta_1._encode_KeyAccessFlags(value.accessFlags, $.BER),
/* IF_ABSENT */ value.keyReference === undefined
? undefined
: Reference_ta_1._encode_Reference(value.keyReference, $.BER),
/* IF_ABSENT */ value.startDate === undefined
? undefined
: $._encodeGeneralizedTime(value.startDate, $.BER),
/* IF_ABSENT */ value.endDate === undefined
? undefined
: $._encode_implicit(asn1_ts_1.ASN1TagClass.context, 0, () => $._encodeGeneralizedTime, $.BER)(value.endDate, $.BER),
], value._unrecognizedExtensionsList
? value._unrecognizedExtensionsList
: [])
.filter((c) => !!c), $.BER);
};
}
return _cached_encoder_for_CommonKeyAttributes(value, elGetter);
}
exports._encode_CommonKeyAttributes = _encode_CommonKeyAttributes;
/* END_OF_SYMBOL_DEFINITION _encode_CommonKeyAttributes */
/* eslint-enable */
//# sourceMappingURL=CommonKeyAttributes.ta.js.map