@wildboar/pki-stub
Version:
X.510 PKI-Stub ASN.1 data structures in TypeScript
130 lines (129 loc) • 4.36 kB
JavaScript
/* eslint-disable */
import { ASN1TagClass as _TagClass, ASN1ConstructionError as _ConstructionError, } from "@wildboar/asn1";
import * as $ from "@wildboar/asn1/functional";
import { _decode_AlgorithmIdentifier, _encode_AlgorithmIdentifier, } from "../PKI-Stub/AlgorithmIdentifier.ta.mjs";
import { _decode_PublicKey, _encode_PublicKey, } from "../PKI-Stub/PublicKey.ta.mjs";
/**
* @summary SubjectPublicKeyInfo
* @description
*
* ### ASN.1 Definition:
*
* ```asn1
* SubjectPublicKeyInfo ::= SEQUENCE {
* algorithm AlgorithmIdentifier{{SupportedAlgorithms}},
* subjectPublicKey PublicKey,
* ... }
* ```
*
*/
export class SubjectPublicKeyInfo {
algorithm;
subjectPublicKey;
_unrecognizedExtensionsList;
constructor(
/**
* @summary `algorithm`.
* @public
* @readonly
*/
algorithm,
/**
* @summary `subjectPublicKey`.
* @public
* @readonly
*/
subjectPublicKey,
/**
* @summary Extensions that are not recognized.
* @public
* @readonly
*/
_unrecognizedExtensionsList = []) {
this.algorithm = algorithm;
this.subjectPublicKey = subjectPublicKey;
this._unrecognizedExtensionsList = _unrecognizedExtensionsList;
}
/**
* @summary Restructures an object into a SubjectPublicKeyInfo
* @description
*
* This takes an `object` and converts it to a `SubjectPublicKeyInfo`.
*
* @public
* @static
* @method
* @param {Object} _o An object having all of the keys and values of a `SubjectPublicKeyInfo`.
* @returns {SubjectPublicKeyInfo}
*/
static _from_object(_o) {
return new SubjectPublicKeyInfo(_o.algorithm, _o.subjectPublicKey, _o._unrecognizedExtensionsList);
}
}
/**
* @summary The Leading Root Component Types of SubjectPublicKeyInfo
* @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_SubjectPublicKeyInfo = [
new $.ComponentSpec("algorithm", false, $.hasTag(_TagClass.universal, 16)),
new $.ComponentSpec("subjectPublicKey", false, $.hasTag(_TagClass.universal, 3)),
];
/**
* @summary The Trailing Root Component Types of SubjectPublicKeyInfo
* @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_SubjectPublicKeyInfo = [];
/**
* @summary The Extension Addition Component Types of SubjectPublicKeyInfo
* @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_SubjectPublicKeyInfo = [];
/**
* @summary Decodes an ASN.1 element into a(n) SubjectPublicKeyInfo
* @function
* @param {_Element} el The element being decoded.
* @returns {SubjectPublicKeyInfo} The decoded data structure.
*/
export function _decode_SubjectPublicKeyInfo(el) {
const sequence = el.sequence;
if (sequence.length < 2) {
throw new _ConstructionError("SubjectPublicKeyInfo contained only " +
sequence.length.toString() +
" elements.");
}
sequence[0].name = "algorithm";
sequence[1].name = "subjectPublicKey";
let algorithm;
let subjectPublicKey;
algorithm = _decode_AlgorithmIdentifier(sequence[0]);
subjectPublicKey = _decode_PublicKey(sequence[1]);
return new SubjectPublicKeyInfo(algorithm, subjectPublicKey, sequence.slice(2));
}
/**
* @summary Encodes a(n) SubjectPublicKeyInfo 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 SubjectPublicKeyInfo, encoded as an ASN.1 Element.
*/
export function _encode_SubjectPublicKeyInfo(value, _elGetter) {
const components = [
/* REQUIRED */ _encode_AlgorithmIdentifier(value.algorithm, $.BER),
/* REQUIRED */ _encode_PublicKey(value.subjectPublicKey, $.BER),
...value._unrecognizedExtensionsList ?? [],
];
return $._encodeSequence(components, $.BER);
}
/* eslint-enable */