@wildboar/pkcs
Version:
Public Key Cryptography Standard PDUs in TypeScript
49 lines (48 loc) • 2.24 kB
JavaScript
/* eslint-disable */
import { ASN1TagClass as _TagClass } from "@wildboar/asn1";
import * as $ from "@wildboar/asn1/functional";
import { _decode_AttributeCertificate, _encode_AttributeCertificate, } from "@wildboar/x500/AttributeCertificateDefinitions";
import { _decode_Certificate, _encode_Certificate, } from "@wildboar/x500/AuthenticationFramework";
import { _decode_ExtendedCertificate, _encode_ExtendedCertificate, } from "../PKCS7/ExtendedCertificate.ta.mjs";
let _cached_decoder_for_CertificateChoice = null;
/**
* @summary Decodes an ASN.1 element into a(n) CertificateChoice
* @function
* @param {_Element} el The element being decoded.
* @returns {CertificateChoice} The decoded data structure.
*/
export function _decode_CertificateChoice(el) {
if (!_cached_decoder_for_CertificateChoice) {
_cached_decoder_for_CertificateChoice = $._decode_inextensible_choice({
"UNIVERSAL 16": ["certificate", _decode_Certificate],
"CONTEXT 0": [
"extendedCertificate",
$._decode_implicit(() => _decode_ExtendedCertificate),
],
"CONTEXT 1": [
"attributeCertificate",
$._decode_implicit(() => _decode_AttributeCertificate),
],
});
}
return _cached_decoder_for_CertificateChoice(el);
}
let _cached_encoder_for_CertificateChoice = null;
/**
* @summary Encodes a(n) CertificateChoice 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 CertificateChoice, encoded as an ASN.1 Element.
*/
export function _encode_CertificateChoice(value, elGetter) {
if (!_cached_encoder_for_CertificateChoice) {
_cached_encoder_for_CertificateChoice = $._encode_choice({
certificate: _encode_Certificate,
extendedCertificate: $._encode_implicit(_TagClass.context, 0, () => _encode_ExtendedCertificate, $.BER),
attributeCertificate: $._encode_implicit(_TagClass.context, 1, () => _encode_AttributeCertificate, $.BER),
}, $.BER);
}
return _cached_encoder_for_CertificateChoice(value, elGetter);
}
/* eslint-enable */