@wildboar/pkcs
Version:
Public Key Cryptography Standard PDUs in TypeScript
132 lines (131 loc) • 4.05 kB
JavaScript
/* eslint-disable */
import { ASN1ConstructionError as _ConstructionError, ASN1TagClass as _TagClass, } from "@wildboar/asn1";
import * as $ from "@wildboar/asn1/functional";
/**
* @summary CertBag
* @description
*
* ### ASN.1 Definition:
*
* ```asn1
* CertBag ::= SEQUENCE {
* certId BAG-TYPE.&id ({CertTypes}),
* certValue [0] EXPLICIT BAG-TYPE.&Type ({CertTypes}{@certId})
* }
* ```
*
*/
export class CertBag {
certId;
certValue;
constructor(
/**
* @summary `certId`.
* @public
* @readonly
*/
certId,
/**
* @summary `certValue`.
* @public
* @readonly
*/
certValue) {
this.certId = certId;
this.certValue = certValue;
}
/**
* @summary Restructures an object into a CertBag
* @description
*
* This takes an `object` and converts it to a `CertBag`.
*
* @public
* @static
* @method
* @param {Object} _o An object having all of the keys and values of a `CertBag`.
* @returns {CertBag}
*/
static _from_object(_o) {
return new CertBag(_o.certId, _o.certValue);
}
}
/**
* @summary The Leading Root Component Types of CertBag
* @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_CertBag = [
new $.ComponentSpec("certId", false, $.hasTag(_TagClass.universal, 6)),
new $.ComponentSpec("certValue", false, $.hasTag(_TagClass.context, 0)),
];
/**
* @summary The Trailing Root Component Types of CertBag
* @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_CertBag = [];
/**
* @summary The Extension Addition Component Types of CertBag
* @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_CertBag = [];
let _cached_decoder_for_CertBag = null;
/**
* @summary Decodes an ASN.1 element into a(n) CertBag
* @function
* @param {_Element} el The element being decoded.
* @returns {CertBag} The decoded data structure.
*/
export function _decode_CertBag(el) {
if (!_cached_decoder_for_CertBag) {
_cached_decoder_for_CertBag = function (el) {
const sequence = el.sequence;
if (sequence.length < 2) {
throw new _ConstructionError("CertBag contained only " +
sequence.length.toString() +
" elements.");
}
sequence[0].name = "certId";
sequence[1].name = "certValue";
let certId;
let certValue;
certId = $._decodeObjectIdentifier(sequence[0]);
certValue = $._decode_explicit(() => $._decodeAny)(sequence[1]);
return new CertBag(certId, certValue);
};
}
return _cached_decoder_for_CertBag(el);
}
let _cached_encoder_for_CertBag = null;
/**
* @summary Encodes a(n) CertBag 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 CertBag, encoded as an ASN.1 Element.
*/
export function _encode_CertBag(value, elGetter) {
if (!_cached_encoder_for_CertBag) {
_cached_encoder_for_CertBag = function (value) {
return $._encodeSequence([]
.concat([
/* REQUIRED */ $._encodeObjectIdentifier(value.certId, $.BER),
/* REQUIRED */ $._encode_explicit(_TagClass.context, 0, () => $._encodeAny, $.BER)(value.certValue, $.BER),
])
.filter((c) => !!c), $.BER);
};
}
return _cached_encoder_for_CertBag(value, elGetter);
}
/* eslint-enable */