@wildboar/pki-stub
Version:
X.510 PKI-Stub ASN.1 data structures in TypeScript
121 lines (120 loc) • 4.29 kB
JavaScript
/* eslint-disable */
import { ASN1ConstructionError as _ConstructionError, ASN1TagClass as _TagClass, } from "@wildboar/asn1";
import * as $ from "@wildboar/asn1/functional";
/**
* @summary ExtensionAttribute
* @description
*
* ### ASN.1 Definition:
*
* ```asn1
* ExtensionAttribute ::= SEQUENCE {
* extension-attribute-type
* [0] EXTENSION-ATTRIBUTE.&id({ExtensionAttributeTable}),
* extension-attribute-value
* [1] EXTENSION-ATTRIBUTE.&Type
* ({ExtensionAttributeTable}{@extension-attribute-type}) }
* ```
*
*/
export class ExtensionAttribute {
extension_attribute_type;
extension_attribute_value;
constructor(
/**
* @summary `extension_attribute_type`.
* @public
* @readonly
*/
extension_attribute_type,
/**
* @summary `extension_attribute_value`.
* @public
* @readonly
*/
extension_attribute_value) {
this.extension_attribute_type = extension_attribute_type;
this.extension_attribute_value = extension_attribute_value;
}
/**
* @summary Restructures an object into a ExtensionAttribute
* @description
*
* This takes an `object` and converts it to a `ExtensionAttribute`.
*
* @public
* @static
* @method
* @param {Object} _o An object having all of the keys and values of a `ExtensionAttribute`.
* @returns {ExtensionAttribute}
*/
static _from_object(_o) {
return new ExtensionAttribute(_o.extension_attribute_type, _o.extension_attribute_value);
}
}
/**
* @summary The Leading Root Component Types of ExtensionAttribute
* @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_ExtensionAttribute = [
new $.ComponentSpec("extension-attribute-type", false, $.hasTag(_TagClass.context, 0)),
new $.ComponentSpec("extension-attribute-value", false, $.hasTag(_TagClass.context, 1)),
];
/**
* @summary The Trailing Root Component Types of ExtensionAttribute
* @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_ExtensionAttribute = [];
/**
* @summary The Extension Addition Component Types of ExtensionAttribute
* @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_ExtensionAttribute = [];
/**
* @summary Decodes an ASN.1 element into a(n) ExtensionAttribute
* @function
* @param {_Element} el The element being decoded.
* @returns {ExtensionAttribute} The decoded data structure.
*/
export function _decode_ExtensionAttribute(el) {
const sequence = el.sequence;
if (sequence.length < 2) {
throw new _ConstructionError("ExtensionAttribute contained only " +
sequence.length.toString() +
" elements.");
}
sequence[0].name = "extension-attribute-type";
sequence[1].name = "extension-attribute-value";
let extension_attribute_type;
let extension_attribute_value;
extension_attribute_type = $._decode_explicit(() => $._decodeInteger)(sequence[0]);
extension_attribute_value = $._decode_explicit(() => $._decodeAny)(sequence[1]);
return new ExtensionAttribute(extension_attribute_type, extension_attribute_value);
}
/**
* @summary Encodes a(n) ExtensionAttribute 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 ExtensionAttribute, encoded as an ASN.1 Element.
*/
export function _encode_ExtensionAttribute(value) {
const components = [
/* REQUIRED */ $._encode_explicit(_TagClass.context, 0, () => $._encodeInteger, $.BER)(value.extension_attribute_type, $.BER),
/* REQUIRED */ $._encode_explicit(_TagClass.context, 1, () => $._encodeAny, $.BER)(value.extension_attribute_value, $.BER),
];
return $._encodeSequence(components, $.BER);
}
/* eslint-enable */