Warning, /utilities/keysmith/src/contents/ui/HOTPDetailsForm.qml is written in an unsupported language. File is not indexed.

0001 /*
0002  * SPDX-License-Identifier: GPL-3.0-or-later
0003  * SPDX-FileCopyrightText: 2020 Johan Ouwerkerk <jm.ouwerkerk@gmail.com>
0004  */
0005 
0006 import QtQuick
0007 import QtQuick.Layouts
0008 import QtQuick.Controls as QQC2
0009 import org.kde.kirigami as Kirigami
0010 import org.kde.kirigamiaddons.formcard 1 as FormCard
0011 
0012 import Keysmith.Models as Models
0013 import Keysmith.Validators as Validators
0014 
0015 FormCard.FormCard {
0016     id: root
0017 
0018     property Models.ValidatedAccountInput validatedInput
0019 
0020     property bool counterAcceptable: counterField.acceptableInput
0021     property bool acceptable: counterAcceptable
0022 
0023     FormCard.FormTextFieldDelegate {
0024         id: counterField
0025 
0026         text: validatedInput ? validatedInput.counter : ""
0027         label: i18nc("@label:textbox", "Counter:")
0028         validator: Validators.HOTPCounterValidator {}
0029         inputMethodHints: Qt.ImhDigitsOnly
0030         onTextChanged: {
0031             if (acceptableInput) {
0032                 validatedInput.setCounter(text, validator);
0033             }
0034         }
0035     }
0036 
0037     FormCard.FormDelegateSeparator {}
0038 
0039     /*
0040      * OATH tokens are derived from a 32bit value, base-10 encoded.
0041      * Meaning tokens should not be longer than 10 digits max.
0042      * In addition tokens must be 6 digits long at minimum.
0043      *
0044      * Make a virtue of it by offering a spinner for better UX
0045      */
0046     FormCard.FormSpinBoxDelegate {
0047         id: tokenLengthField
0048         label: i18nc("@label:spinbox", "Token length:")
0049         from: 6
0050         to: 10
0051         value: validatedInput ? validatedInput.tokenLength : 6
0052         onValueChanged: {
0053             validatedInput.tokenLength = value;
0054         }
0055     }
0056 
0057     FormCard.FormDelegateSeparator { above: checksumField }
0058 
0059     FormCard.FormCheckDelegate {
0060         id: checksumField
0061 
0062         checked: validatedInput.checksum
0063         text: i18nc("@option:check", "Add checksum digit")
0064         onCheckedChanged: {
0065             validatedInput.checksum = checked;
0066         }
0067     }
0068 
0069     FormCard.FormDelegateSeparator { below: checksumField }
0070 
0071     FormCard.FormCheckDelegate {
0072         id: truncationTypeField
0073 
0074         checked: validatedInput && validatedInput.fixedTruncation
0075         text: i18nc("@option:check", "Use custom truncation offset")
0076         onCheckedChanged: {
0077             if (!checked) {
0078                 validatedInput.setDynamicTruncation();
0079             }
0080         }
0081     }
0082 
0083     FormCard.FormDelegateSeparator { below: truncationTypeField }
0084 
0085     FormCard.FormSpinBoxDelegate {
0086         id: truncationValueField
0087 
0088         enabled: truncationTypeField.checked
0089         label: i18nc("@label:spinbox", "Truncation offset:")
0090         from: 0
0091         /*
0092          * HOTP tokens are based on a HMAC-SHA1 construction yielding 20 bytes of output of which 4 are taken to
0093          * compute the token value.
0094          */
0095         to: 16
0096         value: validatedInput ? validatedInput.truncationOffset : 0
0097     }
0098 }