@wildboar/pkcs
Version:
Public Key Cryptography Standard PDUs in TypeScript
255 lines (254 loc) • 10.7 kB
JavaScript
/* eslint-disable */
import { ASN1TagClass as _TagClass, } from "@wildboar/asn1";
import * as $ from "@wildboar/asn1/functional";
import { _decode_AuthAttributes, _encode_AuthAttributes, } from "../CryptographicMessageSyntax/AuthAttributes.ta.mjs";
import { _decode_CMSVersion, _encode_CMSVersion, } from "../CryptographicMessageSyntax/CMSVersion.ta.mjs";
import { _decode_DigestAlgorithmIdentifier, _encode_DigestAlgorithmIdentifier, } from "../CryptographicMessageSyntax/DigestAlgorithmIdentifier.ta.mjs";
import { _decode_EncapsulatedContentInfo, _encode_EncapsulatedContentInfo, } from "../CryptographicMessageSyntax/EncapsulatedContentInfo.ta.mjs";
import { _decode_MessageAuthenticationCode, _encode_MessageAuthenticationCode, } from "../CryptographicMessageSyntax/MessageAuthenticationCode.ta.mjs";
import { _decode_MessageAuthenticationCodeAlgorithm, _encode_MessageAuthenticationCodeAlgorithm, } from "../CryptographicMessageSyntax/MessageAuthenticationCodeAlgorithm.ta.mjs";
import { _decode_OriginatorInfo, _encode_OriginatorInfo, } from "../CryptographicMessageSyntax/OriginatorInfo.ta.mjs";
import { _decode_RecipientInfos, _encode_RecipientInfos, } from "../CryptographicMessageSyntax/RecipientInfos.ta.mjs";
import { _decode_UnauthAttributes, _encode_UnauthAttributes, } from "../CryptographicMessageSyntax/UnauthAttributes.ta.mjs";
/**
* @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
* }
* ```
*
*/
export class AuthenticatedData {
version;
originatorInfo;
recipientInfos;
macAlgorithm;
digestAlgorithm;
encapContentInfo;
authenticatedAttributes;
mac;
unauthenticatedAttributes;
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);
}
}
/**
* @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
*/
export const _root_component_type_list_1_spec_for_AuthenticatedData = [
new $.ComponentSpec("version", false, $.hasTag(_TagClass.universal, 2)),
new $.ComponentSpec("originatorInfo", true, $.hasTag(_TagClass.context, 0)),
new $.ComponentSpec("recipientInfos", false, $.hasTag(_TagClass.universal, 17)),
new $.ComponentSpec("macAlgorithm", false, $.hasTag(_TagClass.universal, 16)),
new $.ComponentSpec("digestAlgorithm", true, $.hasTag(_TagClass.context, 1)),
new $.ComponentSpec("encapContentInfo", false, $.hasTag(_TagClass.universal, 16)),
new $.ComponentSpec("authenticatedAttributes", true, $.hasTag(_TagClass.context, 2)),
new $.ComponentSpec("mac", false, $.hasTag(_TagClass.universal, 4)),
new $.ComponentSpec("unauthenticatedAttributes", true, $.hasTag(_TagClass.context, 3)),
];
/**
* @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
*/
export const _root_component_type_list_2_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
*/
export const _extension_additions_list_spec_for_AuthenticatedData = [];
let _cached_decoder_for_AuthenticatedData = null;
/**
* @summary Decodes an ASN.1 element into a(n) AuthenticatedData
* @function
* @param {_Element} el The element being decoded.
* @returns {AuthenticatedData} The decoded data structure.
*/
export function _decode_AuthenticatedData(el) {
if (!_cached_decoder_for_AuthenticatedData) {
_cached_decoder_for_AuthenticatedData = function (el) {
let version;
let originatorInfo;
let recipientInfos;
let macAlgorithm;
let digestAlgorithm;
let encapContentInfo;
let authenticatedAttributes;
let mac;
let unauthenticatedAttributes;
const callbacks = {
version: (_el) => {
version = _decode_CMSVersion(_el);
},
originatorInfo: (_el) => {
originatorInfo = $._decode_implicit(() => _decode_OriginatorInfo)(_el);
},
recipientInfos: (_el) => {
recipientInfos = _decode_RecipientInfos(_el);
},
macAlgorithm: (_el) => {
macAlgorithm = _decode_MessageAuthenticationCodeAlgorithm(_el);
},
digestAlgorithm: (_el) => {
digestAlgorithm = $._decode_implicit(() => _decode_DigestAlgorithmIdentifier)(_el);
},
encapContentInfo: (_el) => {
encapContentInfo = _decode_EncapsulatedContentInfo(_el);
},
authenticatedAttributes: (_el) => {
authenticatedAttributes = $._decode_implicit(() => _decode_AuthAttributes)(_el);
},
mac: (_el) => {
mac = _decode_MessageAuthenticationCode(_el);
},
unauthenticatedAttributes: (_el) => {
unauthenticatedAttributes = $._decode_implicit(() => _decode_UnauthAttributes)(_el);
},
};
$._parse_sequence(el, callbacks, _root_component_type_list_1_spec_for_AuthenticatedData, _extension_additions_list_spec_for_AuthenticatedData, _root_component_type_list_2_spec_for_AuthenticatedData, undefined);
return new AuthenticatedData(version, originatorInfo, recipientInfos, macAlgorithm, digestAlgorithm, encapContentInfo, authenticatedAttributes, mac, unauthenticatedAttributes);
};
}
return _cached_decoder_for_AuthenticatedData(el);
}
let _cached_encoder_for_AuthenticatedData = null;
/**
* @summary Encodes a(n) AuthenticatedData 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 AuthenticatedData, encoded as an ASN.1 Element.
*/
export function _encode_AuthenticatedData(value, elGetter) {
if (!_cached_encoder_for_AuthenticatedData) {
_cached_encoder_for_AuthenticatedData = function (value) {
return $._encodeSequence([]
.concat([
/* REQUIRED */ _encode_CMSVersion(value.version, $.BER),
/* IF_ABSENT */ value.originatorInfo === undefined
? undefined
: $._encode_implicit(_TagClass.context, 0, () => _encode_OriginatorInfo, $.BER)(value.originatorInfo, $.BER),
/* REQUIRED */ _encode_RecipientInfos(value.recipientInfos, $.BER),
/* REQUIRED */ _encode_MessageAuthenticationCodeAlgorithm(value.macAlgorithm, $.BER),
/* IF_ABSENT */ value.digestAlgorithm === undefined
? undefined
: $._encode_implicit(_TagClass.context, 1, () => _encode_DigestAlgorithmIdentifier, $.BER)(value.digestAlgorithm, $.BER),
/* REQUIRED */ _encode_EncapsulatedContentInfo(value.encapContentInfo, $.BER),
/* IF_ABSENT */ value.authenticatedAttributes ===
undefined
? undefined
: $._encode_implicit(_TagClass.context, 2, () => _encode_AuthAttributes, $.BER)(value.authenticatedAttributes, $.BER),
/* REQUIRED */ _encode_MessageAuthenticationCode(value.mac, $.BER),
/* IF_ABSENT */ value.unauthenticatedAttributes ===
undefined
? undefined
: $._encode_implicit(_TagClass.context, 3, () => _encode_UnauthAttributes, $.BER)(value.unauthenticatedAttributes, $.BER),
])
.filter((c) => !!c), $.BER);
};
}
return _cached_encoder_for_AuthenticatedData(value, elGetter);
}
/* eslint-enable */