@wildboar/pkcs
Version:
Public Key Cryptography Standard PDUs in TypeScript
244 lines (243 loc) • 8.51 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";
import { _decode_KeyAccessFlags, _encode_KeyAccessFlags, } from "../PKCS-15/KeyAccessFlags.ta.mjs";
import { _decode_KeyUsageFlags, _encode_KeyUsageFlags, } from "../PKCS-15/KeyUsageFlags.ta.mjs";
import { _decode_Reference, _encode_Reference, } from "../PKCS-15/Reference.ta.mjs";
/**
* @summary CommonKeyAttributes
* @description
*
* ### ASN.1 Definition:
*
* ```asn1
* CommonKeyAttributes ::= SEQUENCE {
* iD Identifier,
* usage KeyUsageFlags,
* native BOOLEAN DEFAULT TRUE,
* accessFlags KeyAccessFlags OPTIONAL,
* keyReference Reference OPTIONAL,
* startDate GeneralizedTime OPTIONAL,
* endDate [0] GeneralizedTime OPTIONAL,
* ... -- For future extensions
* }
* ```
*
*/
export class CommonKeyAttributes {
iD;
usage;
native;
accessFlags;
keyReference;
startDate;
endDate;
_unrecognizedExtensionsList;
constructor(
/**
* @summary `iD`.
* @public
* @readonly
*/
iD,
/**
* @summary `usage`.
* @public
* @readonly
*/
usage,
/**
* @summary `native`.
* @public
* @readonly
*/
native,
/**
* @summary `accessFlags`.
* @public
* @readonly
*/
accessFlags,
/**
* @summary `keyReference`.
* @public
* @readonly
*/
keyReference,
/**
* @summary `startDate`.
* @public
* @readonly
*/
startDate,
/**
* @summary `endDate`.
* @public
* @readonly
*/
endDate,
/**
* @summary Extensions that are not recognized.
* @public
* @readonly
*/
_unrecognizedExtensionsList = []) {
this.iD = iD;
this.usage = usage;
this.native = native;
this.accessFlags = accessFlags;
this.keyReference = keyReference;
this.startDate = startDate;
this.endDate = endDate;
this._unrecognizedExtensionsList = _unrecognizedExtensionsList;
}
/**
* @summary Restructures an object into a CommonKeyAttributes
* @description
*
* This takes an `object` and converts it to a `CommonKeyAttributes`.
*
* @public
* @static
* @method
* @param {Object} _o An object having all of the keys and values of a `CommonKeyAttributes`.
* @returns {CommonKeyAttributes}
*/
static _from_object(_o) {
return new CommonKeyAttributes(_o.iD, _o.usage, _o.native, _o.accessFlags, _o.keyReference, _o.startDate, _o.endDate, _o._unrecognizedExtensionsList);
}
/**
* @summary Getter that returns the default value for `native`.
* @public
* @static
* @method
*/
static get _default_value_for_native() {
return true;
}
}
/**
* @summary The Leading Root Component Types of CommonKeyAttributes
* @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_CommonKeyAttributes = [
new $.ComponentSpec("iD", false, $.hasTag(_TagClass.universal, 4)),
new $.ComponentSpec("usage", false, $.hasTag(_TagClass.universal, 3)),
new $.ComponentSpec("native", true, $.hasTag(_TagClass.universal, 1)),
new $.ComponentSpec("accessFlags", true, $.hasTag(_TagClass.universal, 3)),
new $.ComponentSpec("keyReference", true, $.hasTag(_TagClass.universal, 2)),
new $.ComponentSpec("startDate", true, $.hasTag(_TagClass.universal, 24)),
new $.ComponentSpec("endDate", true, $.hasTag(_TagClass.context, 0)),
];
/**
* @summary The Trailing Root Component Types of CommonKeyAttributes
* @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_CommonKeyAttributes = [];
/**
* @summary The Extension Addition Component Types of CommonKeyAttributes
* @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_CommonKeyAttributes = [];
let _cached_decoder_for_CommonKeyAttributes = null;
/**
* @summary Decodes an ASN.1 element into a(n) CommonKeyAttributes
* @function
* @param {_Element} el The element being decoded.
* @returns {CommonKeyAttributes} The decoded data structure.
*/
export function _decode_CommonKeyAttributes(el) {
if (!_cached_decoder_for_CommonKeyAttributes) {
_cached_decoder_for_CommonKeyAttributes = function (el) {
let iD;
let usage;
let native = CommonKeyAttributes._default_value_for_native;
let accessFlags;
let keyReference;
let startDate;
let endDate;
let _unrecognizedExtensionsList = [];
const callbacks = {
iD: (_el) => {
iD = _decode_Identifier(_el);
},
usage: (_el) => {
usage = _decode_KeyUsageFlags(_el);
},
native: (_el) => {
native = $._decodeBoolean(_el);
},
accessFlags: (_el) => {
accessFlags = _decode_KeyAccessFlags(_el);
},
keyReference: (_el) => {
keyReference = _decode_Reference(_el);
},
startDate: (_el) => {
startDate = $._decodeGeneralizedTime(_el);
},
endDate: (_el) => {
endDate = $._decode_implicit(() => $._decodeGeneralizedTime)(_el);
},
};
$._parse_sequence(el, callbacks, _root_component_type_list_1_spec_for_CommonKeyAttributes, _extension_additions_list_spec_for_CommonKeyAttributes, _root_component_type_list_2_spec_for_CommonKeyAttributes, (ext) => {
_unrecognizedExtensionsList.push(ext);
});
return new CommonKeyAttributes(iD, usage, native, accessFlags, keyReference, startDate, endDate, _unrecognizedExtensionsList);
};
}
return _cached_decoder_for_CommonKeyAttributes(el);
}
let _cached_encoder_for_CommonKeyAttributes = null;
/**
* @summary Encodes a(n) CommonKeyAttributes 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 CommonKeyAttributes, encoded as an ASN.1 Element.
*/
export function _encode_CommonKeyAttributes(value, elGetter) {
if (!_cached_encoder_for_CommonKeyAttributes) {
_cached_encoder_for_CommonKeyAttributes = function (value) {
return $._encodeSequence([]
.concat([
/* REQUIRED */ _encode_Identifier(value.iD, $.BER),
/* REQUIRED */ _encode_KeyUsageFlags(value.usage, $.BER),
/* IF_DEFAULT */ value.native === undefined ||
$.deepEq(value.native, CommonKeyAttributes._default_value_for_native)
? undefined
: $._encodeBoolean(value.native, $.BER),
/* IF_ABSENT */ value.accessFlags === undefined
? undefined
: _encode_KeyAccessFlags(value.accessFlags, $.BER),
/* IF_ABSENT */ value.keyReference === undefined
? undefined
: _encode_Reference(value.keyReference, $.BER),
/* IF_ABSENT */ value.startDate === undefined
? undefined
: $._encodeGeneralizedTime(value.startDate, $.BER),
/* IF_ABSENT */ value.endDate === undefined
? undefined
: $._encode_implicit(_TagClass.context, 0, () => $._encodeGeneralizedTime, $.BER)(value.endDate, $.BER),
], value._unrecognizedExtensionsList
? value._unrecognizedExtensionsList
: [])
.filter((c) => !!c), $.BER);
};
}
return _cached_encoder_for_CommonKeyAttributes(value, elGetter);
}
/* eslint-enable */