@wildboar/pkcs
Version:
Public Key Cryptography Standard PDUs in TypeScript
132 lines (131 loc) • 4.25 kB
JavaScript
/* eslint-disable */
import { ASN1ConstructionError as _ConstructionError, ASN1TagClass as _TagClass, } from "@wildboar/asn1";
import * as $ from "@wildboar/asn1/functional";
/**
* @summary SMIMECapability
* @description
*
* ### ASN.1 Definition:
*
* ```asn1
* SMIMECapability ::= SEQUENCE {
* algorithm ALGORITHM.&id ({SMIMEv3Algorithms}),
* parameters ALGORITHM.&Type ({SMIMEv3Algorithms}{@algorithm})
* }
* ```
*
*/
export class SMIMECapability {
algorithm;
parameters;
constructor(
/**
* @summary `algorithm`.
* @public
* @readonly
*/
algorithm,
/**
* @summary `parameters`.
* @public
* @readonly
*/
parameters) {
this.algorithm = algorithm;
this.parameters = parameters;
}
/**
* @summary Restructures an object into a SMIMECapability
* @description
*
* This takes an `object` and converts it to a `SMIMECapability`.
*
* @public
* @static
* @method
* @param {Object} _o An object having all of the keys and values of a `SMIMECapability`.
* @returns {SMIMECapability}
*/
static _from_object(_o) {
return new SMIMECapability(_o.algorithm, _o.parameters);
}
}
/**
* @summary The Leading Root Component Types of SMIMECapability
* @description
*
* This is an array of `ComponentSpec`s that define how to decode the leading root component type list of a SET or SEQUENCE.
*
* @constant
*/
export const _root_component_type_list_1_spec_for_SMIMECapability = [
new $.ComponentSpec("algorithm", false, $.hasTag(_TagClass.universal, 6)),
new $.ComponentSpec("parameters", false, $.hasAnyTag),
];
/**
* @summary The Trailing Root Component Types of SMIMECapability
* @description
*
* This is an array of `ComponentSpec`s that define how to decode the trailing root component type list of a SET or SEQUENCE.
*
* @constant
*/
export const _root_component_type_list_2_spec_for_SMIMECapability = [];
/**
* @summary The Extension Addition Component Types of SMIMECapability
* @description
*
* This is an array of `ComponentSpec`s that define how to decode the extension addition component type list of a SET or SEQUENCE.
*
* @constant
*/
export const _extension_additions_list_spec_for_SMIMECapability = [];
let _cached_decoder_for_SMIMECapability = null;
/**
* @summary Decodes an ASN.1 element into a(n) SMIMECapability
* @function
* @param {_Element} el The element being decoded.
* @returns {SMIMECapability} The decoded data structure.
*/
export function _decode_SMIMECapability(el) {
if (!_cached_decoder_for_SMIMECapability) {
_cached_decoder_for_SMIMECapability = function (el) {
const sequence = el.sequence;
if (sequence.length < 2) {
throw new _ConstructionError("SMIMECapability contained only " +
sequence.length.toString() +
" elements.");
}
sequence[0].name = "algorithm";
sequence[1].name = "parameters";
let algorithm;
let parameters;
algorithm = $._decodeObjectIdentifier(sequence[0]);
parameters = $._decodeAny(sequence[1]);
return new SMIMECapability(algorithm, parameters);
};
}
return _cached_decoder_for_SMIMECapability(el);
}
let _cached_encoder_for_SMIMECapability = null;
/**
* @summary Encodes a(n) SMIMECapability 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 SMIMECapability, encoded as an ASN.1 Element.
*/
export function _encode_SMIMECapability(value, elGetter) {
if (!_cached_encoder_for_SMIMECapability) {
_cached_encoder_for_SMIMECapability = function (value) {
return $._encodeSequence([]
.concat([
/* REQUIRED */ $._encodeObjectIdentifier(value.algorithm, $.BER),
/* REQUIRED */ $._encodeAny(value.parameters, $.BER),
])
.filter((c) => !!c), $.BER);
};
}
return _cached_encoder_for_SMIMECapability(value, elGetter);
}
/* eslint-enable */