2022-10-19 21:28:43 +00:00
|
|
|
import Component from '@glimmer/component';
|
|
|
|
import { action } from '@ember/object';
|
|
|
|
|
|
|
|
/**
|
2022-11-18 00:50:58 +00:00
|
|
|
* @module PkiKeyParameters
|
2022-11-21 22:58:34 +00:00
|
|
|
* PkiKeyParameters components are used to display a list of key bit options depending on the selected key type.
|
|
|
|
* If the component renders in a group, other attrs may be passed in and will be rendered using the <FormField> component
|
2022-10-19 21:28:43 +00:00
|
|
|
* @example
|
|
|
|
* ```js
|
2022-11-21 22:58:34 +00:00
|
|
|
* <PkiKeyParameters @model={{@model}} @fields={{fields}}/>
|
2022-10-19 21:28:43 +00:00
|
|
|
* ```
|
2022-11-10 21:27:19 +00:00
|
|
|
* @param {class} model - The pki/role model.
|
2022-11-21 22:58:34 +00:00
|
|
|
* @param {string} fields - The name of the fields created in the model. In this case, it's the "Key parameters" fields.
|
2022-10-19 21:28:43 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
const KEY_BITS_OPTIONS = {
|
|
|
|
rsa: [2048, 3072, 4096],
|
|
|
|
ec: [256, 224, 384, 521],
|
|
|
|
ed25519: [0],
|
|
|
|
any: [0],
|
|
|
|
};
|
|
|
|
|
2022-11-18 00:50:58 +00:00
|
|
|
export default class PkiKeyParameters extends Component {
|
2022-11-21 22:58:34 +00:00
|
|
|
// TODO clarify types here
|
2022-10-19 21:28:43 +00:00
|
|
|
get keyBitOptions() {
|
|
|
|
return KEY_BITS_OPTIONS[this.args.model.keyType];
|
|
|
|
}
|
|
|
|
|
|
|
|
get keyBitsDefault() {
|
|
|
|
return Number(KEY_BITS_OPTIONS[this.args.model.keyType][0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
@action onKeyBitsChange(selection) {
|
|
|
|
this.args.model.set('keyBits', Number(selection.target.value));
|
|
|
|
}
|
|
|
|
|
|
|
|
@action onSignatureBitsOrKeyTypeChange(name, selection) {
|
|
|
|
if (name === 'signatureBits') {
|
2022-11-21 22:58:34 +00:00
|
|
|
this.args.model.set(name, Number(selection));
|
2022-10-19 21:28:43 +00:00
|
|
|
}
|
|
|
|
if (name === 'keyType') {
|
|
|
|
this.args.model.set('keyBits', this.keyBitsDefault);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|