@wildboar/pkcs
Version:
Public Key Cryptography Standard PDUs in TypeScript
49 lines (48 loc) • 2.19 kB
JavaScript
/* eslint-disable */
import { ASN1TagClass as _TagClass } from "@wildboar/asn1";
import * as $ from "@wildboar/asn1/functional";
import { _decode_KEKRecipientInfo, _encode_KEKRecipientInfo, } from "../CryptographicMessageSyntax/KEKRecipientInfo.ta.mjs";
import { _decode_KeyAgreeRecipientInfo, _encode_KeyAgreeRecipientInfo, } from "../CryptographicMessageSyntax/KeyAgreeRecipientInfo.ta.mjs";
import { _decode_KeyTransRecipientInfo, _encode_KeyTransRecipientInfo, } from "../CryptographicMessageSyntax/KeyTransRecipientInfo.ta.mjs";
let _cached_decoder_for_RecipientInfo = null;
/**
* @summary Decodes an ASN.1 element into a(n) RecipientInfo
* @function
* @param {_Element} el The element being decoded.
* @returns {RecipientInfo} The decoded data structure.
*/
export function _decode_RecipientInfo(el) {
if (!_cached_decoder_for_RecipientInfo) {
_cached_decoder_for_RecipientInfo = $._decode_inextensible_choice({
"UNIVERSAL 16": ["ktri", _decode_KeyTransRecipientInfo],
"CONTEXT 1": [
"kari",
$._decode_implicit(() => _decode_KeyAgreeRecipientInfo),
],
"CONTEXT 2": [
"kekri",
$._decode_implicit(() => _decode_KEKRecipientInfo),
],
});
}
return _cached_decoder_for_RecipientInfo(el);
}
let _cached_encoder_for_RecipientInfo = null;
/**
* @summary Encodes a(n) RecipientInfo 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 RecipientInfo, encoded as an ASN.1 Element.
*/
export function _encode_RecipientInfo(value, elGetter) {
if (!_cached_encoder_for_RecipientInfo) {
_cached_encoder_for_RecipientInfo = $._encode_choice({
ktri: _encode_KeyTransRecipientInfo,
kari: $._encode_implicit(_TagClass.context, 1, () => _encode_KeyAgreeRecipientInfo, $.BER),
kekri: $._encode_implicit(_TagClass.context, 2, () => _encode_KEKRecipientInfo, $.BER),
}, $.BER);
}
return _cached_encoder_for_RecipientInfo(value, elGetter);
}
/* eslint-enable */