@wildboar/pki-stub
Version:
X.510 PKI-Stub ASN.1 data structures in TypeScript
128 lines (127 loc) • 3.92 kB
JavaScript
/* eslint-disable */
import { ASN1ConstructionError as _ConstructionError, ASN1TagClass as _TagClass, } from "@wildboar/asn1";
import * as $ from "@wildboar/asn1/functional";
/**
* @summary AttributeTypeAndValue
* @description
*
* ### ASN.1 Definition:
*
* ```asn1
* AttributeTypeAndValue ::= SEQUENCE {
* type ATTRIBUTE.&id({SupportedAttributes}),
* value ATTRIBUTE.&Type({SupportedAttributes}{@type}),
* ... }
* ```
*
*/
export class AttributeTypeAndValue {
type_;
value;
_unrecognizedExtensionsList;
constructor(
/**
* @summary `type_`.
* @public
* @readonly
*/
type_,
/**
* @summary `value`.
* @public
* @readonly
*/
value,
/**
* @summary Extensions that are not recognized.
* @public
* @readonly
*/
_unrecognizedExtensionsList = []) {
this.type_ = type_;
this.value = value;
this._unrecognizedExtensionsList = _unrecognizedExtensionsList;
}
/**
* @summary Restructures an object into a AttributeTypeAndValue
* @description
*
* This takes an `object` and converts it to a `AttributeTypeAndValue`.
*
* @public
* @static
* @method
* @param {Object} _o An object having all of the keys and values of a `AttributeTypeAndValue`.
* @returns {AttributeTypeAndValue}
*/
static _from_object(_o) {
return new AttributeTypeAndValue(_o.type_, _o.value, _o._unrecognizedExtensionsList);
}
}
/**
* @summary The Leading Root Component Types of AttributeTypeAndValue
* @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_AttributeTypeAndValue = [
new $.ComponentSpec("type", false, $.hasTag(_TagClass.universal, 6)),
new $.ComponentSpec("value", false, $.hasAnyTag),
];
/**
* @summary The Trailing Root Component Types of AttributeTypeAndValue
* @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_AttributeTypeAndValue = [];
/**
* @summary The Extension Addition Component Types of AttributeTypeAndValue
* @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_AttributeTypeAndValue = [];
/**
* @summary Decodes an ASN.1 element into a(n) AttributeTypeAndValue
* @function
* @param {_Element} el The element being decoded.
* @returns {AttributeTypeAndValue} The decoded data structure.
*/
export function _decode_AttributeTypeAndValue(el) {
const sequence = el.sequence;
if (sequence.length < 2) {
throw new _ConstructionError("AttributeTypeAndValue contained only " +
sequence.length.toString() +
" elements.");
}
sequence[0].name = "type";
sequence[1].name = "value";
let type_;
let value;
type_ = $._decodeObjectIdentifier(sequence[0]);
value = sequence[1];
return new AttributeTypeAndValue(type_, value, sequence.slice(2));
}
/**
* @summary Encodes a(n) AttributeTypeAndValue 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 AttributeTypeAndValue, encoded as an ASN.1 Element.
*/
export function _encode_AttributeTypeAndValue(value) {
const components = [
$._encodeObjectIdentifier(value.type_, $.BER),
value.value,
...value._unrecognizedExtensionsList ?? [],
];
return $._encodeSequence(components, $.BER);
}
/* eslint-enable */