@wildboar/pkcs
Version:
Public Key Cryptography Standard PDUs in TypeScript
196 lines (195 loc) • 6.53 kB
JavaScript
/* eslint-disable */
import { ASN1TagClass as _TagClass, } from "@wildboar/asn1";
import * as $ from "@wildboar/asn1/functional";
import { _decode_Reference, _encode_Reference, } from "../PKCS-15/Reference.ta.mjs";
/**
* @summary AlgorithmInfo
* @description
*
* ### ASN.1 Definition:
*
* ```asn1
* AlgorithmInfo ::= SEQUENCE {
* reference Reference,
* algorithm PKCS15-ALGORITHM.&id({AlgorithmSet}),
* parameters PKCS15-ALGORITHM.&Parameters({AlgorithmSet}{@algorithm}),
* supportedOperations PKCS15-ALGORITHM.&Operations({AlgorithmSet}{@algorithm}),
* algId PKCS15-ALGORITHM.&objectIdentifier({AlgorithmSet}{@algorithm}) OPTIONAL,
* algRef Reference OPTIONAL
* }
* ```
*
*/
export class AlgorithmInfo {
reference;
algorithm;
parameters;
supportedOperations;
algId;
algRef;
constructor(
/**
* @summary `reference`.
* @public
* @readonly
*/
reference,
/**
* @summary `algorithm`.
* @public
* @readonly
*/
algorithm,
/**
* @summary `parameters`.
* @public
* @readonly
*/
parameters,
/**
* @summary `supportedOperations`.
* @public
* @readonly
*/
supportedOperations,
/**
* @summary `algId`.
* @public
* @readonly
*/
algId,
/**
* @summary `algRef`.
* @public
* @readonly
*/
algRef) {
this.reference = reference;
this.algorithm = algorithm;
this.parameters = parameters;
this.supportedOperations = supportedOperations;
this.algId = algId;
this.algRef = algRef;
}
/**
* @summary Restructures an object into a AlgorithmInfo
* @description
*
* This takes an `object` and converts it to a `AlgorithmInfo`.
*
* @public
* @static
* @method
* @param {Object} _o An object having all of the keys and values of a `AlgorithmInfo`.
* @returns {AlgorithmInfo}
*/
static _from_object(_o) {
return new AlgorithmInfo(_o.reference, _o.algorithm, _o.parameters, _o.supportedOperations, _o.algId, _o.algRef);
}
}
/**
* @summary The Leading Root Component Types of AlgorithmInfo
* @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_AlgorithmInfo = [
new $.ComponentSpec("reference", false, $.hasTag(_TagClass.universal, 2)),
new $.ComponentSpec("algorithm", false, $.hasTag(_TagClass.universal, 2)),
new $.ComponentSpec("parameters", false, $.hasAnyTag),
new $.ComponentSpec("supportedOperations", false, $.hasTag(_TagClass.universal, 3)),
new $.ComponentSpec("algId", true, $.hasTag(_TagClass.universal, 6)),
new $.ComponentSpec("algRef", true, $.hasTag(_TagClass.universal, 2)),
];
/**
* @summary The Trailing Root Component Types of AlgorithmInfo
* @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_AlgorithmInfo = [];
/**
* @summary The Extension Addition Component Types of AlgorithmInfo
* @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_AlgorithmInfo = [];
let _cached_decoder_for_AlgorithmInfo = null;
/**
* @summary Decodes an ASN.1 element into a(n) AlgorithmInfo
* @function
* @param {_Element} el The element being decoded.
* @returns {AlgorithmInfo} The decoded data structure.
*/
export function _decode_AlgorithmInfo(el) {
if (!_cached_decoder_for_AlgorithmInfo) {
_cached_decoder_for_AlgorithmInfo = function (el) {
let reference;
let algorithm;
let parameters;
let supportedOperations;
let algId;
let algRef;
const callbacks = {
reference: (_el) => {
reference = _decode_Reference(_el);
},
algorithm: (_el) => {
algorithm = $._decodeInteger(_el);
},
parameters: (_el) => {
parameters = $._decodeAny(_el);
},
supportedOperations: (_el) => {
supportedOperations = $._decodeAny(_el);
},
algId: (_el) => {
algId = $._decodeObjectIdentifier(_el);
},
algRef: (_el) => {
algRef = _decode_Reference(_el);
},
};
$._parse_sequence(el, callbacks, _root_component_type_list_1_spec_for_AlgorithmInfo, _extension_additions_list_spec_for_AlgorithmInfo, _root_component_type_list_2_spec_for_AlgorithmInfo, undefined);
return new AlgorithmInfo(reference, algorithm, parameters, supportedOperations, algId, algRef);
};
}
return _cached_decoder_for_AlgorithmInfo(el);
}
let _cached_encoder_for_AlgorithmInfo = null;
/**
* @summary Encodes a(n) AlgorithmInfo 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 AlgorithmInfo, encoded as an ASN.1 Element.
*/
export function _encode_AlgorithmInfo(value, elGetter) {
if (!_cached_encoder_for_AlgorithmInfo) {
_cached_encoder_for_AlgorithmInfo = function (value) {
return $._encodeSequence([]
.concat([
/* REQUIRED */ _encode_Reference(value.reference, $.BER),
/* REQUIRED */ $._encodeInteger(value.algorithm, $.BER),
/* REQUIRED */ $._encodeAny(value.parameters, $.BER),
/* REQUIRED */ $._encodeAny(value.supportedOperations, $.BER),
/* IF_ABSENT */ value.algId === undefined
? undefined
: $._encodeObjectIdentifier(value.algId, $.BER),
/* IF_ABSENT */ value.algRef === undefined
? undefined
: _encode_Reference(value.algRef, $.BER),
])
.filter((c) => !!c), $.BER);
};
}
return _cached_encoder_for_AlgorithmInfo(value, elGetter);
}
/* eslint-enable */