@wildboar/ocsp
Version:
Online Certificate Status Protocol PDUs in TypeScript
161 lines (160 loc) • 5.45 kB
JavaScript
/* eslint-disable */
import { ASN1ConstructionError as _ConstructionError, ASN1TagClass as _TagClass, } from "@wildboar/asn1";
import * as $ from "@wildboar/asn1/functional";
import { _decode_AlgorithmIdentifier, _encode_AlgorithmIdentifier, _decode_CertificateSerialNumber, _encode_CertificateSerialNumber, } from "@wildboar/pki-stub";
/**
* @summary CertID
* @description
*
* ### ASN.1 Definition:
*
* ```asn1
* CertID ::= SEQUENCE {
* hashAlgorithm AlgorithmIdentifier
* {DIGEST-ALGORITHM, {...}},
* issuerNameHash OCTET STRING, -- Hash of issuer's DN
* issuerKeyHash OCTET STRING, -- Hash of issuer's public key
* serialNumber CertificateSerialNumber }
* ```
*
*/
export class CertID {
hashAlgorithm;
issuerNameHash;
issuerKeyHash;
serialNumber;
constructor(
/**
* @summary `hashAlgorithm`.
* @public
* @readonly
*/
hashAlgorithm,
/**
* @summary `issuerNameHash`.
* @public
* @readonly
*/
issuerNameHash,
/**
* @summary `issuerKeyHash`.
* @public
* @readonly
*/
issuerKeyHash,
/**
* @summary `serialNumber`.
* @public
* @readonly
*/
serialNumber) {
this.hashAlgorithm = hashAlgorithm;
this.issuerNameHash = issuerNameHash;
this.issuerKeyHash = issuerKeyHash;
this.serialNumber = serialNumber;
}
/**
* @summary Restructures an object into a CertID
* @description
*
* This takes an `object` and converts it to a `CertID`.
*
* @public
* @static
* @method
* @param {Object} _o An object having all of the keys and values of a `CertID`.
* @returns {CertID}
*/
static _from_object(_o) {
return new CertID(_o.hashAlgorithm, _o.issuerNameHash, _o.issuerKeyHash, _o.serialNumber);
}
}
/**
* @summary The Leading Root Component Types of CertID
* @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_CertID = [
new $.ComponentSpec("hashAlgorithm", false, $.hasTag(_TagClass.universal, 16)),
new $.ComponentSpec("issuerNameHash", false, $.hasTag(_TagClass.universal, 4)),
new $.ComponentSpec("issuerKeyHash", false, $.hasTag(_TagClass.universal, 4)),
new $.ComponentSpec("serialNumber", false, $.hasTag(_TagClass.universal, 2)),
];
/**
* @summary The Trailing Root Component Types of CertID
* @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_CertID = [];
/**
* @summary The Extension Addition Component Types of CertID
* @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_CertID = [];
let _cached_decoder_for_CertID = null;
/**
* @summary Decodes an ASN.1 element into a(n) CertID
* @function
* @param {_Element} el The element being decoded.
* @returns {CertID} The decoded data structure.
*/
export function _decode_CertID(el) {
if (!_cached_decoder_for_CertID) {
_cached_decoder_for_CertID = function (el) {
const sequence = el.sequence;
if (sequence.length < 4) {
throw new _ConstructionError("CertID contained only " +
sequence.length.toString() +
" elements.");
}
sequence[0].name = "hashAlgorithm";
sequence[1].name = "issuerNameHash";
sequence[2].name = "issuerKeyHash";
sequence[3].name = "serialNumber";
let hashAlgorithm;
let issuerNameHash;
let issuerKeyHash;
let serialNumber;
hashAlgorithm = _decode_AlgorithmIdentifier(sequence[0]);
issuerNameHash = $._decodeOctetString(sequence[1]);
issuerKeyHash = $._decodeOctetString(sequence[2]);
serialNumber = _decode_CertificateSerialNumber(sequence[3]);
return new CertID(hashAlgorithm, issuerNameHash, issuerKeyHash, serialNumber);
};
}
return _cached_decoder_for_CertID(el);
}
let _cached_encoder_for_CertID = null;
/**
* @summary Encodes a(n) CertID 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 CertID, encoded as an ASN.1 Element.
*/
export function _encode_CertID(value, elGetter) {
if (!_cached_encoder_for_CertID) {
_cached_encoder_for_CertID = function (value) {
return $._encodeSequence([]
.concat([
/* REQUIRED */ _encode_AlgorithmIdentifier(value.hashAlgorithm, $.DER),
/* REQUIRED */ $._encodeOctetString(value.issuerNameHash, $.DER),
/* REQUIRED */ $._encodeOctetString(value.issuerKeyHash, $.DER),
/* REQUIRED */ _encode_CertificateSerialNumber(value.serialNumber, $.DER),
])
.filter((c) => !!c), $.DER);
};
}
return _cached_encoder_for_CertID(value, elGetter);
}
/* eslint-enable */