@wildboar/pkcs
Version:
Public Key Cryptography Standard PDUs in TypeScript
158 lines (157 loc) • 5.35 kB
JavaScript
/* eslint-disable */
import { ASN1TagClass as _TagClass, } from "@wildboar/asn1";
import * as $ from "@wildboar/asn1/functional";
import { _decode_Identifier, _encode_Identifier, } from "../PKCS-15/Identifier.ta.mjs";
/**
* @summary AuthKeyAttributes
* @description
*
* ### ASN.1 Definition:
*
* ```asn1
* AuthKeyAttributes ::= SEQUENCE {
* derivedKey BOOLEAN DEFAULT TRUE,
* authKeyId Identifier,
* ... -- For future extensions
* }
* ```
*
*/
export class AuthKeyAttributes {
derivedKey;
authKeyId;
_unrecognizedExtensionsList;
constructor(
/**
* @summary `derivedKey`.
* @public
* @readonly
*/
derivedKey,
/**
* @summary `authKeyId`.
* @public
* @readonly
*/
authKeyId,
/**
* @summary Extensions that are not recognized.
* @public
* @readonly
*/
_unrecognizedExtensionsList = []) {
this.derivedKey = derivedKey;
this.authKeyId = authKeyId;
this._unrecognizedExtensionsList = _unrecognizedExtensionsList;
}
/**
* @summary Restructures an object into a AuthKeyAttributes
* @description
*
* This takes an `object` and converts it to a `AuthKeyAttributes`.
*
* @public
* @static
* @method
* @param {Object} _o An object having all of the keys and values of a `AuthKeyAttributes`.
* @returns {AuthKeyAttributes}
*/
static _from_object(_o) {
return new AuthKeyAttributes(_o.derivedKey, _o.authKeyId, _o._unrecognizedExtensionsList);
}
/**
* @summary Getter that returns the default value for `derivedKey`.
* @public
* @static
* @method
*/
static get _default_value_for_derivedKey() {
return true;
}
}
/**
* @summary The Leading Root Component Types of AuthKeyAttributes
* @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_AuthKeyAttributes = [
new $.ComponentSpec("derivedKey", true, $.hasTag(_TagClass.universal, 1)),
new $.ComponentSpec("authKeyId", false, $.hasTag(_TagClass.universal, 4)),
];
/**
* @summary The Trailing Root Component Types of AuthKeyAttributes
* @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_AuthKeyAttributes = [];
/**
* @summary The Extension Addition Component Types of AuthKeyAttributes
* @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_AuthKeyAttributes = [];
let _cached_decoder_for_AuthKeyAttributes = null;
/**
* @summary Decodes an ASN.1 element into a(n) AuthKeyAttributes
* @function
* @param {_Element} el The element being decoded.
* @returns {AuthKeyAttributes} The decoded data structure.
*/
export function _decode_AuthKeyAttributes(el) {
if (!_cached_decoder_for_AuthKeyAttributes) {
_cached_decoder_for_AuthKeyAttributes = function (el) {
let derivedKey = AuthKeyAttributes._default_value_for_derivedKey;
let authKeyId;
let _unrecognizedExtensionsList = [];
const callbacks = {
derivedKey: (_el) => {
derivedKey = $._decodeBoolean(_el);
},
authKeyId: (_el) => {
authKeyId = _decode_Identifier(_el);
},
};
$._parse_sequence(el, callbacks, _root_component_type_list_1_spec_for_AuthKeyAttributes, _extension_additions_list_spec_for_AuthKeyAttributes, _root_component_type_list_2_spec_for_AuthKeyAttributes, (ext) => {
_unrecognizedExtensionsList.push(ext);
});
return new AuthKeyAttributes(derivedKey, authKeyId, _unrecognizedExtensionsList);
};
}
return _cached_decoder_for_AuthKeyAttributes(el);
}
let _cached_encoder_for_AuthKeyAttributes = null;
/**
* @summary Encodes a(n) AuthKeyAttributes 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 AuthKeyAttributes, encoded as an ASN.1 Element.
*/
export function _encode_AuthKeyAttributes(value, elGetter) {
if (!_cached_encoder_for_AuthKeyAttributes) {
_cached_encoder_for_AuthKeyAttributes = function (value) {
return $._encodeSequence([]
.concat([
/* IF_DEFAULT */ value.derivedKey === undefined ||
$.deepEq(value.derivedKey, AuthKeyAttributes._default_value_for_derivedKey)
? undefined
: $._encodeBoolean(value.derivedKey, $.BER),
/* REQUIRED */ _encode_Identifier(value.authKeyId, $.BER),
], value._unrecognizedExtensionsList
? value._unrecognizedExtensionsList
: [])
.filter((c) => !!c), $.BER);
};
}
return _cached_encoder_for_AuthKeyAttributes(value, elGetter);
}
/* eslint-enable */