UNPKG

@wildboar/pkcs

Version:
65 lines (64 loc) 3.55 kB
/* eslint-disable */ import { ASN1TagClass as _TagClass } from "@wildboar/asn1"; import * as $ from "@wildboar/asn1/functional"; import { _decode_PrivateDHKeyAttributes, _encode_PrivateDHKeyAttributes, } from "../PKCS-15/PrivateDHKeyAttributes.ta.mjs"; import { _decode_PrivateDSAKeyAttributes, _encode_PrivateDSAKeyAttributes, } from "../PKCS-15/PrivateDSAKeyAttributes.ta.mjs"; import { _decode_PrivateECKeyAttributes, _encode_PrivateECKeyAttributes, } from "../PKCS-15/PrivateECKeyAttributes.ta.mjs"; import { _decode_PrivateKEAKeyAttributes, _encode_PrivateKEAKeyAttributes, } from "../PKCS-15/PrivateKEAKeyAttributes.ta.mjs"; import { _get_decoder_for_PrivateKeyObject, _get_encoder_for_PrivateKeyObject, } from "../PKCS-15/PrivateKeyObject.ta.mjs"; import { _decode_PrivateRSAKeyAttributes, _encode_PrivateRSAKeyAttributes, } from "../PKCS-15/PrivateRSAKeyAttributes.ta.mjs"; let _cached_decoder_for_PrivateKeyType = null; /** * @summary Decodes an ASN.1 element into a(n) PrivateKeyType * @function * @param {_Element} el The element being decoded. * @returns {PrivateKeyType} The decoded data structure. */ export function _decode_PrivateKeyType(el) { if (!_cached_decoder_for_PrivateKeyType) { _cached_decoder_for_PrivateKeyType = $._decode_extensible_choice({ "UNIVERSAL 16": [ "privateRSAKey", _get_decoder_for_PrivateKeyObject(_decode_PrivateRSAKeyAttributes), ], "CONTEXT 0": [ "privateECKey", $._decode_implicit(() => _get_decoder_for_PrivateKeyObject(_decode_PrivateECKeyAttributes)), ], "CONTEXT 1": [ "privateDHKey", $._decode_implicit(() => _get_decoder_for_PrivateKeyObject(_decode_PrivateDHKeyAttributes)), ], "CONTEXT 2": [ "privateDSAKey", $._decode_implicit(() => _get_decoder_for_PrivateKeyObject(_decode_PrivateDSAKeyAttributes)), ], "CONTEXT 3": [ "privateKEAKey", $._decode_implicit(() => _get_decoder_for_PrivateKeyObject(_decode_PrivateKEAKeyAttributes)), ], }); } return _cached_decoder_for_PrivateKeyType(el); } let _cached_encoder_for_PrivateKeyType = null; /** * @summary Encodes a(n) PrivateKeyType 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 PrivateKeyType, encoded as an ASN.1 Element. */ export function _encode_PrivateKeyType(value, elGetter) { if (!_cached_encoder_for_PrivateKeyType) { _cached_encoder_for_PrivateKeyType = $._encode_choice({ privateRSAKey: _get_encoder_for_PrivateKeyObject(_encode_PrivateRSAKeyAttributes), privateECKey: $._encode_implicit(_TagClass.context, 0, () => _get_encoder_for_PrivateKeyObject(_encode_PrivateECKeyAttributes), $.BER), privateDHKey: $._encode_implicit(_TagClass.context, 1, () => _get_encoder_for_PrivateKeyObject(_encode_PrivateDHKeyAttributes), $.BER), privateDSAKey: $._encode_implicit(_TagClass.context, 2, () => _get_encoder_for_PrivateKeyObject(_encode_PrivateDSAKeyAttributes), $.BER), privateKEAKey: $._encode_implicit(_TagClass.context, 3, () => _get_encoder_for_PrivateKeyObject(_encode_PrivateKEAKeyAttributes), $.BER), }, $.BER); } return _cached_encoder_for_PrivateKeyType(value, elGetter); } /* eslint-enable */