@wildboar/pki-stub
Version:
X.510 PKI-Stub ASN.1 data structures in TypeScript
131 lines (130 loc) • 4.13 kB
JavaScript
/* eslint-disable */
import { ASN1TagClass as _TagClass, ASN1ConstructionError as _ConstructionError, } from "@wildboar/asn1";
import * as $ from "@wildboar/asn1/functional";
import { _decode_AlgorithmIdentifier, _encode_AlgorithmIdentifier, } from "../PKI-Stub/AlgorithmIdentifier.ta.mjs";
/**
* @summary HASH
* @description
*
* ### ASN.1 Definition:
*
* ```asn1
* HASH{ToBeHashed} ::= SEQUENCE {
* algorithmIdentifier AlgorithmIdentifier{{SupportedAlgorithms}},
* hashValue BIT STRING,
* ... }
* ```
*
*/
export class HASH {
algorithmIdentifier;
hashValue;
_unrecognizedExtensionsList;
constructor(
/**
* @summary `algorithmIdentifier`.
* @public
* @readonly
*/
algorithmIdentifier,
/**
* @summary `hashValue`.
* @public
* @readonly
*/
hashValue,
/**
* @summary Extensions that are not recognized.
* @public
* @readonly
*/
_unrecognizedExtensionsList = []) {
this.algorithmIdentifier = algorithmIdentifier;
this.hashValue = hashValue;
this._unrecognizedExtensionsList = _unrecognizedExtensionsList;
}
/**
* @summary Restructures an object into a HASH
* @description
*
* This takes an `object` and converts it to a `HASH`.
*
* @public
* @static
* @method
* @param {Object} _o An object having all of the keys and values of a `HASH`.
* @returns {HASH}
*/
static _from_object(_o) {
return new HASH(_o.algorithmIdentifier, _o.hashValue, _o._unrecognizedExtensionsList);
}
}
/**
* @summary The Leading Root Component Types of HASH
* @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_HASH = [
new $.ComponentSpec("algorithmIdentifier", false, $.hasTag(_TagClass.universal, 16)),
new $.ComponentSpec("hashValue", false, $.hasTag(_TagClass.universal, 3)),
];
/**
* @summary The Trailing Root Component Types of HASH
* @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_HASH = [];
/**
* @summary The Extension Addition Component Types of HASH
* @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_HASH = [];
/**
* @summary Returns a function that will decode an ASN.1 element into a(n) HASH
* @function
* @param {_Element} el The element being decoded.
* @returns A function that will decode an ASN.1 element.
*/
export function _get_decoder_for_HASH(_decode_ToBeHashed) {
return function (el) {
const sequence = el.sequence;
if (sequence.length < 2) {
throw new _ConstructionError("HASH contained only " +
sequence.length.toString() +
" elements.");
}
sequence[0].name = "algorithmIdentifier";
sequence[1].name = "hashValue";
let algorithmIdentifier;
let hashValue;
algorithmIdentifier = _decode_AlgorithmIdentifier(sequence[0]);
hashValue = $._decodeBitString(sequence[1]);
return new HASH(algorithmIdentifier, hashValue, sequence.slice(2));
};
}
/**
* @summary Returns a function that will encode a(n) HASH into an ASN.1 Element.
* @function
* @returns A function that will encode a(n) HASH as an ASN.1 element.
*/
export function _get_encoder_for_HASH(_encode_ToBeHashed) {
return function (value, _elGetter) {
const components = [
/* REQUIRED */ _encode_AlgorithmIdentifier(value.algorithmIdentifier, $.BER),
/* REQUIRED */ $._encodeBitString(value.hashValue, $.BER),
...value._unrecognizedExtensionsList ?? [],
];
return $._encodeSequence(components, $.DER);
};
}
/* eslint-enable */