@wildboar/pkcs
Version:
Public Key Cryptography Standard PDUs in TypeScript
155 lines (154 loc) • 5.21 kB
JavaScript
/* eslint-disable */
import { ASN1TagClass as _TagClass, } from "@wildboar/asn1";
import * as $ from "@wildboar/asn1/functional";
import { _decode_AlgorithmIdentifier, _encode_AlgorithmIdentifier, } from "@wildboar/x500/AuthenticationFramework";
import { _decode_CertId, _encode_CertId, } from "../PKIXCRMF-2009/CertId.ta.mjs";
/**
* @summary OOBCertHash
* @description
*
* ### ASN.1 Definition:
*
* ```asn1
* OOBCertHash ::= SEQUENCE {
* hashAlg [0] AlgorithmIdentifier{DIGEST-ALGORITHM, {...}}
* OPTIONAL,
* certId [1] CertId OPTIONAL,
* hashVal BIT STRING
* -- hashVal is calculated over the DER encoding of the
* -- self-signed certificate with the identifier certID.
* }
* ```
*
*/
export class OOBCertHash {
hashAlg;
certId;
hashVal;
constructor(
/**
* @summary `hashAlg`.
* @public
* @readonly
*/
hashAlg,
/**
* @summary `certId`.
* @public
* @readonly
*/
certId,
/**
* @summary `hashVal`.
* @public
* @readonly
*/
hashVal) {
this.hashAlg = hashAlg;
this.certId = certId;
this.hashVal = hashVal;
}
/**
* @summary Restructures an object into a OOBCertHash
* @description
*
* This takes an `object` and converts it to a `OOBCertHash`.
*
* @public
* @static
* @method
* @param {Object} _o An object having all of the keys and values of a `OOBCertHash`.
* @returns {OOBCertHash}
*/
static _from_object(_o) {
return new OOBCertHash(_o.hashAlg, _o.certId, _o.hashVal);
}
}
/**
* @summary The Leading Root Component Types of OOBCertHash
* @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_OOBCertHash = [
new $.ComponentSpec("hashAlg", true, $.hasTag(_TagClass.context, 0)),
new $.ComponentSpec("certId", true, $.hasTag(_TagClass.universal, 16)),
new $.ComponentSpec("hashVal", false, $.hasTag(_TagClass.universal, 3)),
];
/**
* @summary The Trailing Root Component Types of OOBCertHash
* @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_OOBCertHash = [];
/**
* @summary The Extension Addition Component Types of OOBCertHash
* @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_OOBCertHash = [];
let _cached_decoder_for_OOBCertHash = null;
/**
* @summary Decodes an ASN.1 element into a(n) OOBCertHash
* @function
* @param {_Element} el The element being decoded.
* @returns {OOBCertHash} The decoded data structure.
*/
export function _decode_OOBCertHash(el) {
if (!_cached_decoder_for_OOBCertHash) {
_cached_decoder_for_OOBCertHash = function (el) {
let hashAlg;
let certId;
let hashVal;
const callbacks = {
hashAlg: (_el) => {
hashAlg = $._decode_explicit(() => _decode_AlgorithmIdentifier)(_el);
},
certId: (_el) => {
certId = $._decode_explicit(() => _decode_CertId)(_el);
},
hashVal: (_el) => {
hashVal = $._decodeBitString(_el);
},
};
$._parse_sequence(el, callbacks, _root_component_type_list_1_spec_for_OOBCertHash, _extension_additions_list_spec_for_OOBCertHash, _root_component_type_list_2_spec_for_OOBCertHash, undefined);
return new OOBCertHash(hashAlg, certId, hashVal);
};
}
return _cached_decoder_for_OOBCertHash(el);
}
let _cached_encoder_for_OOBCertHash = null;
/**
* @summary Encodes a(n) OOBCertHash 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 OOBCertHash, encoded as an ASN.1 Element.
*/
export function _encode_OOBCertHash(value, elGetter) {
if (!_cached_encoder_for_OOBCertHash) {
_cached_encoder_for_OOBCertHash = function (value) {
return $._encodeSequence([]
.concat([
/* IF_ABSENT */ value.hashAlg === undefined
? undefined
: $._encode_explicit(_TagClass.context, 0, () => _encode_AlgorithmIdentifier, $.BER)(value.hashAlg, $.BER),
/* IF_ABSENT */ value.certId === undefined
? undefined
: $._encode_explicit(_TagClass.context, 1, () => _encode_CertId, $.BER)(value.certId, $.BER),
/* REQUIRED */ $._encodeBitString(value.hashVal, $.BER),
])
.filter((c) => !!c), $.BER);
};
}
return _cached_encoder_for_OOBCertHash(value, elGetter);
}
/* eslint-enable */