<commit_before>import QtQuick 2.5
import QtQuick.Dialogs 1.2
import QtQuick.Controls 1.4
import QtQuick.Layouts 1.1
import QtQuick.Window 2.0
import "slotutils.js" as SlotUtils

ColumnLayout {

    property var device
    property var slotsEnabled: [false, false]
    property int selectedSlot
    signal configureSlot(int slot)
    signal updateStatus
    signal goToOverview
    signal goToSelectType
    signal goToSlotStatus
    signal goToConfigureOTP
    signal goToChallengeResponse
    signal goToStaticPassword
    signal goToOathHotp

    Text {
        text: qsTr("Configure Yubico OTP for ") + SlotUtils.slotNameCapitalized(selectedSlot)
        font.bold: true
    }

    Text {
        text: qsTr("When triggered, the YubiKey will output a one time password.")
    }


    GroupBox {
        title: qsTr("Public ID")
        Layout.fillWidth: true
        ColumnLayout {

         RowLayout{
             TextField {
                 id: publicIdInput
                 implicitWidth: 110
                 font.family: "Courier"
                 validator: RegExpValidator {
                     regExp: /[cbdefghijklnrtuv]{12}$/
                 }
             }
             CheckBox {
                 id: useSerialCb
                 anchors.margins: 5
                 enabled: device.serial
                 anchors.left: publicIdInput.right
                 text: qsTr("Use encoded serial number")
                 onCheckedChanged: useSerial()
             }
         }
         RowLayout {
             Text {
                 text: qsTr("The Public ID can contain the following characters: cbdefghijklnrtuv.")
             }
         }

        }
    }

    GroupBox {
        title: qsTr("Private ID")
        Layout.fillWidth: true
        ColumnLayout {

             RowLayout{
                 TextField {
                     id: privateIdInput
                     implicitWidth: 110
                     font.family: "Courier"
                     validator: RegExpValidator {
                         regExp: /[0-9a-fA-F]{12}$/
                     }
                 }
                 Button {
                     anchors.margins: 5
                     text: qsTr("Generate")
                     anchors.left: privateIdInput.right
                     onClicked: generatePrivateId()
                 }
             }
             RowLayout {
                 Text {
                     text: qsTr("The Private ID contains 12 hexadecimal characters.")
                 }
             }
        }
    }

    GroupBox {
        title: qsTr("Secret key")
        Layout.fillWidth: true
        ColumnLayout {

             RowLayout{
                 TextField {
                     id: secretKeyInput
                     implicitWidth: 260
                     font.family: "Courier"
                     validator: RegExpValidator {
                         regExp: /[0-9a-fA-F]{32}$/
                     }
                 }
                 Button {
                     anchors.margins: 5
                     anchors.left: secretKeyInput.right
                     text: qsTr("Generate")
                     onClicked: generateKey()
                 }
             }
             RowLayout {
                 Text {
                     text: qsTr("The Secret key contains 32 hexadecimal characters.")
                 }
             }
        }
    }

    RowLayout {
        Layout.alignment: Qt.AlignRight
        Button {
            text: qsTr("Back")
            onClicked: goToSelectType()
        }
        Button {
            text: qsTr("Finish")
            enabled: publicIdInput.acceptableInput
                     && privateIdInput.acceptableInput
                     && secretKeyInput.acceptableInput
            onClicked: finish()
        }
    }

    SlotOverwriteWarning {
        id: warning
        onAccepted: programOTP()
    }

    function finish() {
        if (slotsEnabled[selectedSlot - 1]) {
            warning.open()
        } else {
            programOTP()
        }
    }

    function useSerial() {
        if (useSerialCb.checked) {
            device.serial_modhex(function (res) {
                publicIdInput.text = res
            })
        }
    }

    function generatePrivateId() {
        device.random_uid(function (res) {
            privateIdInput.text = res
        })
    }

    function generateKey() {
        device.random_key(16, function (res) {
            secretKeyInput.text = res
        })
    }

    function programOTP() {
        device.program_otp(selectedSlot, publicIdInput.text,
                           privateIdInput.text, secretKeyInput.text,
                           function (error) {
                               if (!error) {
                                   updateStatus()
                                   confirmConfigured.open()
                               } else {
                                   if (error === 3) {
                                     writeError.open()
                                   }
                               }
                           })
    }

}
<commit_msg>Yubico OTP: disable public id input when using serial<commit_after>import QtQuick 2.5
import QtQuick.Dialogs 1.2
import QtQuick.Controls 1.4
import QtQuick.Layouts 1.1
import QtQuick.Window 2.0
import "slotutils.js" as SlotUtils

ColumnLayout {

    property var device
    property var slotsEnabled: [false, false]
    property int selectedSlot
    signal configureSlot(int slot)
    signal updateStatus
    signal goToOverview
    signal goToSelectType
    signal goToSlotStatus
    signal goToConfigureOTP
    signal goToChallengeResponse
    signal goToStaticPassword
    signal goToOathHotp

    Text {
        text: qsTr("Configure Yubico OTP for ") + SlotUtils.slotNameCapitalized(selectedSlot)
        font.bold: true
    }

    Text {
        text: qsTr("When triggered, the YubiKey will output a one time password.")
    }


    GroupBox {
        title: qsTr("Public ID")
        Layout.fillWidth: true
        ColumnLayout {

         RowLayout{
             TextField {
                 id: publicIdInput
                 enabled: !useSerialCb.checked
                 implicitWidth: 110
                 font.family: "Courier"
                 validator: RegExpValidator {
                     regExp: /[cbdefghijklnrtuv]{12}$/
                 }
             }
             CheckBox {
                 id: useSerialCb
                 anchors.margins: 5
                 enabled: device.serial
                 anchors.left: publicIdInput.right
                 text: qsTr("Use encoded serial number")
                 onCheckedChanged: useSerial()
             }
         }
         RowLayout {
             Text {
                 text: qsTr("The Public ID can contain the following characters: cbdefghijklnrtuv.")
             }
         }

        }
    }

    GroupBox {
        title: qsTr("Private ID")
        Layout.fillWidth: true
        ColumnLayout {

             RowLayout{
                 TextField {
                     id: privateIdInput
                     implicitWidth: 110
                     font.family: "Courier"
                     validator: RegExpValidator {
                         regExp: /[0-9a-fA-F]{12}$/
                     }
                 }
                 Button {
                     anchors.margins: 5
                     text: qsTr("Generate")
                     anchors.left: privateIdInput.right
                     onClicked: generatePrivateId()
                 }
             }
             RowLayout {
                 Text {
                     text: qsTr("The Private ID contains 12 hexadecimal characters.")
                 }
             }
        }
    }

    GroupBox {
        title: qsTr("Secret key")
        Layout.fillWidth: true
        ColumnLayout {

             RowLayout{
                 TextField {
                     id: secretKeyInput
                     implicitWidth: 260
                     font.family: "Courier"
                     validator: RegExpValidator {
                         regExp: /[0-9a-fA-F]{32}$/
                     }
                 }
                 Button {
                     anchors.margins: 5
                     anchors.left: secretKeyInput.right
                     text: qsTr("Generate")
                     onClicked: generateKey()
                 }
             }
             RowLayout {
                 Text {
                     text: qsTr("The Secret key contains 32 hexadecimal characters.")
                 }
             }
        }
    }

    RowLayout {
        Layout.alignment: Qt.AlignRight
        Button {
            text: qsTr("Back")
            onClicked: goToSelectType()
        }
        Button {
            text: qsTr("Finish")
            enabled: publicIdInput.acceptableInput
                     && privateIdInput.acceptableInput
                     && secretKeyInput.acceptableInput
            onClicked: finish()
        }
    }

    SlotOverwriteWarning {
        id: warning
        onAccepted: programOTP()
    }

    function finish() {
        if (slotsEnabled[selectedSlot - 1]) {
            warning.open()
        } else {
            programOTP()
        }
    }

    function useSerial() {
        if (useSerialCb.checked) {
            device.serial_modhex(function (res) {
                publicIdInput.text = res
            })
        }
    }

    function generatePrivateId() {
        device.random_uid(function (res) {
            privateIdInput.text = res
        })
    }

    function generateKey() {
        device.random_key(16, function (res) {
            secretKeyInput.text = res
        })
    }

    function programOTP() {
        device.program_otp(selectedSlot, publicIdInput.text,
                           privateIdInput.text, secretKeyInput.text,
                           function (error) {
                               if (!error) {
                                   updateStatus()
                                   confirmConfigured.open()
                               } else {
                                   if (error === 3) {
                                     writeError.open()
                                   }
                               }
                           })
    }

}

{'fraction_non_alphanumeric': 0.07146306132303235, 'fraction_numerical': 0.00772573635924674, 'mean_word_length': 1.0576197099145639, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4804750', 'n_tokens_mistral': 2646, 'n_tokens_neox': 2479, 'n_words': 534}