@wildboar/pki-stub
Version:
X.510 PKI-Stub ASN.1 data structures in TypeScript
173 lines (172 loc) • 6.18 kB
JavaScript
/* eslint-disable */
import { ASN1TagClass as _TagClass, } from "@wildboar/asn1";
import * as $ from "@wildboar/asn1/functional";
/**
* @summary PersonalName
* @description
*
* ### ASN.1 Definition:
*
* ```asn1
* PersonalName ::= SET {
* surname [0] PrintableString(SIZE (1..ub-surname-length)),
* given-name
* [1] PrintableString(SIZE (1..ub-given-name-length)) OPTIONAL,
* initials
* [2] PrintableString(SIZE (1..ub-initials-length)) OPTIONAL,
* generation-qualifier
* [3] PrintableString(SIZE (1..ub-generation-qualifier-length)) OPTIONAL }
* ```
*
*/
export class PersonalName {
surname;
given_name;
initials;
generation_qualifier;
constructor(
/**
* @summary `surname`.
* @public
* @readonly
*/
surname,
/**
* @summary `given_name`.
* @public
* @readonly
*/
given_name,
/**
* @summary `initials`.
* @public
* @readonly
*/
initials,
/**
* @summary `generation_qualifier`.
* @public
* @readonly
*/
generation_qualifier) {
this.surname = surname;
this.given_name = given_name;
this.initials = initials;
this.generation_qualifier = generation_qualifier;
}
/**
* @summary Restructures an object into a PersonalName
* @description
*
* This takes an `object` and converts it to a `PersonalName`.
*
* @public
* @static
* @method
* @param {Object} _o An object having all of the keys and values of a `PersonalName`.
* @returns {PersonalName}
*/
static _from_object(_o) {
return new PersonalName(_o.surname, _o.given_name, _o.initials, _o.generation_qualifier);
}
}
/**
* @summary The Leading Root Component Types of PersonalName
* @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_PersonalName = [
new $.ComponentSpec("surname", false, $.hasTag(_TagClass.context, 0)),
new $.ComponentSpec("given-name", true, $.hasTag(_TagClass.context, 1)),
new $.ComponentSpec("initials", true, $.hasTag(_TagClass.context, 2)),
new $.ComponentSpec("generation-qualifier", true, $.hasTag(_TagClass.context, 3)),
];
/**
* @summary The Trailing Root Component Types of PersonalName
* @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_PersonalName = [];
/**
* @summary The Extension Addition Component Types of PersonalName
* @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_PersonalName = [];
let _cached_decoder_for_PersonalName = null;
/**
* @summary Decodes an ASN.1 element into a(n) PersonalName
* @function
* @param {_Element} el The element being decoded.
* @returns {PersonalName} The decoded data structure.
*/
export function _decode_PersonalName(el) {
if (!_cached_decoder_for_PersonalName) {
_cached_decoder_for_PersonalName = function (el) {
/* START_OF_SET_COMPONENT_DECLARATIONS */
let surname;
let given_name;
let initials;
let generation_qualifier;
/* END_OF_SET_COMPONENT_DECLARATIONS */
const callbacks = {
surname: (_el) => {
surname = $._decode_explicit(() => $._decodePrintableString)(_el);
},
"given-name": (_el) => {
given_name = $._decode_explicit(() => $._decodePrintableString)(_el);
},
initials: (_el) => {
initials = $._decode_explicit(() => $._decodePrintableString)(_el);
},
"generation-qualifier": (_el) => {
generation_qualifier = $._decode_explicit(() => $._decodePrintableString)(_el);
},
};
$._parse_set(el, callbacks, _root_component_type_list_1_spec_for_PersonalName, _extension_additions_list_spec_for_PersonalName, _root_component_type_list_2_spec_for_PersonalName, undefined);
return new PersonalName(
/* SET_CONSTRUCTOR_CALL */ surname, given_name, initials, generation_qualifier);
};
}
return _cached_decoder_for_PersonalName(el);
}
let _cached_encoder_for_PersonalName = null;
/**
* @summary Encodes a(n) PersonalName 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 PersonalName, encoded as an ASN.1 Element.
*/
export function _encode_PersonalName(value, elGetter) {
if (!_cached_encoder_for_PersonalName) {
_cached_encoder_for_PersonalName = function (value) {
return $._encodeSet([]
.concat([
/* REQUIRED */ $._encode_explicit(_TagClass.context, 0, () => $._encodePrintableString, $.BER)(value.surname, $.BER),
/* IF_ABSENT */ value.given_name === undefined
? undefined
: $._encode_explicit(_TagClass.context, 1, () => $._encodePrintableString, $.BER)(value.given_name, $.BER),
/* IF_ABSENT */ value.initials === undefined
? undefined
: $._encode_explicit(_TagClass.context, 2, () => $._encodePrintableString, $.BER)(value.initials, $.BER),
/* IF_ABSENT */ value.generation_qualifier ===
undefined
? undefined
: $._encode_explicit(_TagClass.context, 3, () => $._encodePrintableString, $.BER)(value.generation_qualifier, $.BER),
])
.filter((c) => !!c), $.BER);
};
}
return _cached_encoder_for_PersonalName(value, elGetter);
}
/* eslint-enable */