@wildboar/pkcs
Version:
Public Key Cryptography Standard PDUs in TypeScript
313 lines • 19.7 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports._encode_AuthenticatedData = exports._decode_AuthenticatedData = exports._extension_additions_list_spec_for_AuthenticatedData = exports._root_component_type_list_2_spec_for_AuthenticatedData = exports._root_component_type_list_1_spec_for_AuthenticatedData = exports.AuthenticatedData = exports._encode_UnauthAttributes = exports._decode_UnauthAttributes = exports._encode_RecipientInfos = exports._decode_RecipientInfos = exports._encode_OriginatorInfo = exports._decode_OriginatorInfo = exports.OriginatorInfo = exports._encode_MessageAuthenticationCodeAlgorithm = exports._decode_MessageAuthenticationCodeAlgorithm = exports._encode_MessageAuthenticationCode = exports._decode_MessageAuthenticationCode = exports._encode_EncapsulatedContentInfo = exports._decode_EncapsulatedContentInfo = exports.EncapsulatedContentInfo = exports._encode_DigestAlgorithmIdentifier = exports._decode_DigestAlgorithmIdentifier = exports._encode_CMSVersion = exports._decode_CMSVersion = exports.v4 = exports.v3 = exports.v2 = exports.v1 = exports.v0 = exports.CMSVersion_v4 = exports.CMSVersion_v3 = exports.CMSVersion_v2 = exports.CMSVersion_v1 = exports.CMSVersion_v0 = exports._encode_AuthAttributes = exports._decode_AuthAttributes = void 0;
/* eslint-disable */
const asn1_ts_1 = require("asn1-ts");
const $ = require("asn1-ts/dist/node/functional");
const AuthAttributes_ta_1 = require("../CryptographicMessageSyntax/AuthAttributes.ta");
const CMSVersion_ta_1 = require("../CryptographicMessageSyntax/CMSVersion.ta");
const DigestAlgorithmIdentifier_ta_1 = require("../CryptographicMessageSyntax/DigestAlgorithmIdentifier.ta");
const EncapsulatedContentInfo_ta_1 = require("../CryptographicMessageSyntax/EncapsulatedContentInfo.ta");
const MessageAuthenticationCode_ta_1 = require("../CryptographicMessageSyntax/MessageAuthenticationCode.ta");
const MessageAuthenticationCodeAlgorithm_ta_1 = require("../CryptographicMessageSyntax/MessageAuthenticationCodeAlgorithm.ta");
const OriginatorInfo_ta_1 = require("../CryptographicMessageSyntax/OriginatorInfo.ta");
const RecipientInfos_ta_1 = require("../CryptographicMessageSyntax/RecipientInfos.ta");
const UnauthAttributes_ta_1 = require("../CryptographicMessageSyntax/UnauthAttributes.ta");
var AuthAttributes_ta_2 = require("../CryptographicMessageSyntax/AuthAttributes.ta");
Object.defineProperty(exports, "_decode_AuthAttributes", { enumerable: true, get: function () { return AuthAttributes_ta_2._decode_AuthAttributes; } });
Object.defineProperty(exports, "_encode_AuthAttributes", { enumerable: true, get: function () { return AuthAttributes_ta_2._encode_AuthAttributes; } });
var CMSVersion_ta_2 = require("../CryptographicMessageSyntax/CMSVersion.ta");
Object.defineProperty(exports, "CMSVersion_v0", { enumerable: true, get: function () { return CMSVersion_ta_2.CMSVersion_v0; } }); /* IMPORTED_LONG_NAMED_INTEGER */
Object.defineProperty(exports, "CMSVersion_v1", { enumerable: true, get: function () { return CMSVersion_ta_2.CMSVersion_v1; } }); /* IMPORTED_LONG_NAMED_INTEGER */
Object.defineProperty(exports, "CMSVersion_v2", { enumerable: true, get: function () { return CMSVersion_ta_2.CMSVersion_v2; } }); /* IMPORTED_LONG_NAMED_INTEGER */
Object.defineProperty(exports, "CMSVersion_v3", { enumerable: true, get: function () { return CMSVersion_ta_2.CMSVersion_v3; } }); /* IMPORTED_LONG_NAMED_INTEGER */
Object.defineProperty(exports, "CMSVersion_v4", { enumerable: true, get: function () { return CMSVersion_ta_2.CMSVersion_v4; } }); /* IMPORTED_LONG_NAMED_INTEGER */
Object.defineProperty(exports, "v0", { enumerable: true, get: function () { return CMSVersion_ta_2.v0; } }); /* IMPORTED_SHORT_NAMED_INTEGER */
Object.defineProperty(exports, "v1", { enumerable: true, get: function () { return CMSVersion_ta_2.v1; } }); /* IMPORTED_SHORT_NAMED_INTEGER */
Object.defineProperty(exports, "v2", { enumerable: true, get: function () { return CMSVersion_ta_2.v2; } }); /* IMPORTED_SHORT_NAMED_INTEGER */
Object.defineProperty(exports, "v3", { enumerable: true, get: function () { return CMSVersion_ta_2.v3; } }); /* IMPORTED_SHORT_NAMED_INTEGER */
Object.defineProperty(exports, "v4", { enumerable: true, get: function () { return CMSVersion_ta_2.v4; } }); /* IMPORTED_SHORT_NAMED_INTEGER */
Object.defineProperty(exports, "_decode_CMSVersion", { enumerable: true, get: function () { return CMSVersion_ta_2._decode_CMSVersion; } });
Object.defineProperty(exports, "_encode_CMSVersion", { enumerable: true, get: function () { return CMSVersion_ta_2._encode_CMSVersion; } });
var DigestAlgorithmIdentifier_ta_2 = require("../CryptographicMessageSyntax/DigestAlgorithmIdentifier.ta");
Object.defineProperty(exports, "_decode_DigestAlgorithmIdentifier", { enumerable: true, get: function () { return DigestAlgorithmIdentifier_ta_2._decode_DigestAlgorithmIdentifier; } });
Object.defineProperty(exports, "_encode_DigestAlgorithmIdentifier", { enumerable: true, get: function () { return DigestAlgorithmIdentifier_ta_2._encode_DigestAlgorithmIdentifier; } });
var EncapsulatedContentInfo_ta_2 = require("../CryptographicMessageSyntax/EncapsulatedContentInfo.ta");
Object.defineProperty(exports, "EncapsulatedContentInfo", { enumerable: true, get: function () { return EncapsulatedContentInfo_ta_2.EncapsulatedContentInfo; } });
Object.defineProperty(exports, "_decode_EncapsulatedContentInfo", { enumerable: true, get: function () { return EncapsulatedContentInfo_ta_2._decode_EncapsulatedContentInfo; } });
Object.defineProperty(exports, "_encode_EncapsulatedContentInfo", { enumerable: true, get: function () { return EncapsulatedContentInfo_ta_2._encode_EncapsulatedContentInfo; } });
var MessageAuthenticationCode_ta_2 = require("../CryptographicMessageSyntax/MessageAuthenticationCode.ta");
Object.defineProperty(exports, "_decode_MessageAuthenticationCode", { enumerable: true, get: function () { return MessageAuthenticationCode_ta_2._decode_MessageAuthenticationCode; } });
Object.defineProperty(exports, "_encode_MessageAuthenticationCode", { enumerable: true, get: function () { return MessageAuthenticationCode_ta_2._encode_MessageAuthenticationCode; } });
var MessageAuthenticationCodeAlgorithm_ta_2 = require("../CryptographicMessageSyntax/MessageAuthenticationCodeAlgorithm.ta");
Object.defineProperty(exports, "_decode_MessageAuthenticationCodeAlgorithm", { enumerable: true, get: function () { return MessageAuthenticationCodeAlgorithm_ta_2._decode_MessageAuthenticationCodeAlgorithm; } });
Object.defineProperty(exports, "_encode_MessageAuthenticationCodeAlgorithm", { enumerable: true, get: function () { return MessageAuthenticationCodeAlgorithm_ta_2._encode_MessageAuthenticationCodeAlgorithm; } });
var OriginatorInfo_ta_2 = require("../CryptographicMessageSyntax/OriginatorInfo.ta");
Object.defineProperty(exports, "OriginatorInfo", { enumerable: true, get: function () { return OriginatorInfo_ta_2.OriginatorInfo; } });
Object.defineProperty(exports, "_decode_OriginatorInfo", { enumerable: true, get: function () { return OriginatorInfo_ta_2._decode_OriginatorInfo; } });
Object.defineProperty(exports, "_encode_OriginatorInfo", { enumerable: true, get: function () { return OriginatorInfo_ta_2._encode_OriginatorInfo; } });
var RecipientInfos_ta_2 = require("../CryptographicMessageSyntax/RecipientInfos.ta");
Object.defineProperty(exports, "_decode_RecipientInfos", { enumerable: true, get: function () { return RecipientInfos_ta_2._decode_RecipientInfos; } });
Object.defineProperty(exports, "_encode_RecipientInfos", { enumerable: true, get: function () { return RecipientInfos_ta_2._encode_RecipientInfos; } });
var UnauthAttributes_ta_2 = require("../CryptographicMessageSyntax/UnauthAttributes.ta");
Object.defineProperty(exports, "_decode_UnauthAttributes", { enumerable: true, get: function () { return UnauthAttributes_ta_2._decode_UnauthAttributes; } });
Object.defineProperty(exports, "_encode_UnauthAttributes", { enumerable: true, get: function () { return UnauthAttributes_ta_2._encode_UnauthAttributes; } });
/* START_OF_SYMBOL_DEFINITION AuthenticatedData */
/**
* @summary AuthenticatedData
* @description
*
* ### ASN.1 Definition:
*
* ```asn1
* AuthenticatedData ::= SEQUENCE {
* version CMSVersion,
* originatorInfo [0] IMPLICIT OriginatorInfo OPTIONAL,
* recipientInfos RecipientInfos,
* macAlgorithm MessageAuthenticationCodeAlgorithm,
* digestAlgorithm [1] DigestAlgorithmIdentifier OPTIONAL,
* encapContentInfo EncapsulatedContentInfo,
* authenticatedAttributes [2] IMPLICIT AuthAttributes OPTIONAL,
* mac MessageAuthenticationCode,
* unauthenticatedAttributes [3] IMPLICIT UnauthAttributes OPTIONAL
* }
* ```
*
* @class
*/
class AuthenticatedData {
constructor(
/**
* @summary `version`.
* @public
* @readonly
*/
version,
/**
* @summary `originatorInfo`.
* @public
* @readonly
*/
originatorInfo,
/**
* @summary `recipientInfos`.
* @public
* @readonly
*/
recipientInfos,
/**
* @summary `macAlgorithm`.
* @public
* @readonly
*/
macAlgorithm,
/**
* @summary `digestAlgorithm`.
* @public
* @readonly
*/
digestAlgorithm,
/**
* @summary `encapContentInfo`.
* @public
* @readonly
*/
encapContentInfo,
/**
* @summary `authenticatedAttributes`.
* @public
* @readonly
*/
authenticatedAttributes,
/**
* @summary `mac`.
* @public
* @readonly
*/
mac,
/**
* @summary `unauthenticatedAttributes`.
* @public
* @readonly
*/
unauthenticatedAttributes) {
this.version = version;
this.originatorInfo = originatorInfo;
this.recipientInfos = recipientInfos;
this.macAlgorithm = macAlgorithm;
this.digestAlgorithm = digestAlgorithm;
this.encapContentInfo = encapContentInfo;
this.authenticatedAttributes = authenticatedAttributes;
this.mac = mac;
this.unauthenticatedAttributes = unauthenticatedAttributes;
}
/**
* @summary Restructures an object into a AuthenticatedData
* @description
*
* This takes an `object` and converts it to a `AuthenticatedData`.
*
* @public
* @static
* @method
* @param {Object} _o An object having all of the keys and values of a `AuthenticatedData`.
* @returns {AuthenticatedData}
*/
static _from_object(_o) {
return new AuthenticatedData(_o.version, _o.originatorInfo, _o.recipientInfos, _o.macAlgorithm, _o.digestAlgorithm, _o.encapContentInfo, _o.authenticatedAttributes, _o.mac, _o.unauthenticatedAttributes);
}
}
exports.AuthenticatedData = AuthenticatedData;
/* END_OF_SYMBOL_DEFINITION AuthenticatedData */
/* START_OF_SYMBOL_DEFINITION _root_component_type_list_1_spec_for_AuthenticatedData */
/**
* @summary The Leading Root Component Types of AuthenticatedData
* @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_AuthenticatedData = [
new $.ComponentSpec("version", false, $.hasTag(asn1_ts_1.ASN1TagClass.universal, 2), undefined, undefined),
new $.ComponentSpec("originatorInfo", true, $.hasTag(asn1_ts_1.ASN1TagClass.context, 0), undefined, undefined),
new $.ComponentSpec("recipientInfos", false, $.hasTag(asn1_ts_1.ASN1TagClass.universal, 17), undefined, undefined),
new $.ComponentSpec("macAlgorithm", false, $.hasTag(asn1_ts_1.ASN1TagClass.universal, 16), undefined, undefined),
new $.ComponentSpec("digestAlgorithm", true, $.hasTag(asn1_ts_1.ASN1TagClass.context, 1), undefined, undefined),
new $.ComponentSpec("encapContentInfo", false, $.hasTag(asn1_ts_1.ASN1TagClass.universal, 16), undefined, undefined),
new $.ComponentSpec("authenticatedAttributes", true, $.hasTag(asn1_ts_1.ASN1TagClass.context, 2), undefined, undefined),
new $.ComponentSpec("mac", false, $.hasTag(asn1_ts_1.ASN1TagClass.universal, 4), undefined, undefined),
new $.ComponentSpec("unauthenticatedAttributes", true, $.hasTag(asn1_ts_1.ASN1TagClass.context, 3), undefined, undefined),
];
/* END_OF_SYMBOL_DEFINITION _root_component_type_list_1_spec_for_AuthenticatedData */
/* START_OF_SYMBOL_DEFINITION _root_component_type_list_2_spec_for_AuthenticatedData */
/**
* @summary The Trailing Root Component Types of AuthenticatedData
* @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_AuthenticatedData = [];
/* END_OF_SYMBOL_DEFINITION _root_component_type_list_2_spec_for_AuthenticatedData */
/* START_OF_SYMBOL_DEFINITION _extension_additions_list_spec_for_AuthenticatedData */
/**
* @summary The Extension Addition Component Types of AuthenticatedData
* @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_AuthenticatedData = [];
/* END_OF_SYMBOL_DEFINITION _extension_additions_list_spec_for_AuthenticatedData */
/* START_OF_SYMBOL_DEFINITION _cached_decoder_for_AuthenticatedData */
let _cached_decoder_for_AuthenticatedData = null;
/* END_OF_SYMBOL_DEFINITION _cached_decoder_for_AuthenticatedData */
/* START_OF_SYMBOL_DEFINITION _decode_AuthenticatedData */
/**
* @summary Decodes an ASN.1 element into a(n) AuthenticatedData
* @function
* @param {_Element} el The element being decoded.
* @returns {AuthenticatedData} The decoded data structure.
*/
function _decode_AuthenticatedData(el) {
if (!_cached_decoder_for_AuthenticatedData) {
_cached_decoder_for_AuthenticatedData = function (el) {
/* START_OF_SEQUENCE_COMPONENT_DECLARATIONS */
let version;
let originatorInfo;
let recipientInfos;
let macAlgorithm;
let digestAlgorithm;
let encapContentInfo;
let authenticatedAttributes;
let mac;
let unauthenticatedAttributes;
/* END_OF_SEQUENCE_COMPONENT_DECLARATIONS */
/* START_OF_CALLBACKS_MAP */
const callbacks = {
version: (_el) => {
version = CMSVersion_ta_1._decode_CMSVersion(_el);
},
originatorInfo: (_el) => {
originatorInfo = $._decode_implicit(() => OriginatorInfo_ta_1._decode_OriginatorInfo)(_el);
},
recipientInfos: (_el) => {
recipientInfos = RecipientInfos_ta_1._decode_RecipientInfos(_el);
},
macAlgorithm: (_el) => {
macAlgorithm = MessageAuthenticationCodeAlgorithm_ta_1._decode_MessageAuthenticationCodeAlgorithm(_el);
},
digestAlgorithm: (_el) => {
digestAlgorithm = $._decode_implicit(() => DigestAlgorithmIdentifier_ta_1._decode_DigestAlgorithmIdentifier)(_el);
},
encapContentInfo: (_el) => {
encapContentInfo = EncapsulatedContentInfo_ta_1._decode_EncapsulatedContentInfo(_el);
},
authenticatedAttributes: (_el) => {
authenticatedAttributes = $._decode_implicit(() => AuthAttributes_ta_1._decode_AuthAttributes)(_el);
},
mac: (_el) => {
mac = MessageAuthenticationCode_ta_1._decode_MessageAuthenticationCode(_el);
},
unauthenticatedAttributes: (_el) => {
unauthenticatedAttributes = $._decode_implicit(() => UnauthAttributes_ta_1._decode_UnauthAttributes)(_el);
},
};
/* END_OF_CALLBACKS_MAP */
$._parse_sequence(el, callbacks, exports._root_component_type_list_1_spec_for_AuthenticatedData, exports._extension_additions_list_spec_for_AuthenticatedData, exports._root_component_type_list_2_spec_for_AuthenticatedData, undefined);
return new AuthenticatedData(
/* SEQUENCE_CONSTRUCTOR_CALL */ version, originatorInfo, recipientInfos, macAlgorithm, digestAlgorithm, encapContentInfo, authenticatedAttributes, mac, unauthenticatedAttributes);
};
}
return _cached_decoder_for_AuthenticatedData(el);
}
exports._decode_AuthenticatedData = _decode_AuthenticatedData;
/* END_OF_SYMBOL_DEFINITION _decode_AuthenticatedData */
/* START_OF_SYMBOL_DEFINITION _cached_encoder_for_AuthenticatedData */
let _cached_encoder_for_AuthenticatedData = null;
/* END_OF_SYMBOL_DEFINITION _cached_encoder_for_AuthenticatedData */
/* START_OF_SYMBOL_DEFINITION _encode_AuthenticatedData */
/**
* @summary Encodes a(n) AuthenticatedData 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 AuthenticatedData, encoded as an ASN.1 Element.
*/
function _encode_AuthenticatedData(value, elGetter) {
if (!_cached_encoder_for_AuthenticatedData) {
_cached_encoder_for_AuthenticatedData = function (value, elGetter) {
return $._encodeSequence([]
.concat([
/* REQUIRED */ CMSVersion_ta_1._encode_CMSVersion(value.version, $.BER),
/* IF_ABSENT */ value.originatorInfo === undefined
? undefined
: $._encode_implicit(asn1_ts_1.ASN1TagClass.context, 0, () => OriginatorInfo_ta_1._encode_OriginatorInfo, $.BER)(value.originatorInfo, $.BER),
/* REQUIRED */ RecipientInfos_ta_1._encode_RecipientInfos(value.recipientInfos, $.BER),
/* REQUIRED */ MessageAuthenticationCodeAlgorithm_ta_1._encode_MessageAuthenticationCodeAlgorithm(value.macAlgorithm, $.BER),
/* IF_ABSENT */ value.digestAlgorithm === undefined
? undefined
: $._encode_implicit(asn1_ts_1.ASN1TagClass.context, 1, () => DigestAlgorithmIdentifier_ta_1._encode_DigestAlgorithmIdentifier, $.BER)(value.digestAlgorithm, $.BER),
/* REQUIRED */ EncapsulatedContentInfo_ta_1._encode_EncapsulatedContentInfo(value.encapContentInfo, $.BER),
/* IF_ABSENT */ value.authenticatedAttributes ===
undefined
? undefined
: $._encode_implicit(asn1_ts_1.ASN1TagClass.context, 2, () => AuthAttributes_ta_1._encode_AuthAttributes, $.BER)(value.authenticatedAttributes, $.BER),
/* REQUIRED */ MessageAuthenticationCode_ta_1._encode_MessageAuthenticationCode(value.mac, $.BER),
/* IF_ABSENT */ value.unauthenticatedAttributes ===
undefined
? undefined
: $._encode_implicit(asn1_ts_1.ASN1TagClass.context, 3, () => UnauthAttributes_ta_1._encode_UnauthAttributes, $.BER)(value.unauthenticatedAttributes, $.BER),
])
.filter((c) => !!c), $.BER);
};
}
return _cached_encoder_for_AuthenticatedData(value, elGetter);
}
exports._encode_AuthenticatedData = _encode_AuthenticatedData;
/* END_OF_SYMBOL_DEFINITION _encode_AuthenticatedData */
/* eslint-enable */
//# sourceMappingURL=AuthenticatedData.ta.js.map