@wildboar/pkcs
Version:
Public Key Cryptography Standard PDUs in TypeScript
280 lines (279 loc) • 9.61 kB
JavaScript
/* eslint-disable */
import { ASN1TagClass as _TagClass, } from "@wildboar/asn1";
import * as $ from "@wildboar/asn1/functional";
import { _decode_Path, _encode_Path } from "../PKCS-15/Path.ta.mjs";
import { _decode_PinFlags, _encode_PinFlags, } from "../PKCS-15/PinFlags.ta.mjs";
import { _decode_PinType, _encode_PinType, _enum_for_PinType, } from "../PKCS-15/PinType.ta.mjs";
import { _decode_Reference, _encode_Reference, } from "../PKCS-15/Reference.ta.mjs";
/**
* @summary PinAttributes
* @description
*
* ### ASN.1 Definition:
*
* ```asn1
* PinAttributes ::= SEQUENCE {
* pinFlags PinFlags,
* pinType PinType,
* minLength INTEGER (pkcs15-lb-minPinLength..pkcs15-ub-minPinLength),
* storedLength INTEGER (0..pkcs15-ub-storedPinLength),
* maxLength INTEGER OPTIONAL,
* pinReference [0] Reference DEFAULT 0,
* padChar OCTET STRING (SIZE(1)) OPTIONAL,
* lastPinChange GeneralizedTime OPTIONAL,
* path Path OPTIONAL,
* ... -- For future extensions
* }
* ```
*
*/
export class PinAttributes {
pinFlags;
pinType;
minLength;
storedLength;
maxLength;
pinReference;
padChar;
lastPinChange;
path;
_unrecognizedExtensionsList;
constructor(
/**
* @summary `pinFlags`.
* @public
* @readonly
*/
pinFlags,
/**
* @summary `pinType`.
* @public
* @readonly
*/
pinType,
/**
* @summary `minLength`.
* @public
* @readonly
*/
minLength,
/**
* @summary `storedLength`.
* @public
* @readonly
*/
storedLength,
/**
* @summary `maxLength`.
* @public
* @readonly
*/
maxLength,
/**
* @summary `pinReference`.
* @public
* @readonly
*/
pinReference,
/**
* @summary `padChar`.
* @public
* @readonly
*/
padChar,
/**
* @summary `lastPinChange`.
* @public
* @readonly
*/
lastPinChange,
/**
* @summary `path`.
* @public
* @readonly
*/
path,
/**
* @summary Extensions that are not recognized.
* @public
* @readonly
*/
_unrecognizedExtensionsList = []) {
this.pinFlags = pinFlags;
this.pinType = pinType;
this.minLength = minLength;
this.storedLength = storedLength;
this.maxLength = maxLength;
this.pinReference = pinReference;
this.padChar = padChar;
this.lastPinChange = lastPinChange;
this.path = path;
this._unrecognizedExtensionsList = _unrecognizedExtensionsList;
}
/**
* @summary Restructures an object into a PinAttributes
* @description
*
* This takes an `object` and converts it to a `PinAttributes`.
*
* @public
* @static
* @method
* @param {Object} _o An object having all of the keys and values of a `PinAttributes`.
* @returns {PinAttributes}
*/
static _from_object(_o) {
return new PinAttributes(_o.pinFlags, _o.pinType, _o.minLength, _o.storedLength, _o.maxLength, _o.pinReference, _o.padChar, _o.lastPinChange, _o.path, _o._unrecognizedExtensionsList);
}
/**
* @summary Getter that returns the default value for `pinReference`.
* @public
* @static
* @method
*/
static get _default_value_for_pinReference() {
return 0;
}
/**
* @summary The enum used as the type of the component `pinType`
* @public
* @static
*/
static _enum_for_pinType = _enum_for_PinType;
}
/**
* @summary The Leading Root Component Types of PinAttributes
* @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_PinAttributes = [
new $.ComponentSpec("pinFlags", false, $.hasTag(_TagClass.universal, 3)),
new $.ComponentSpec("pinType", false, $.hasTag(_TagClass.universal, 10)),
new $.ComponentSpec("minLength", false, $.hasTag(_TagClass.universal, 2)),
new $.ComponentSpec("storedLength", false, $.hasTag(_TagClass.universal, 2)),
new $.ComponentSpec("maxLength", true, $.hasTag(_TagClass.universal, 2)),
new $.ComponentSpec("pinReference", true, $.hasTag(_TagClass.context, 0)),
new $.ComponentSpec("padChar", true, $.hasTag(_TagClass.universal, 4)),
new $.ComponentSpec("lastPinChange", true, $.hasTag(_TagClass.universal, 24)),
new $.ComponentSpec("path", true, $.hasTag(_TagClass.universal, 16)),
];
/**
* @summary The Trailing Root Component Types of PinAttributes
* @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_PinAttributes = [];
/**
* @summary The Extension Addition Component Types of PinAttributes
* @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_PinAttributes = [];
let _cached_decoder_for_PinAttributes = null;
/**
* @summary Decodes an ASN.1 element into a(n) PinAttributes
* @function
* @param {_Element} el The element being decoded.
* @returns {PinAttributes} The decoded data structure.
*/
export function _decode_PinAttributes(el) {
if (!_cached_decoder_for_PinAttributes) {
_cached_decoder_for_PinAttributes = function (el) {
let pinFlags;
let pinType;
let minLength;
let storedLength;
let maxLength;
let pinReference = PinAttributes._default_value_for_pinReference;
let padChar;
let lastPinChange;
let path;
let _unrecognizedExtensionsList = [];
const callbacks = {
pinFlags: (_el) => {
pinFlags = _decode_PinFlags(_el);
},
pinType: (_el) => {
pinType = _decode_PinType(_el);
},
minLength: (_el) => {
minLength = $._decodeInteger(_el);
},
storedLength: (_el) => {
storedLength = $._decodeInteger(_el);
},
maxLength: (_el) => {
maxLength = $._decodeInteger(_el);
},
pinReference: (_el) => {
pinReference = $._decode_implicit(() => _decode_Reference)(_el);
},
padChar: (_el) => {
padChar = $._decodeOctetString(_el);
},
lastPinChange: (_el) => {
lastPinChange = $._decodeGeneralizedTime(_el);
},
path: (_el) => {
path = _decode_Path(_el);
},
};
$._parse_sequence(el, callbacks, _root_component_type_list_1_spec_for_PinAttributes, _extension_additions_list_spec_for_PinAttributes, _root_component_type_list_2_spec_for_PinAttributes, (ext) => {
_unrecognizedExtensionsList.push(ext);
});
return new PinAttributes(pinFlags, pinType, minLength, storedLength, maxLength, pinReference, padChar, lastPinChange, path, _unrecognizedExtensionsList);
};
}
return _cached_decoder_for_PinAttributes(el);
}
let _cached_encoder_for_PinAttributes = null;
/**
* @summary Encodes a(n) PinAttributes 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 PinAttributes, encoded as an ASN.1 Element.
*/
export function _encode_PinAttributes(value, elGetter) {
if (!_cached_encoder_for_PinAttributes) {
_cached_encoder_for_PinAttributes = function (value) {
return $._encodeSequence([]
.concat([
/* REQUIRED */ _encode_PinFlags(value.pinFlags, $.BER),
/* REQUIRED */ _encode_PinType(value.pinType, $.BER),
/* REQUIRED */ $._encodeInteger(value.minLength, $.BER),
/* REQUIRED */ $._encodeInteger(value.storedLength, $.BER),
/* IF_ABSENT */ value.maxLength === undefined
? undefined
: $._encodeInteger(value.maxLength, $.BER),
/* IF_DEFAULT */ value.pinReference === undefined ||
$.deepEq(value.pinReference, PinAttributes._default_value_for_pinReference)
? undefined
: $._encode_implicit(_TagClass.context, 0, () => _encode_Reference, $.BER)(value.pinReference, $.BER),
/* IF_ABSENT */ value.padChar === undefined
? undefined
: $._encodeOctetString(value.padChar, $.BER),
/* IF_ABSENT */ value.lastPinChange === undefined
? undefined
: $._encodeGeneralizedTime(value.lastPinChange, $.BER),
/* IF_ABSENT */ value.path === undefined
? undefined
: _encode_Path(value.path, $.BER),
], value._unrecognizedExtensionsList
? value._unrecognizedExtensionsList
: [])
.filter((c) => !!c), $.BER);
};
}
return _cached_encoder_for_PinAttributes(value, elGetter);
}
/* eslint-enable */