@wildboar/pki-stub
Version:
X.510 PKI-Stub ASN.1 data structures in TypeScript
149 lines • 5.34 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports._get_encoder_for_HASH = exports._get_decoder_for_HASH = exports._extension_additions_list_spec_for_HASH = exports._root_component_type_list_2_spec_for_HASH = exports._root_component_type_list_1_spec_for_HASH = exports.HASH = void 0;
/* eslint-disable */
const asn1_ts_1 = require("asn1-ts");
const $ = require("asn1-ts/dist/node/functional");
const AlgorithmIdentifier_ta_1 = require("../PKI-Stub/AlgorithmIdentifier.ta");
/* START_OF_SYMBOL_DEFINITION HASH */
/**
* @summary HASH
* @description
*
* ### ASN.1 Definition:
*
* ```asn1
* HASH{ToBeHashed} ::= SEQUENCE {
* algorithmIdentifier AlgorithmIdentifier{{SupportedAlgorithms}},
* hashValue BIT STRING,
* ... }
* ```
*
* @class
*/
class HASH {
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);
}
}
exports.HASH = HASH;
/* END_OF_SYMBOL_DEFINITION HASH */
/* START_OF_SYMBOL_DEFINITION _root_component_type_list_1_spec_for_HASH */
/**
* @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
*/
exports._root_component_type_list_1_spec_for_HASH = [
new $.ComponentSpec("algorithmIdentifier", false, $.hasTag(asn1_ts_1.ASN1TagClass.universal, 16), undefined, undefined),
new $.ComponentSpec("hashValue", false, $.hasTag(asn1_ts_1.ASN1TagClass.universal, 3), undefined, undefined),
];
/* END_OF_SYMBOL_DEFINITION _root_component_type_list_1_spec_for_HASH */
/* START_OF_SYMBOL_DEFINITION _root_component_type_list_2_spec_for_HASH */
/**
* @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
*/
exports._root_component_type_list_2_spec_for_HASH = [];
/* END_OF_SYMBOL_DEFINITION _root_component_type_list_2_spec_for_HASH */
/* START_OF_SYMBOL_DEFINITION _extension_additions_list_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
*/
exports._extension_additions_list_spec_for_HASH = [];
/* END_OF_SYMBOL_DEFINITION _extension_additions_list_spec_for_HASH */
/* START_OF_SYMBOL_DEFINITION _get_decoder_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.
*/
function _get_decoder_for_HASH(_decode_ToBeHashed) {
return function (el) {
const sequence = el.sequence;
if (sequence.length < 2) {
throw new asn1_ts_1.ASN1ConstructionError("HASH contained only " +
sequence.length.toString() +
" elements.");
}
sequence[0].name = "algorithmIdentifier";
sequence[1].name = "hashValue";
let algorithmIdentifier;
let hashValue;
algorithmIdentifier = AlgorithmIdentifier_ta_1._decode_AlgorithmIdentifier(sequence[0]);
hashValue = $._decodeBitString(sequence[1]);
return new HASH(algorithmIdentifier, hashValue, sequence.slice(2));
};
}
exports._get_decoder_for_HASH = _get_decoder_for_HASH;
/* END_OF_SYMBOL_DEFINITION _get_decoder_for_HASH */
/* START_OF_SYMBOL_DEFINITION _get_encoder_for_HASH */
/**
* @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.
*/
function _get_encoder_for_HASH(_encode_ToBeHashed) {
return function (value, elGetter) {
return $._encodeSequence([]
.concat([
/* REQUIRED */ AlgorithmIdentifier_ta_1._encode_AlgorithmIdentifier(value.algorithmIdentifier, $.BER),
/* REQUIRED */ $._encodeBitString(value.hashValue, $.BER),
], value._unrecognizedExtensionsList
? value._unrecognizedExtensionsList
: [])
.filter((c) => !!c), $.BER);
};
}
exports._get_encoder_for_HASH = _get_encoder_for_HASH;
/* END_OF_SYMBOL_DEFINITION _get_encoder_for_HASH */
/* eslint-enable */
//# sourceMappingURL=HASH.ta.js.map