@wildboar/pki-stub
Version:
X.510 PKI-Stub ASN.1 data structures in TypeScript
176 lines (175 loc) • 6.19 kB
JavaScript
/* eslint-disable */
import { ASN1TagClass as _TagClass, } from "@wildboar/asn1";
import * as $ from "@wildboar/asn1/functional";
import { _enum_for_ObjectDigestInfo_digestedObjectType, _decode_ObjectDigestInfo_digestedObjectType, _encode_ObjectDigestInfo_digestedObjectType, } from "../PKI-Stub/ObjectDigestInfo-digestedObjectType.ta.mjs";
import { _decode_AlgorithmIdentifier, _encode_AlgorithmIdentifier, } from "../PKI-Stub/AlgorithmIdentifier.ta.mjs";
/**
* @summary ObjectDigestInfo
* @description
*
* ### ASN.1 Definition:
*
* ```asn1
* ObjectDigestInfo ::= SEQUENCE {
* digestedObjectType ENUMERATED {
* publicKey (0),
* publicKeyCert (1),
* otherObjectTypes (2)},
* otherObjectTypeID OBJECT IDENTIFIER OPTIONAL,
* digestAlgorithm AlgorithmIdentifier{{SupportedAlgorithms}},
* objectDigest BIT STRING,
* ... }
* ```
*
*/
export class ObjectDigestInfo {
digestedObjectType;
otherObjectTypeID;
digestAlgorithm;
objectDigest;
_unrecognizedExtensionsList;
constructor(
/**
* @summary `digestedObjectType`.
* @public
* @readonly
*/
digestedObjectType,
/**
* @summary `otherObjectTypeID`.
* @public
* @readonly
*/
otherObjectTypeID,
/**
* @summary `digestAlgorithm`.
* @public
* @readonly
*/
digestAlgorithm,
/**
* @summary `objectDigest`.
* @public
* @readonly
*/
objectDigest,
/**
* @summary Extensions that are not recognized.
* @public
* @readonly
*/
_unrecognizedExtensionsList = []) {
this.digestedObjectType = digestedObjectType;
this.otherObjectTypeID = otherObjectTypeID;
this.digestAlgorithm = digestAlgorithm;
this.objectDigest = objectDigest;
this._unrecognizedExtensionsList = _unrecognizedExtensionsList;
}
/**
* @summary Restructures an object into a ObjectDigestInfo
* @description
*
* This takes an `object` and converts it to a `ObjectDigestInfo`.
*
* @public
* @static
* @method
* @param {Object} _o An object having all of the keys and values of a `ObjectDigestInfo`.
* @returns {ObjectDigestInfo}
*/
static _from_object(_o) {
return new ObjectDigestInfo(_o.digestedObjectType, _o.otherObjectTypeID, _o.digestAlgorithm, _o.objectDigest, _o._unrecognizedExtensionsList);
}
/**
* @summary The enum used as the type of the component `digestedObjectType`
* @public
* @static
*/
static _enum_for_digestedObjectType = _enum_for_ObjectDigestInfo_digestedObjectType;
}
/**
* @summary The Leading Root Component Types of ObjectDigestInfo
* @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_ObjectDigestInfo = [
new $.ComponentSpec("digestedObjectType", false, $.hasTag(_TagClass.universal, 10)),
new $.ComponentSpec("otherObjectTypeID", true, $.hasTag(_TagClass.universal, 6)),
new $.ComponentSpec("digestAlgorithm", false, $.hasTag(_TagClass.universal, 16)),
new $.ComponentSpec("objectDigest", false, $.hasTag(_TagClass.universal, 3)),
];
/**
* @summary The Trailing Root Component Types of ObjectDigestInfo
* @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_ObjectDigestInfo = [];
/**
* @summary The Extension Addition Component Types of ObjectDigestInfo
* @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_ObjectDigestInfo = [];
/**
* @summary Decodes an ASN.1 element into a(n) ObjectDigestInfo
* @function
* @param {_Element} el The element being decoded.
* @returns {ObjectDigestInfo} The decoded data structure.
*/
export function _decode_ObjectDigestInfo(el) {
let digestedObjectType;
let otherObjectTypeID;
let digestAlgorithm;
let objectDigest;
let _unrecognizedExtensionsList = [];
const callbacks = {
digestedObjectType: (_el) => {
digestedObjectType =
_decode_ObjectDigestInfo_digestedObjectType(_el);
},
otherObjectTypeID: (_el) => {
otherObjectTypeID = $._decodeObjectIdentifier(_el);
},
digestAlgorithm: (_el) => {
digestAlgorithm = _decode_AlgorithmIdentifier(_el);
},
objectDigest: (_el) => {
objectDigest = $._decodeBitString(_el);
},
};
$._parse_sequence(el, callbacks, _root_component_type_list_1_spec_for_ObjectDigestInfo, _extension_additions_list_spec_for_ObjectDigestInfo, _root_component_type_list_2_spec_for_ObjectDigestInfo, (ext) => {
_unrecognizedExtensionsList.push(ext);
});
return new ObjectDigestInfo(digestedObjectType, otherObjectTypeID, digestAlgorithm, objectDigest, _unrecognizedExtensionsList);
}
/**
* @summary Encodes a(n) ObjectDigestInfo 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 ObjectDigestInfo, encoded as an ASN.1 Element.
*/
export function _encode_ObjectDigestInfo(value, _elGetter) {
const components = [
/* REQUIRED */ _encode_ObjectDigestInfo_digestedObjectType(value.digestedObjectType, $.BER),
...value._unrecognizedExtensionsList ?? [],
];
if (value.otherObjectTypeID) {
const c = _encode_ObjectDigestInfo_digestedObjectType(value.digestedObjectType, $.BER);
components.push(c);
}
components.push(_encode_AlgorithmIdentifier(value.digestAlgorithm, $.BER));
components.push($._encodeBitString(value.objectDigest, $.BER));
components.push(...value._unrecognizedExtensionsList);
return $._encodeSequence(components, $.BER);
}
/* eslint-enable */