@wildboar/pkcs
Version:
Public Key Cryptography Standard PDUs in TypeScript
49 lines (48 loc) • 2.25 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 "../CryptographicMessageSyntax/ExtendedCertificate.ta.mjs";
let _cached_decoder_for_CertificateChoices = null;
/**
* @summary Decodes an ASN.1 element into a(n) CertificateChoices
* @function
* @param {_Element} el The element being decoded.
* @returns {CertificateChoices} The decoded data structure.
*/
export function _decode_CertificateChoices(el) {
if (!_cached_decoder_for_CertificateChoices) {
_cached_decoder_for_CertificateChoices = $._decode_inextensible_choice({
"UNIVERSAL 16": ["certificate", _decode_Certificate],
"CONTEXT 0": [
"extendedCertificate",
$._decode_implicit(() => _decode_ExtendedCertificate),
],
"CONTEXT 1": [
"attrCert",
$._decode_implicit(() => _decode_AttributeCertificate),
],
});
}
return _cached_decoder_for_CertificateChoices(el);
}
let _cached_encoder_for_CertificateChoices = null;
/**
* @summary Encodes a(n) CertificateChoices 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 CertificateChoices, encoded as an ASN.1 Element.
*/
export function _encode_CertificateChoices(value, elGetter) {
if (!_cached_encoder_for_CertificateChoices) {
_cached_encoder_for_CertificateChoices = $._encode_choice({
certificate: _encode_Certificate,
extendedCertificate: $._encode_implicit(_TagClass.context, 0, () => _encode_ExtendedCertificate, $.BER),
attrCert: $._encode_implicit(_TagClass.context, 1, () => _encode_AttributeCertificate, $.BER),
}, $.BER);
}
return _cached_encoder_for_CertificateChoices(value, elGetter);
}
/* eslint-enable */