@wildboar/pkcs
Version:
Public Key Cryptography Standard PDUs in TypeScript
51 lines (50 loc) • 2.22 kB
JavaScript
/* eslint-disable */
import { ASN1TagClass as _TagClass } from "@wildboar/asn1";
import * as $ from "@wildboar/asn1/functional";
import { _get_decoder_for_EnvelopedData, _get_encoder_for_EnvelopedData, } from "../PKCS-15/EnvelopedData.ta.mjs";
import { _get_decoder_for_ReferencedValue, _get_encoder_for_ReferencedValue, } from "../PKCS-15/ReferencedValue.ta.mjs";
/**
* @summary Returns a function that will decode an ASN.1 element into a(n) ObjectValue
* @function
* @param {_Element} el The element being decoded.
* @returns A function that will decode an ASN.1 element.
*/
export function _get_decoder_for_ObjectValue(_decode_Type) {
return $._decode_inextensible_choice({
"UNIVERSAL 16": [
"indirect",
_get_decoder_for_ReferencedValue(_decode_Type),
],
"UNIVERSAL 19": [
"indirect",
_get_decoder_for_ReferencedValue(_decode_Type),
],
"CONTEXT 3": [
"indirect",
_get_decoder_for_ReferencedValue(_decode_Type),
],
"CONTEXT 0": ["direct", $._decode_implicit(() => _decode_Type)],
"CONTEXT 1": [
"indirect_protected",
$._decode_explicit(() => _get_decoder_for_ReferencedValue(_get_decoder_for_EnvelopedData(_decode_Type))),
],
"CONTEXT 2": [
"direct_protected",
$._decode_implicit(() => _get_decoder_for_EnvelopedData(_decode_Type)),
],
});
}
/**
* @summary Returns a function that will encode a(n) ObjectValue into an ASN.1 Element.
* @function
* @returns A function that will encode a(n) ObjectValue as an ASN.1 element.
*/
export function _get_encoder_for_ObjectValue(_encode_Type) {
return $._encode_choice({
indirect: _get_encoder_for_ReferencedValue(_encode_Type),
direct: $._encode_implicit(_TagClass.context, 0, () => _encode_Type, $.BER),
indirect_protected: $._encode_explicit(_TagClass.context, 1, () => _get_encoder_for_ReferencedValue(_get_encoder_for_EnvelopedData(_encode_Type)), $.BER),
direct_protected: $._encode_implicit(_TagClass.context, 2, () => _get_encoder_for_EnvelopedData(_encode_Type), $.BER),
}, $.BER);
}
/* eslint-enable */