@wildboar/pkcs
Version:
Public Key Cryptography Standard PDUs in TypeScript
227 lines (226 loc) • 9.02 kB
JavaScript
/* eslint-disable */
import { ASN1TagClass as _TagClass, } from "@wildboar/asn1";
import * as $ from "@wildboar/asn1/functional";
import { _decode_CertificateRevocationLists, _encode_CertificateRevocationLists, } from "../PKCS7/CertificateRevocationLists.ta.mjs";
import { _decode_CertificateSet, _encode_CertificateSet, } from "../PKCS7/CertificateSet.ta.mjs";
import { _decode_DigestAlgorithmIdentifiers, _encode_DigestAlgorithmIdentifiers, } from "../PKCS7/DigestAlgorithmIdentifiers.ta.mjs";
import { _decode_EncryptedContentInfo, _encode_EncryptedContentInfo, } from "../PKCS7/EncryptedContentInfo.ta.mjs";
import { _decode_KeyTransportRecipientInfo, _encode_KeyTransportRecipientInfo, } from "../PKCS7/KeyTransportRecipientInfo.ta.mjs";
import { _decode_SignerInfo, _encode_SignerInfo, } from "../PKCS7/SignerInfo.ta.mjs";
import { _decode_Version, _encode_Version } from "../PKCS7/Version.ta.mjs";
/**
* @summary SignedAndEnvelopedData
* @description
*
* ### ASN.1 Definition:
*
* ```asn1
* SignedAndEnvelopedData ::= SEQUENCE {
* version Version,
* recipientInfos SET SIZE (1..MAX) OF KeyTransportRecipientInfo,
* digestAlgorithms DigestAlgorithmIdentifiers,
* encryptedContentInfo EncryptedContentInfo,
* certificates [0] CertificateSet OPTIONAL,
* crls [1] CertificateRevocationLists OPTIONAL,
* signerInfos
* SET SIZE (1..MAX) OF
* SignerInfo
* (WITH COMPONENTS {
* ...,
* signerIdentifier (WITH COMPONENTS {
* issuerAndSerialNumber PRESENT
* }),
* authenticatedAttributes ABSENT,
* unauthenticatedAttributes ABSENT
* })
* }
* ```
*
*/
export class SignedAndEnvelopedData {
version;
recipientInfos;
digestAlgorithms;
encryptedContentInfo;
certificates;
crls;
signerInfos;
constructor(
/**
* @summary `version`.
* @public
* @readonly
*/
version,
/**
* @summary `recipientInfos`.
* @public
* @readonly
*/
recipientInfos,
/**
* @summary `digestAlgorithms`.
* @public
* @readonly
*/
digestAlgorithms,
/**
* @summary `encryptedContentInfo`.
* @public
* @readonly
*/
encryptedContentInfo,
/**
* @summary `certificates`.
* @public
* @readonly
*/
certificates,
/**
* @summary `crls`.
* @public
* @readonly
*/
crls,
/**
* @summary `signerInfos`.
* @public
* @readonly
*/
signerInfos) {
this.version = version;
this.recipientInfos = recipientInfos;
this.digestAlgorithms = digestAlgorithms;
this.encryptedContentInfo = encryptedContentInfo;
this.certificates = certificates;
this.crls = crls;
this.signerInfos = signerInfos;
}
/**
* @summary Restructures an object into a SignedAndEnvelopedData
* @description
*
* This takes an `object` and converts it to a `SignedAndEnvelopedData`.
*
* @public
* @static
* @method
* @param {Object} _o An object having all of the keys and values of a `SignedAndEnvelopedData`.
* @returns {SignedAndEnvelopedData}
*/
static _from_object(_o) {
return new SignedAndEnvelopedData(_o.version, _o.recipientInfos, _o.digestAlgorithms, _o.encryptedContentInfo, _o.certificates, _o.crls, _o.signerInfos);
}
}
/**
* @summary The Leading Root Component Types of SignedAndEnvelopedData
* @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_SignedAndEnvelopedData = [
new $.ComponentSpec("version", false, $.hasTag(_TagClass.universal, 2)),
new $.ComponentSpec("recipientInfos", false, $.hasTag(_TagClass.universal, 17)),
new $.ComponentSpec("digestAlgorithms", false, $.hasTag(_TagClass.universal, 17)),
new $.ComponentSpec("encryptedContentInfo", false, $.hasTag(_TagClass.universal, 16)),
new $.ComponentSpec("certificates", true, $.hasTag(_TagClass.context, 0)),
new $.ComponentSpec("crls", true, $.hasTag(_TagClass.context, 1)),
new $.ComponentSpec("signerInfos", false, $.hasTag(_TagClass.universal, 17)),
];
/**
* @summary The Trailing Root Component Types of SignedAndEnvelopedData
* @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_SignedAndEnvelopedData = [];
/**
* @summary The Extension Addition Component Types of SignedAndEnvelopedData
* @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_SignedAndEnvelopedData = [];
let _cached_decoder_for_SignedAndEnvelopedData = null;
/**
* @summary Decodes an ASN.1 element into a(n) SignedAndEnvelopedData
* @function
* @param {_Element} el The element being decoded.
* @returns {SignedAndEnvelopedData} The decoded data structure.
*/
export function _decode_SignedAndEnvelopedData(el) {
if (!_cached_decoder_for_SignedAndEnvelopedData) {
_cached_decoder_for_SignedAndEnvelopedData = function (el) {
let version;
let recipientInfos;
let digestAlgorithms;
let encryptedContentInfo;
let certificates;
let crls;
let signerInfos;
const callbacks = {
version: (_el) => {
version = _decode_Version(_el);
},
recipientInfos: (_el) => {
recipientInfos = $._decodeSetOf(() => _decode_KeyTransportRecipientInfo)(_el);
},
digestAlgorithms: (_el) => {
digestAlgorithms = _decode_DigestAlgorithmIdentifiers(_el);
},
encryptedContentInfo: (_el) => {
encryptedContentInfo = _decode_EncryptedContentInfo(_el);
},
certificates: (_el) => {
certificates = $._decode_implicit(() => _decode_CertificateSet)(_el);
},
crls: (_el) => {
crls = $._decode_implicit(() => _decode_CertificateRevocationLists)(_el);
},
signerInfos: (_el) => {
signerInfos = $._decodeSetOf(() => _decode_SignerInfo)(_el);
},
};
$._parse_sequence(el, callbacks, _root_component_type_list_1_spec_for_SignedAndEnvelopedData, _extension_additions_list_spec_for_SignedAndEnvelopedData, _root_component_type_list_2_spec_for_SignedAndEnvelopedData, undefined);
return new SignedAndEnvelopedData(version, recipientInfos, digestAlgorithms, encryptedContentInfo, certificates, crls, signerInfos);
};
}
return _cached_decoder_for_SignedAndEnvelopedData(el);
}
let _cached_encoder_for_SignedAndEnvelopedData = null;
/**
* @summary Encodes a(n) SignedAndEnvelopedData 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 SignedAndEnvelopedData, encoded as an ASN.1 Element.
*/
export function _encode_SignedAndEnvelopedData(value, elGetter) {
if (!_cached_encoder_for_SignedAndEnvelopedData) {
_cached_encoder_for_SignedAndEnvelopedData = function (value) {
return $._encodeSequence([]
.concat([
/* REQUIRED */ _encode_Version(value.version, $.BER),
/* REQUIRED */ $._encodeSetOf(() => _encode_KeyTransportRecipientInfo, $.BER)(value.recipientInfos, $.BER),
/* REQUIRED */ _encode_DigestAlgorithmIdentifiers(value.digestAlgorithms, $.BER),
/* REQUIRED */ _encode_EncryptedContentInfo(value.encryptedContentInfo, $.BER),
/* IF_ABSENT */ value.certificates === undefined
? undefined
: $._encode_implicit(_TagClass.context, 0, () => _encode_CertificateSet, $.BER)(value.certificates, $.BER),
/* IF_ABSENT */ value.crls === undefined
? undefined
: $._encode_implicit(_TagClass.context, 1, () => _encode_CertificateRevocationLists, $.BER)(value.crls, $.BER),
/* REQUIRED */ $._encodeSetOf(() => _encode_SignerInfo, $.BER)(value.signerInfos, $.BER),
])
.filter((c) => !!c), $.BER);
};
}
return _cached_encoder_for_SignedAndEnvelopedData(value, elGetter);
}
/* eslint-enable */