[-]
[+]
|
Changed |
_service:tar_git:harbour-foilauth.changes
|
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilauth.spec
^
|
|
[-]
[+]
|
Changed |
_service
^
|
@@ -2,6 +2,6 @@
<service name="tar_git">
<param name="url">https://github.com/monich/harbour-foilauth.git</param>
<param name="branch">master</param>
- <param name="revision">f70e7c7</param>
+ <param name="revision">62d0c9e</param>
</service>
</services>
\ No newline at end of file
|
[-]
[+]
|
Deleted |
_service:tar_git:harbour-foilauth-1.1.2.tar.gz/qml/SelectTokenPage.qml
^
|
@@ -1,64 +0,0 @@
-import QtQuick 2.0
-import Sailfish.Silica 1.0
-
-Page {
- id: page
-
- property var tokens: []
-
- signal tokenSelected(var token)
-
- SilicaListView {
- anchors.fill: parent
- width: parent.width
- clip: true
- model: tokens
-
- header: Label {
- x: Theme.horizontalPageMargin
- width: parent.width - 2 * x
- height: implicitHeight + 2 * Theme.paddingLarge
- font.pixelSize: Theme.fontSizeExtraLarge
- wrapMode: Text.Wrap
- color: Theme.highlightColor
- verticalAlignment: Text.AlignVCenter
- //: Wrappable page title
- //% "This QR code contains multiple tokens. Please select one:"
- text: qsTrId("foilauth-select_token-title")
- }
-
- delegate: BackgroundItem {
- id: delegate
-
- height: Theme.itemSizeMedium
-
- readonly property var token: modelData
-
- Column {
- x: Theme.horizontalPageMargin
- width: parent.width - 2 * x
- anchors.verticalCenter: parent.verticalCenter
-
- Label {
- text: token.label
- width: parent.width
- truncationMode: TruncationMode.Fade
- color: delegate.highlighted ? Theme.highlightColor : Theme.primaryColor
- }
-
- Label {
- text: token.issuer
- width: parent.width
- truncationMode: TruncationMode.Fade
- font.pixelSize: Theme.fontSizeExtraSmall
- color: delegate.highlighted ? Theme.secondaryHighlightColor : Theme.secondaryColor
- visible: text !== ""
- }
- }
-
- onClicked: page.tokenSelected(token)
- }
-
- VerticalScrollDecorator { }
- }
-}
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilauth-1.1.3.tar.gz/app.pro
^
|
@@ -80,6 +80,7 @@
src/FoilAuth.h \
src/FoilAuthDefs.h \
src/FoilAuthFavoritesModel.h \
+ src/FoilAuthImportModel.h \
src/FoilAuthModel.h \
src/FoilAuthSettings.h \
src/FoilAuthToken.h \
@@ -91,6 +92,7 @@
SOURCES += \
src/FoilAuth.cpp \
src/FoilAuthFavoritesModel.cpp \
+ src/FoilAuthImportModel.cpp \
src/FoilAuthModel.cpp \
src/FoilAuthSettings.cpp \
src/FoilAuthToken.cpp \
@@ -144,6 +146,7 @@
$${HARBOUR_LIB_INCLUDE}/HarbourDebug.h \
$${HARBOUR_LIB_INCLUDE}/HarbourOrganizeListModel.h \
$${HARBOUR_LIB_INCLUDE}/HarbourProcessState.h \
+ $${HARBOUR_LIB_INCLUDE}/HarbourProtoBuf.h \
$${HARBOUR_LIB_INCLUDE}/HarbourQrCodeGenerator.h \
$${HARBOUR_LIB_INCLUDE}/HarbourQrCodeImageProvider.h \
$${HARBOUR_LIB_INCLUDE}/HarbourSelectionListModel.h \
@@ -157,6 +160,7 @@
$${HARBOUR_LIB_SRC}/HarbourMce.cpp \
$${HARBOUR_LIB_SRC}/HarbourOrganizeListModel.cpp \
$${HARBOUR_LIB_SRC}/HarbourProcessState.cpp \
+ $${HARBOUR_LIB_SRC}/HarbourProtoBuf.cpp \
$${HARBOUR_LIB_SRC}/HarbourQrCodeGenerator.cpp \
$${HARBOUR_LIB_SRC}/HarbourQrCodeImageProvider.cpp \
$${HARBOUR_LIB_SRC}/HarbourSelectionListModel.cpp \
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilauth-1.1.3.tar.gz/foil-ui/FoilUiConfirmPasswordDialog.qml
^
|
@@ -13,8 +13,8 @@
property bool wrongPassword
readonly property bool landscapeLayout: isLandscape && Screen.sizeCategory < Screen.Large
- readonly property bool canCheckPassword: inputField.text.length > 0 &&
- inputField.text.length > 0 && !wrongPassword
+ readonly property bool canCheckPassword: inputField.text.length > 0 && !wrongPassword
+ readonly property int fullHeight: dialog.isPortrait ? Screen.height : Screen.width
signal passwordConfirmed()
@@ -60,8 +60,8 @@
id: panel
width: parent.width
- height: childrenRect.height
- y: (parent.height > height) ? Math.floor((parent.height - height)/2) : (parent.height - height)
+ height: childrenRect.height + (landscapeLayout ? 0 : Theme.paddingLarge)
+ y: Math.min((fullHeight - height)/2, parent.height - panel.height)
Label {
id: warning
@@ -93,10 +93,7 @@
Button {
id: button
- anchors {
- topMargin: Theme.paddingLarge
- bottomMargin: 2 * Theme.paddingSmall
- }
+ anchors.bottomMargin: Theme.paddingLarge
text: foilUi.qsTrConfirmPasswordButton()
enabled: dialog.canCheckPassword
onClicked: dialog.checkPassword()
@@ -120,10 +117,7 @@
},
PropertyChanges {
target: inputField
- anchors {
- rightMargin: 0
- bottomMargin: Theme.paddingLarge
- }
+ anchors.rightMargin: 0
},
AnchorChanges {
target: button
@@ -150,10 +144,7 @@
},
PropertyChanges {
target: inputField
- anchors {
- rightMargin: Theme.horizontalPageMargin
- bottomMargin: Theme.paddingSmall
- }
+ anchors.rightMargin: Theme.horizontalPageMargin
},
AnchorChanges {
target: button
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilauth-1.1.3.tar.gz/foil-ui/FoilUiEnterPasswordView.qml
^
|
@@ -30,6 +30,8 @@
PullDownMenu {
id: pullDownMenu
+ visible: !Qt.inputMethod.visible
+
MenuItem {
text: foilUi.qsTrEnterPasswordViewMenuGenerateNewKey()
onClicked: pageStack.push(Qt.resolvedUrl("FoilUiGenerateKeyWarning.qml"), {
@@ -53,21 +55,17 @@
anchors.horizontalCenter: parent.horizontalCenter
y: (panel.y > height) ? Math.floor((panel.y - height)/2) : (panel.y - height)
- // Hide it when it's only partially visible (i.e. in langscape)
+ // Hide it when it's only partially visible (i.e. in landscape)
// or getting too close to the edge of the screen
- opacity: (y < Theme.paddingMedium) ? 0 : 1
- Behavior on opacity {
- enabled: !page.orientationTransitionRunning
- FadeAnimation { duration: 100 }
- }
+ opacity: (y < Theme.paddingLarge) ? 0 : 1
}
Item {
id: panel
width: parent.width
- height: childrenRect.height
- y: (parent.height > height) ? Math.floor((parent.height - height)/2) : (parent.height - height)
+ height: childrenRect.height + (landscapeLayout ? 0 : Theme.paddingLarge)
+ y: Math.min(Math.floor((screenHeight - height)/2), parent.height - height)
readonly property bool showLongPrompt: y >= Theme.paddingMedium
@@ -159,7 +157,7 @@
PropertyChanges {
target: button
anchors {
- topMargin: Theme.paddingLarge
+ topMargin: 0
rightMargin: 0
}
}
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilauth-1.1.3.tar.gz/foil-ui/FoilUiGenerateKeyPage.qml
^
|
@@ -10,6 +10,9 @@
allowedOrientations: Orientation.All
+ // Otherwise width is changing with a delay, causing visible layout changes
+ onIsLandscapeChanged: width = isLandscape ? Screen.height : Screen.width
+
Connections {
target: foilModel
onFoilStateChanged: {
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilauth-1.1.3.tar.gz/foil-ui/FoilUiGenerateKeyView.qml
^
|
@@ -15,6 +15,7 @@
readonly property bool canGenerate: inputField.text.length >= minPassphraseLen && !generating
readonly property bool generating: foilUi.isGeneratingKeyState(foilModel.foilState)
readonly property bool landscapeLayout: page.isLandscape && Screen.sizeCategory < Screen.Large
+ readonly property int fullHeight: page.isPortrait ? Screen.height : Screen.width
function generateKey() {
if (canGenerate) {
@@ -35,22 +36,22 @@
HarbourHighlightIcon {
source: "images/key.svg"
width: Theme.itemSizeHuge
- sourceSize.width: width
+ sourceSize.width: Theme.itemSizeHuge
anchors.horizontalCenter: parent.horizontalCenter
- property real attachToY: panel.y + keySize.y
+ property real attachToY: panel.y + (promptLabel.visible ? promptLabel.y : keySize.y)
y: (attachToY > height) ? Math.floor((attachToY - height)/2) : (attachToY - height)
visible: opacity > 0
// Hide it when it's getting too close to the top if the view
- // Otherwise show it when the prompt is hidden
- opacity: (y < Theme.paddingLarge) ? 0 : (1 - promptLabel.opacity)
+ opacity: (y < Theme.paddingLarge) ? 0 : 1
+ Behavior on opacity { FadeAnimation { } }
}
Item {
id: panel
width: parent.width
- height: childrenRect.height
- y: (parent.height > height) ? Math.floor((parent.height - height)/2) : (parent.height - height)
+ height: childrenRect.height + (landscapeLayout ? 0 : Theme.paddingLarge)
+ y: Math.min((fullHeight - height)/2, parent.height - panel.height)
InfoLabel {
id: promptLabel
@@ -98,23 +99,13 @@
Button {
id: button
- anchors.topMargin: Theme.paddingLarge
+ anchors.bottomMargin: Theme.paddingLarge
text: generating ?
foilUi.qsTrGenerateKeyButtonGenerating() :
foilUi.qsTrGenerateKeyButtonGenerate()
enabled: canGenerate
onClicked: generateKey()
}
-
- // Theme.paddingLarge pixels below the button in portrait
- Item {
- height: landscapeLayout ? 0 : Theme.paddingLarge
- anchors {
- top: button.bottom
- left: button.left
- right: button.right
- }
- }
}
states: [
@@ -134,7 +125,9 @@
target: button
anchors {
top: inputField.bottom
+ right: undefined
horizontalCenter: parent.horizontalCenter
+ bottom: undefined
}
},
PropertyChanges {
@@ -158,9 +151,10 @@
AnchorChanges {
target: button
anchors {
- top: keySize.bottom
+ top: undefined
right: panel.right
horizontalCenter: undefined
+ bottom: inputField.bottom
}
},
PropertyChanges {
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilauth-1.1.3.tar.gz/harbour-lib/harbour-lib.pro
^
|
@@ -36,6 +36,7 @@
src/HarbourOrganizeListModel.cpp \
src/HarbourPolicyPlugin.cpp \
src/HarbourProcessState.cpp \
+ src/HarbourProtoBuf.cpp \
src/HarbourSelectionListModel.cpp \
src/HarbourSigChildHandler.cpp \
src/HarbourSingleImageProvider.cpp \
@@ -46,7 +47,8 @@
src/HarbourTask.cpp \
src/HarbourTemporaryFile.cpp \
src/HarbourTransferMethodInfo.cpp \
- src/HarbourTransferMethodsModel.cpp
+ src/HarbourTransferMethodsModel.cpp \
+ src/HarbourUtil.cpp
greaterThan(QT_MAJOR_VERSION, 4) {
SOURCES += \
@@ -70,6 +72,7 @@
include/HarbourOrganizeListModel.h \
include/HarbourPolicyPlugin.h \
include/HarbourProcessState.h \
+ include/HarbourProtoBuf.h \
include/HarbourSelectionListModel.h \
include/HarbourSigChildHandler.h \
include/HarbourSingleImageProvider.h \
@@ -80,7 +83,8 @@
include/HarbourTask.h \
include/HarbourTemporaryFile.h \
include/HarbourTransferMethodInfo.h \
- include/HarbourTransferMethodsModel.h
+ include/HarbourTransferMethodsModel.h \
+ include/HarbourUtil.h
greaterThan(QT_MAJOR_VERSION, 4) {
PUBLIC_HEADERS += \
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilauth-1.1.3.tar.gz/harbour-lib/include/HarbourBase32.h
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2019-2021 Jolla Ltd.
- * Copyright (C) 2019-2021 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2019-2022 Jolla Ltd.
+ * Copyright (C) 2019-2022 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of the BSD license as follows:
*
@@ -37,13 +37,15 @@
#include <QString>
#include <QByteArray>
-class HarbourBase32 {
+class HarbourBase32
+{
class Private;
- HarbourBase32();
+ HarbourBase32() Q_DECL_EQ_DELETE;
+
public:
- static QByteArray fromBase32(QString aBase32);
- static QString toBase32(QByteArray aBinary, bool aLowerCase = true);
- static bool isValidBase32(QString aBase32);
+ static bool isValidBase32(const QString);
+ static QString toBase32(const QByteArray, bool aLowerCase = true);
+ static QByteArray fromBase32(const QString);
};
#endif // HARBOUR_BASE32_H
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilauth-1.1.3.tar.gz/harbour-lib/include/HarbourBase45.h
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2021 Jolla Ltd.
- * Copyright (C) 2021 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2021-2022 Jolla Ltd.
+ * Copyright (C) 2021-2022 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of the BSD license as follows:
*
@@ -37,13 +37,15 @@
#include <QString>
#include <QByteArray>
-class HarbourBase45 {
+class HarbourBase45
+{
class Private;
- HarbourBase45();
+ HarbourBase45() Q_DECL_EQ_DELETE;
+
public:
- static bool isValidBase45(QString aBase45);
- static QByteArray fromBase45(QString aBase45);
- static QString toBase45(QByteArray aBinary);
+ static bool isValidBase45(const QString);
+ static QString toBase45(const QByteArray);
+ static QByteArray fromBase45(const QString);
};
#endif // HARBOUR_BASE45_H
|
[-]
[+]
|
Added |
_service:tar_git:harbour-foilauth-1.1.3.tar.gz/harbour-lib/include/HarbourProtoBuf.h
^
|
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2022 Jolla Ltd.
+ * Copyright (C) 2022 Slava Monich <slava.monich@jolla.com>
+ *
+ * You may use this file under the terms of the BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef HARBOUR_PROTOBUF_H
+#define HARBOUR_PROTOBUF_H
+
+#include <QByteArray>
+
+#include <gutil_types.h>
+
+// https://developers.google.com/protocol-buffers/docs/encoding
+
+class HarbourProtoBuf
+{
+ HarbourProtoBuf() Q_DECL_EQ_DELETE;
+
+public:
+ enum {
+ TYPE_SHIFT = 3,
+ TYPE_MASK = ((1 << TYPE_SHIFT)-1),
+ TYPE_VARINT = 0,
+ TYPE_DELIMITED = 2
+ };
+
+ static QByteArray* appendVarInt(QByteArray*, quint64);
+ static QByteArray* appendVarIntKeyValue(QByteArray*, quint64, quint64);
+ static QByteArray* appendDelimitedValue(QByteArray*, const QByteArray);
+ static QByteArray* appendDelimitedKeyValue(QByteArray*, quint64, const QByteArray);
+
+ static bool parseVarInt(GUtilRange*, quint64*);
+ static bool parseDelimitedValue(GUtilRange*, GUtilData*);
+};
+
+#endif // HARBOUR_PROTOBUF_H
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilauth-1.1.3.tar.gz/harbour-lib/include/HarbourTheme.h
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2018-2021 Jolla Ltd.
- * Copyright (C) 2018-2021 Slava Monich <slava@monich.com>
+ * Copyright (C) 2018-2022 Jolla Ltd.
+ * Copyright (C) 2018-2022 Slava Monich <slava@monich.com>
*
* You may use this file under the terms of the BSD license as follows:
*
@@ -81,8 +81,6 @@
qreal opacityHigh() const;
qreal opacityOverlay() const;
- static QRgb invertedRgb(QRgb aRgb);
-
Q_INVOKABLE static QColor invertedColor(const QColor& aColor);
Q_INVOKABLE static qreal colorDifference(const QColor& aColor1, const QColor& aColor2);
|
[-]
[+]
|
Added |
_service:tar_git:harbour-foilauth-1.1.3.tar.gz/harbour-lib/include/HarbourUtil.h
^
|
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2022 Jolla Ltd.
+ * Copyright (C) 2022 Slava Monich <slava.monich@jolla.com>
+ *
+ * You may use this file under the terms of the BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef HARBOUR_UTIL_H
+#define HARBOUR_UTIL_H
+
+#include <QByteArray>
+#include <QColor>
+#include <QObject>
+#include <QRgb>
+#include <QString>
+
+class QQmlEngine;
+class QJSEngine;
+
+class HarbourUtil :
+ public QObject
+{
+ Q_OBJECT
+ class Private;
+
+public:
+ explicit HarbourUtil(QObject* aParent = Q_NULLPTR);
+
+ // Callback for qmlRegisterSingletonType<HarbourUtil>
+ static QObject* createSingleton(QQmlEngine*, QJSEngine*);
+
+ // QML (and possibly native) utilities
+ Q_INVOKABLE static QColor invertedColor(const QColor&);
+
+ // Static utilities
+ static QRgb invertedRgb(QRgb);
+ static QByteArray toHexBytes(const void*, size_t);
+ static QString toHex(const void*, size_t);
+ static inline QString toHex(const QByteArray& aData)
+ { return toHex(aData.constData(), aData.size()); }
+};
+
+#endif // HARBOUR_UTIL_H
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilauth-1.1.3.tar.gz/harbour-lib/qml/HarbourBadge.qml
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2018-2019 Jolla Ltd.
- * Copyright (C) 2018-2019 Slava Monich <slava@monich.com>
+ * Copyright (C) 2018-2022 Jolla Ltd.
+ * Copyright (C) 2018-2022 Slava Monich <slava@monich.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -11,8 +11,8 @@
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
+ * notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
* distribution.
* 3. Neither the names of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived
@@ -39,6 +39,9 @@
property real maxWidth: parent.width
property alias text: label.text
+ property alias backgroundColor: background.color
+ property alias textColor: label.color
+
readonly property real radius: height/2
width: Math.max(label.implicitWidth + radius, height)
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilauth-1.1.3.tar.gz/harbour-lib/src/HarbourBase32.cpp
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2019 Jolla Ltd.
- * Copyright (C) 2019 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2019-2022 Jolla Ltd.
+ * Copyright (C) 2019-2022 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of the BSD license as follows:
*
@@ -46,25 +46,33 @@
// HarbourBase32::Private
// ==========================================================================
-class HarbourBase32::Private {
+class HarbourBase32::Private
+{
public:
- static char nibbleToBase32(int nibble, char a);
- static int base32ToNibble(char a);
+ static char nibbleToBase32(int, char);
+ static int base32ToNibble(char);
};
-inline char HarbourBase32::Private::nibbleToBase32(int nibble, char a)
+inline
+char
+HarbourBase32::Private::nibbleToBase32(
+ int aNibble,
+ char aBaseChar)
{
- return (nibble < 26) ? (a + nibble) : ('2' + (nibble - 26));
+ return (aNibble < 26) ? (aBaseChar + aNibble) : ('2' + (aNibble - 26));
}
-inline int HarbourBase32::Private::base32ToNibble(char c)
+inline
+int
+HarbourBase32::Private::base32ToNibble(
+ char aChar)
{
- if (c >= 'a' && c <= 'z') {
- return c - 'a';
- } else if (c >= 'A' && c <= 'Z') {
- return c - 'A';
- } else if (c >= '2' && c <= '7') {
- return 26 + (c - '2');
+ if (aChar >= 'a' && aChar <= 'z') {
+ return aChar - 'a';
+ } else if (aChar >= 'A' && aChar <= 'Z') {
+ return aChar - 'A';
+ } else if (aChar >= '2' && aChar <= '7') {
+ return 26 + (aChar - '2');
} else {
return -1;
}
@@ -74,7 +82,9 @@
// HarbourBase32
// ==========================================================================
-bool HarbourBase32::isValidBase32(QString aBase32)
+bool
+HarbourBase32::isValidBase32(
+ QString aBase32)
{
const int n = aBase32.length();
const QChar* chars = aBase32.constData();
@@ -133,7 +143,9 @@
return !empty;
}
-QByteArray HarbourBase32::fromBase32(QString aBase32)
+QByteArray
+HarbourBase32::fromBase32(
+ const QString aBase32)
{
QByteArray out;
@@ -205,7 +217,10 @@
return out;
}
-QString HarbourBase32::toBase32(QByteArray aBinary, bool aLowerCase)
+QString
+HarbourBase32::toBase32(
+ const QByteArray aBinary,
+ bool aLowerCase)
{
QString str;
const int n = aBinary.size();
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilauth-1.1.3.tar.gz/harbour-lib/src/HarbourBase45.cpp
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2021 Jolla Ltd.
- * Copyright (C) 2021 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2021-2022 Jolla Ltd.
+ * Copyright (C) 2021-2022 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of the BSD license as follows:
*
@@ -39,7 +39,8 @@
// HarbourBase45::Private
// ==========================================================================
-class HarbourBase45::Private {
+class HarbourBase45::Private
+{
public:
enum {
BASE = 45,
@@ -48,7 +49,7 @@
};
static const char mapBase45[BASE];
static const int reverseMapBase45[REVERSE_MAP_SIZE];
- static bool isValidChar(uint x);
+ static bool isValidChar(uint);
};
const char HarbourBase45::Private::mapBase45[HarbourBase45::Private::BASE] = {
@@ -75,16 +76,22 @@
33, 34, 35
};
-inline bool HarbourBase45::Private::isValidChar(uint x)
+inline
+bool
+HarbourBase45::Private::isValidChar(
+ uint aChar)
{
- return (x < Private::REVERSE_MAP_SIZE) && Private::reverseMapBase45[x] >= 0;
+ return (aChar < Private::REVERSE_MAP_SIZE) &&
+ Private::reverseMapBase45[aChar] >= 0;
}
// ==========================================================================
// HarbourBase45::Private
// ==========================================================================
-bool HarbourBase45::isValidBase45(QString aBase45)
+bool
+HarbourBase45::isValidBase45(
+ const QString aBase45)
{
const int len = aBase45.length();
@@ -123,7 +130,9 @@
return false;
}
-QByteArray HarbourBase45::fromBase45(QString aBase45)
+QByteArray
+HarbourBase45::fromBase45(
+ const QString aBase45)
{
QByteArray out;
const int len = aBase45.length();
@@ -175,7 +184,9 @@
return out;
}
-QString HarbourBase45::toBase45(QByteArray aBinary)
+QString
+HarbourBase45::toBase45(
+ const QByteArray aBinary)
{
const uchar* ptr = (uchar*)aBinary.constData();
const int n = aBinary.size();
|
[-]
[+]
|
Added |
_service:tar_git:harbour-foilauth-1.1.3.tar.gz/harbour-lib/src/HarbourProtoBuf.cpp
^
|
@@ -0,0 +1,130 @@
+/*
+ * Copyright (C) 2022 Jolla Ltd.
+ * Copyright (C) 2022 Slava Monich <slava.monich@jolla.com>
+ *
+ * You may use this file under the terms of the BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "HarbourDebug.h"
+#include "HarbourProtoBuf.h"
+
+// https://developers.google.com/protocol-buffers/docs/encoding
+
+QByteArray*
+HarbourProtoBuf::appendVarInt(
+ QByteArray* aOutput,
+ quint64 aValue)
+{
+ uchar out[10];
+ quint64 value = aValue;
+ int i = sizeof(out) - 1;
+
+ out[i] = value & 0x7f;
+ value >>= 7;
+ while (value) {
+ out[--i] = 0x80 | (uchar)value;
+ value >>= 7;
+ }
+
+ const int n = sizeof(out) - i;
+
+ aOutput->reserve(aOutput->size() + n);
+ aOutput->append((char*)(out + i), n);
+ return aOutput;
+}
+
+QByteArray*
+HarbourProtoBuf::appendVarIntKeyValue(
+ QByteArray* aOutput,
+ quint64 aKey,
+ quint64 aValue)
+{
+ HASSERT((aKey & TYPE_MASK) == TYPE_VARINT);
+ return appendVarInt(appendVarInt(aOutput, aKey), aValue);
+}
+
+QByteArray*
+HarbourProtoBuf::appendDelimitedValue(
+ QByteArray* aOutput,
+ const QByteArray aValue)
+{
+ appendVarInt(aOutput, aValue.size())->append(aValue);
+ return aOutput;
+}
+
+QByteArray*
+HarbourProtoBuf::appendDelimitedKeyValue(
+ QByteArray* aOutput,
+ quint64 aKey,
+ const QByteArray aValue)
+{
+ HASSERT((aKey & TYPE_MASK) == TYPE_DELIMITED);
+ return appendDelimitedValue(appendVarInt(aOutput, aKey), aValue);
+}
+
+bool
+HarbourProtoBuf::parseVarInt(
+ GUtilRange* aPos,
+ quint64* aResult)
+{
+ quint64 value = 0;
+ const guint8* ptr = aPos->ptr;
+
+ for (int i = 0; i < 10 && ptr < aPos->end; i++, ptr++) {
+ value = (value << 7) | (*ptr & 0x7f);
+ if (!(*ptr & 0x80)) {
+ aPos->ptr = ptr + 1;
+ *aResult = value;
+ return true;
+ }
+ }
+
+ // Premature end of stream or too many bytes
+ *aResult = 0;
+ return false;
+}
+
+// A delimited value is stored as a size, encoded as a varint, followed
+// by the payload of type (message | string | bytes | packed)
+bool
+HarbourProtoBuf::parseDelimitedValue(
+ GUtilRange* aPos,
+ GUtilData* aPayload)
+{
+ GUtilRange pos = *aPos;
+ quint64 size;
+
+ if (parseVarInt(&pos, &size) && (pos.ptr + size) <= pos.end) {
+ aPayload->bytes = pos.ptr;
+ aPayload->size = size;
+ aPos->ptr = pos.ptr + size;
+ return true;
+ }
+ return false;
+}
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilauth-1.1.3.tar.gz/harbour-lib/src/HarbourTheme.cpp
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2018-2021 Jolla Ltd.
- * Copyright (C) 2018-2021 Slava Monich <slava@monich.com>
+ * Copyright (C) 2018-2022 Jolla Ltd.
+ * Copyright (C) 2018-2022 Slava Monich <slava@monich.com>
*
* You may use this file under the terms of the BSD license as follows:
*
@@ -31,9 +31,10 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include "HarbourTheme.h"
-#include "HarbourSystem.h"
#include "HarbourDebug.h"
+#include "HarbourSystem.h"
+#include "HarbourTheme.h"
+#include "HarbourUtil.h"
#include <QQmlEngine>
@@ -212,21 +213,12 @@
QColor HarbourTheme::invertedPrimaryColor() const
{
- return invertedColor(Private::primaryColor());
-}
-
-QRgb HarbourTheme::invertedRgb(QRgb aRgb)
-{
- return ((~(aRgb & RGB_MASK)) & RGB_MASK) | (aRgb & (~RGB_MASK));
+ return HarbourUtil::invertedColor(Private::primaryColor());
}
QColor HarbourTheme::invertedColor(const QColor& aColor)
{
- if (aColor.isValid()) {
- return QColor(invertedRgb(aColor.rgba()));
- } else {
- return aColor;
- }
+ return HarbourUtil::invertedColor(aColor);
}
qreal HarbourTheme::colorDifference(const QColor& aColor1, const QColor& aColor2)
|
[-]
[+]
|
Added |
_service:tar_git:harbour-foilauth-1.1.3.tar.gz/harbour-lib/src/HarbourUtil.cpp
^
|
@@ -0,0 +1,127 @@
+/*
+ * Copyright (C) 2022 Jolla Ltd.
+ * Copyright (C) 2022 Slava Monich <slava.monich@jolla.com>
+ *
+ * You may use this file under the terms of the BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "HarbourUtil.h"
+
+// ==========================================================================
+// HarbourUtil::Private
+// ==========================================================================
+
+class HarbourUtil::Private
+{
+public:
+ static const char hex[];
+};
+
+const char HarbourUtil::Private::hex[] = "0123456789abcdef";
+
+// ==========================================================================
+// HarbourUtil
+// ==========================================================================
+
+HarbourUtil::HarbourUtil(
+ QObject* aParent) :
+ QObject(aParent)
+{
+}
+
+// Callback for qmlRegisterSingletonType<HarbourUtil>
+QObject*
+HarbourUtil::createSingleton(
+ QQmlEngine*,
+ QJSEngine*)
+{
+ return new HarbourUtil();
+}
+
+QColor
+HarbourUtil::invertedColor(
+ const QColor& aColor)
+{
+ if (aColor.isValid()) {
+ const QRgb inv = invertedRgb(aColor.rgba());
+
+ return QColor(qRed(inv), qGreen(inv), qBlue(inv), qAlpha(inv));
+ } else {
+ return aColor;
+ }
+}
+
+QRgb
+HarbourUtil::invertedRgb(
+ QRgb aRgb)
+{
+ return ((~(aRgb & RGB_MASK)) & RGB_MASK) | (aRgb & (~RGB_MASK));
+}
+
+QString
+HarbourUtil::toHex(
+ const void* aData,
+ size_t aSize)
+{
+ QString hex;
+
+ if (aSize > 0) {
+ const uchar* bytes = (const uchar*)aData;
+
+ hex.reserve(2 * aSize);
+ for (size_t i = 0; i < aSize; i++) {
+ const uchar b = bytes[i];
+
+ hex.append(QChar(Private::hex[(b & 0xf0) >> 4]));
+ hex.append(QChar(Private::hex[b & 0x0f]));
+ }
+ }
+ return hex;
+}
+
+QByteArray
+HarbourUtil::toHexBytes(
+ const void* aData,
+ size_t aSize)
+{
+ QByteArray hex;
+
+ if (aSize > 0) {
+ const uchar* bytes = (const uchar*)aData;
+
+ hex.reserve(2 * aSize);
+ for (size_t i = 0; i < aSize; i++) {
+ const uchar b = bytes[i];
+
+ hex.append(QChar(Private::hex[(b & 0xf0) >> 4]));
+ hex.append(QChar(Private::hex[b & 0x0f]));
+ }
+ }
+ return hex;
+}
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilauth-1.1.3.tar.gz/harbour-lib/test/Makefile
^
|
@@ -4,3 +4,4 @@
%:
@$(MAKE) -C TestHarbourBase32 $*
@$(MAKE) -C TestHarbourBase45 $*
+ @$(MAKE) -C TestHarbourUtil $*
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilauth-1.1.3.tar.gz/harbour-lib/test/Makefile.common
^
|
@@ -31,6 +31,8 @@
SRC_DIR = .
TOP_DIR = ../..
HARBOUR_DIR = $(TOP_DIR)
+HARBOUR_INCLUDE_DIR = $(HARBOUR_DIR)/include
+HARBOUR_SRC_DIR = $(HARBOUR_DIR)/src
BUILD_DIR = build
DEBUG_BUILD_DIR = $(BUILD_DIR)/debug
RELEASE_BUILD_DIR = $(BUILD_DIR)/release
@@ -44,7 +46,7 @@
LD = $(CC)
MOC = qtchooser -run-tool=moc -qt=5
WARNINGS = -Wall
-INCLUDES = -I$(BUILD_DIR) -I$(HARBOUR_DIR)/include
+INCLUDES = -I$(BUILD_DIR) -I$(HARBOUR_INCLUDE_DIR)
BASE_FLAGS = -fPIC
BASE_LDFLAGS = $(BASE_FLAGS) $(LDFLAGS)
BASE_CFLAGS = $(BASE_FLAGS) $(CFLAGS)
@@ -84,6 +86,9 @@
$(MOC_CPP:%.cpp=$(COVERAGE_BUILD_DIR)/moc_cpp_%.o) \
$(SRC:%.cpp=$(COVERAGE_BUILD_DIR)/%.o) \
$(HARBOUR_SRC:%.cpp=$(COVERAGE_BUILD_DIR)/harbour_%.o)
+GEN_FILES = \
+ $(MOC_H:%.h=$(BUILD_DIR)/moc_%.cpp) \
+ $(MOC_CPP:%.cpp=$(BUILD_DIR)/%.moc)
#
# Dependencies
@@ -96,6 +101,7 @@
endif
endif
+$(GEN_FILES): | $(BUILD_DIR)
$(DEBUG_OBJS): | $(DEBUG_BUILD_DIR)
$(RELEASE_OBJS): | $(RELEASE_BUILD_DIR)
$(COVERAGE_OBJS): | $(COVERAGE_BUILD_DIR)
@@ -139,10 +145,10 @@
$(COVERAGE_BUILD_DIR):
mkdir -p $@
-$(BUILD_DIR)/moc_%.cpp : $(APP_DIR)/%.h
+$(BUILD_DIR)/moc_%.cpp : $(HARBOUR_INCLUDE_DIR)/%.h
$(MOC) $< -o $@
-$(BUILD_DIR)/%.moc : $(APP_DIR)/%.cpp
+$(BUILD_DIR)/%.moc : $(HARBOUR_SRC_DIR)/%.cpp
$(MOC) $< -o $@
$(DEBUG_BUILD_DIR)/%.o : $(SRC_DIR)/%.cpp
@@ -163,31 +169,22 @@
$(COVERAGE_BUILD_DIR)/moc_h_%.o : $(BUILD_DIR)/moc_%.cpp $(BUILD_DIR)
$(CC) -c $(COVERAGE_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@
-$(DEBUG_BUILD_DIR)/moc_cpp_%.o : $(HARBOUR_DIR)/%.cpp $(BUILD_DIR)/%.moc
+$(DEBUG_BUILD_DIR)/moc_cpp_%.o : $(HARBOUR_SRC_DIR)/%.cpp $(BUILD_DIR)/%.moc
$(CC) -c $(DEBUG_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@
-$(RELEASE_BUILD_DIR)/moc_cpp_%.o : $(HARBOUR_DIR)/%.cpp $(BUILD_DIR)/%.moc
+$(RELEASE_BUILD_DIR)/moc_cpp_%.o : $(HARBOUR_SRC_DIR)/%.cpp $(BUILD_DIR)/%.moc
$(CC) -c $(RELEASE_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@
-$(COVERAGE_BUILD_DIR)/moc_cpp_%.o : $(HARBOUR_DIR)/%.cpp $(BUILD_DIR)/%.moc
+$(COVERAGE_BUILD_DIR)/moc_cpp_%.o : $(HARBOUR_SRC_DIR)/%.cpp $(BUILD_DIR)/%.moc
$(CC) -c $(COVERAGE_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@
-$(DEBUG_BUILD_DIR)/app_%.o : $(APP_DIR)/%.cpp
+$(DEBUG_BUILD_DIR)/harbour_%.o : $(HARBOUR_SRC_DIR)/%.cpp
$(CC) -c $(DEBUG_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@
-$(RELEASE_BUILD_DIR)/app_%.o : $(APP_DIR)/%.cpp
+$(RELEASE_BUILD_DIR)/harbour_%.o : $(HARBOUR_SRC_DIR)/%.cpp
$(CC) -c $(RELEASE_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@
-$(COVERAGE_BUILD_DIR)/app_%.o : $(APP_DIR)/%.cpp
- $(CC) -c $(COVERAGE_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@
-
-$(DEBUG_BUILD_DIR)/harbour_%.o : $(HARBOUR_DIR)/src/%.cpp
- $(CC) -c $(DEBUG_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@
-
-$(RELEASE_BUILD_DIR)/harbour_%.o : $(HARBOUR_DIR)/src/%.cpp
- $(CC) -c $(RELEASE_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@
-
-$(COVERAGE_BUILD_DIR)/harbour_%.o : $(HARBOUR_DIR)/src/%.cpp
+$(COVERAGE_BUILD_DIR)/harbour_%.o : $(HARBOUR_SRC_DIR)/%.cpp
$(CC) -c $(COVERAGE_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@
$(DEBUG_EXE): $(DEBUG_OBJS)
|
[-]
[+]
|
Added |
_service:tar_git:harbour-foilauth-1.1.3.tar.gz/harbour-lib/test/TestHarbourUtil/Makefile
^
|
@@ -0,0 +1,8 @@
+# -*- Mode: makefile-gmake -*-
+
+PKGS = Qt5Gui
+EXE = TestHarbourUtil
+MOC_H = HarbourUtil.h
+HARBOUR_SRC = HarbourUtil.cpp
+
+include ../Makefile.common
|
[-]
[+]
|
Added |
_service:tar_git:harbour-foilauth-1.1.3.tar.gz/harbour-lib/test/TestHarbourUtil/TestHarbourUtil.cpp
^
|
@@ -0,0 +1,115 @@
+/*
+ * Copyright (C) 2022 Jolla Ltd.
+ * Copyright (C) 2022 Slava Monich <slava.monich@jolla.com>
+ *
+ * You may use this file under the terms of the BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "HarbourUtil.h"
+
+#include <glib.h>
+
+/*==========================================================================*
+ * object
+ *==========================================================================*/
+
+static
+void
+test_object(
+ void)
+{
+ QObject* obj = HarbourUtil::createSingleton(Q_NULLPTR, Q_NULLPTR);
+
+ g_assert(qobject_cast<HarbourUtil*>(obj));
+ delete obj;
+}
+
+/*==========================================================================*
+ * invertColor
+ *==========================================================================*/
+
+static
+void
+test_invertColor(
+ void)
+{
+ g_assert_cmpuint(HarbourUtil::invertedRgb(0x12345678), == ,0x12cba987);
+ const QColor original(0xcb,0xa9,0x87,0x12);
+ const QColor inverted(0x34,0x56,0x78,0x12);
+ g_assert(HarbourUtil::invertedColor(original) == inverted);
+ g_assert(!HarbourUtil::invertedColor(QColor()).isValid());
+}
+
+/*==========================================================================*
+ * toHex
+ *==========================================================================*/
+
+static
+void
+test_toHex(
+ void)
+{
+ static const char data[] = {
+ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A,
+ 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14
+ };
+
+ const QByteArray dataBytes(data, sizeof(data));
+ const QByteArray hex(dataBytes.toHex());
+
+ g_assert(HarbourUtil::toHex(QByteArray()).isEmpty());
+ g_assert(HarbourUtil::toHex(Q_NULLPTR, 0).isEmpty());
+ g_assert(HarbourUtil::toHexBytes(Q_NULLPTR, 0).isEmpty());
+ g_assert(HarbourUtil::toHex(data, sizeof(data)) == QString::fromLatin1(hex));
+ g_assert_cmpstr(HarbourUtil::toHexBytes(data, sizeof(data)).constData(), == ,
+ hex.constData());
+}
+
+/*==========================================================================*
+ * Common
+ *==========================================================================*/
+
+#define TEST_(name) "/HarbourUtil/" name
+
+int main(int argc, char* argv[])
+{
+ g_test_init(&argc, &argv, NULL);
+ g_test_add_func(TEST_("object"), test_object);
+ g_test_add_func(TEST_("invertColor"), test_invertColor);
+ g_test_add_func(TEST_("toHex"), test_toHex);
+ return g_test_run();
+}
+
+/*
+ * Local Variables:
+ * mode: C++
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilauth-1.1.3.tar.gz/harbour-lib/test/coverage/run
^
|
@@ -5,7 +5,8 @@
TESTS="\
TestHarbourBase32 \
-TestHarbourBase45"
+TestHarbourBase45 \
+TestHarbourUtil"
function err() {
echo "*** ERROR!" $1
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilauth-1.1.3.tar.gz/qml/CoverPage.qml
^
|
@@ -50,180 +50,195 @@
text: showAppTitle ? qsTrId("foilauth-app_name") : " "
}
- Item {
- id: backgroundCircle
+ Flipable {
+ id: flipable
- readonly property real size: Math.floor(parent.width * 0.8)
- width: backgroundCircle.size
- height: backgroundCircle.size
- anchors.centerIn: parent
- transform: Scale {
- id: backgroundCircleScale
+ readonly property real circleSize: Math.floor(parent.width * 0.8)
+ readonly property bool flipped: cover.foilModel.keyAvailable
+ property bool flipping
+ property real targetAngle
- origin.x: width / 2
- }
+ anchors.fill: parent
- Rectangle {
+ front: Item {
anchors.fill: parent
- color: "white"
- radius: height/2
- opacity: 0.2
- }
-
- HarbourFitLabel {
- id: noPasswordLabel
-
- width: Math.round(parent.width - 2 * parent.x)
- height: width
- anchors.centerIn: parent
- maxFontSize: Theme.fontSizeHuge
- font {
- family: Theme.fontFamilyHeading
- bold: true
+
+ Image {
+ source: "images/foilauth.svg"
+ height: flipable.circleSize
+ sourceSize.height: flipable.circleSize
+ anchors.centerIn: parent
+ smooth: true
+ opacity: 0.8
}
- text: "\u2022\u2022\u2022\u2022\u2022\u2022"
- visible: list.count == 0 && foilModel.keyAvailable
}
- }
- Image {
- id: lockedImage
+ back: Item {
+ anchors.fill: parent
- source: "images/foilauth.svg"
- height: backgroundCircle.size
- sourceSize.height: backgroundCircle.size
- anchors.centerIn: backgroundCircle
- smooth: true
- opacity: 0.8
- Scale {
- id: lockedImageScale
+ Rectangle {
+ id: backgroundCircle
- origin.x: width / 2
- }
- }
+ width: flipable.circleSize
+ height: flipable.circleSize
+ anchors.centerIn: parent
+ color: "white"
+ radius: flipable.circleSize/2
+ opacity: 0.2
+ }
- Connections {
- target: cover.foilModel
- onKeyAvailableChanged: {
- if (cover.foilModel.keyAvailable) {
- // This transition is not visible, there's no reason to animate it
- lockedImage.visible = false
- lockedImageScale.xScale = 0
- backgroundCircleScale.xScale = 1
- backgroundCircle.visible = true
- } else {
- lockFlipAnimation.start()
+ HarbourFitLabel {
+ width: Math.round(backgroundCircle.width - 2 * parent.x)
+ height: width
+ anchors.centerIn: parent
+ maxFontSize: Theme.fontSizeHuge
+ font {
+ family: Theme.fontFamilyHeading
+ bold: true
+ }
+ text: "\u2022\u2022\u2022\u2022\u2022\u2022"
+ visible: list.count == 0 && foilModel.keyAvailable
}
- }
- }
- // Flip animation
- SequentialAnimation {
- id: lockFlipAnimation
-
- alwaysRunToEnd: true
-
- function switchToImage() {
- lockedImage.visible = true
- backgroundCircle.visible = false
- }
- NumberAnimation {
- easing.type: Easing.InOutSine
- target: backgroundCircleScale
- property: "xScale"
- from: 1
- to: 0
- duration: 125
- }
- ScriptAction { script: lockFlipAnimation.switchToImage() }
- NumberAnimation {
- easing.type: Easing.InOutSine
- target: lockedImageScale
- property: "xScale"
- from: 0
- to: 1
- duration: 125
- }
- }
+ SlideshowView {
+ id: list
- Timer {
- id: currentIndexTimer
+ property string currentLabel
- running: list.count > 1 && displayOn
- interval: 5000
- repeat: true
- onTriggered: list.incrementCurrentIndex()
- }
+ interactive: false
+ anchors.fill: parent
+ model: FoilAuthFavoritesModel {
+ sourceModel: foilModel
+ }
+ delegate: Item {
+ id: passwordDelegate
+ width: parent.width
+ height: list.height
+
+ readonly property string modelLabel: model.label
+ readonly property bool currentItem: passwordDelegate.PathView.isCurrentItem
+
+ function updateCurrentLabel() {
+ if (currentItem) {
+ list.currentLabel = modelLabel
+ }
+ }
+
+ Component.onCompleted: updateCurrentLabel()
+ onCurrentItemChanged: updateCurrentLabel()
+ onModelLabelChanged: updateCurrentLabel()
+
+ Label {
+ readonly property real maxWidth: parent.width - 2 * Theme.paddingMedium
+ width: Math.min(paintedWidth, maxWidth)
+ anchors {
+ top: parent.top
+ horizontalCenter: parent.horizontalCenter
+ }
+ height: implicitHeight + Theme.paddingLarge
+ horizontalAlignment: Text.AlignLeft
+ verticalAlignment: Text.AlignVCenter
+ truncationMode: TruncationMode.Fade
+ text: modelLabel
+ }
+
+ HarbourFitLabel {
+ id: passwordLabel
+
+ y: Math.round(backgroundCircle.y - list.y + (backgroundCircle.height - height)/2)
+ width: Math.round(backgroundCircle.width - 2 * backgroundCircle.x)
+ height: width
+ anchors.horizontalCenter: parent.horizontalCenter
+ maxFontSize: Theme.fontSizeHuge
+ font {
+ family: Theme.fontFamilyHeading
+ bold: true
+ }
+ transform: HarbourTextFlip {
+ enabled: displayOn
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilauth-1.1.3.tar.gz/qml/EditAuthTokenDialog.qml
^
|
@@ -20,10 +20,9 @@
property alias secret: secretField.text
property alias digits: digitsField.text
property alias counter: counterField.text
- property alias timeShift: timeShiftField.text
+ property alias timeshift: timeshiftField.text
signal tokenAccepted(var dialog)
- signal replacedWith(var page)
onAccepted: tokenAccepted(thisDialog)
@@ -31,7 +30,7 @@
id: generator
ecLevel: FoilAuthSettings.qrCodeEcLevel
- text: FoilAuth.toUri(type, secret, label, issuer, digits, counter, timeShift, algorithm)
+ text: FoilAuth.toUri(type, secret, label, issuer, digits, counter, timeshift, algorithm)
}
Item {
@@ -62,6 +61,9 @@
DialogHeader {
id: header
+ //: Dialog button
+ //% "Save"
+ acceptText: qsTrId("foilauth-edit_token-save")
}
TextField {
@@ -120,7 +122,7 @@
enabled: !qrCodeOnly
EnterKey.iconSource: "image://theme/icon-m-enter-next"
- EnterKey.onClicked: timeShiftField.focus = true
+ EnterKey.onClicked: timeshiftField.focus = true
}
TextField {
@@ -141,7 +143,7 @@
}
TextField {
- id: timeShiftField
+ id: timeshiftField
width: parent.columnWidth
//: Text field label (number of password digits)
@@ -169,7 +171,6 @@
menu: ContextMenu {
x: 0
width: algorithmComboBox.width
- MenuItem { text: "MD5" }
//: Menu item for the default digest algorithm
//% "%1 (default)"
MenuItem { text: qsTrId("foilauth-token-digest_algorithm-default").arg("SHA1") }
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilauth-1.1.3.tar.gz/qml/ScanPage.qml
^
|
@@ -16,7 +16,9 @@
readonly property bool canShowViewFinder: Qt.application.active &&
(status === PageStatus.Active || status === PageStatus.Deactivating)
- signal done(var token)
+ signal tokenDetected(var token)
+ signal tokensDetected(var tokens)
+ signal skip()
onStatusChanged: {
if (status === PageStatus.Active) {
@@ -87,6 +89,10 @@
}
}
+ FoilAuthImportModel {
+ id: importModel
+ }
+
QrCodeScanner {
id: scanner
@@ -95,45 +101,18 @@
rotation: orientationAngle()
onScanFinished: {
- if (result.valid) {
- var token = FoilAuth.parseUri(result.text)
- if (token.valid) {
- markImageProvider.image = image
- markImage.visible = true
- unsupportedCodeNotification.close()
- pageStackPopTimer.token = token
- pageStackPopTimer.start()
- } else {
- var tokens = FoilAuth.parseMigrationUri(result.text)
- if (tokens.length === 1) {
- markImageProvider.image = image
- markImage.visible = true
- unsupportedCodeNotification.close()
- pageStackPopTimer.token = tokens[0]
- pageStackPopTimer.start()
- } else if (tokens.length > 1) {
- markImageProvider.image = image
- markImage.visible = true
- unsupportedCodeNotification.close()
- var page = pageStack.push(Qt.resolvedUrl("SelectTokenPage.qml"), {
- allowedOrientations: thisPage.allowedOrientations,
- tokens: tokens
- })
- page.tokenSelected.connect(function(token) {
- thisPage.done(token)
- })
- } else if (lastInvalidCode !== result.text) {
- lastInvalidCode = result.text
- markImageProvider.image = image
- markImage.visible = true
- unsupportedCodeNotification.publish()
- restartScanTimer.start()
- } else {
- if (thisPage.canScan) {
- scanner.start()
- }
- }
- }
+ importModel.setUri(result.text)
+ if (importModel.count > 0) {
+ markImageProvider.image = image
+ markImage.visible = true
+ unsupportedCodeNotification.close()
+ pageStackPopTimer.start()
+ } else if (lastInvalidCode !== result.text) {
+ lastInvalidCode = result.text
+ markImageProvider.image = image
+ markImage.visible = true
+ unsupportedCodeNotification.publish()
+ restartScanTimer.start()
} else if (thisPage.canScan) {
scanner.start()
}
@@ -143,10 +122,15 @@
Timer {
id: pageStackPopTimer
- property var token
-
interval: 1000
- onTriggered: thisPage.done(token)
+ onTriggered: {
+ var n = importModel.count
+ if (n === 1) {
+ thisPage.tokenDetected(importModel.getToken(0))
+ } else if (n > 1) {
+ thisPage.tokensDetected(importModel)
+ }
+ }
}
Timer {
@@ -342,7 +326,7 @@
//: Button label (skip scanning)
//% "Skip"
text: qsTrId("foilauth-scan-skip_button")
- onClicked: thisPage.done({ "valid" : false })
+ onClicked: thisPage.skip()
}
Image {
|
[-]
[+]
|
Added |
_service:tar_git:harbour-foilauth-1.1.3.tar.gz/qml/SelectTokensPage.qml
^
|
@@ -0,0 +1,138 @@
+import QtQuick 2.0
+import Sailfish.Silica 1.0
+import harbour.foilauth 1.0
+
+import "harbour"
+
+Dialog {
+ id: thisDialog
+
+ canAccept: importModel.haveSelectedTokens
+
+ property var tokens
+
+ signal tokensAccepted(var tokens)
+
+ readonly property color _selectionBackground: Theme.rgba(Theme.highlightBackgroundColor, 0.1)
+
+ Component.onCompleted: importModel.setTokens(tokens)
+
+ onAccepted: tokensAccepted(importModel.selectedTokens)
+
+ SilicaListView {
+ id: list
+
+ anchors.fill: parent
+ width: parent.width
+ clip: true
+ model: FoilAuthImportModel {
+ id: importModel
+ }
+
+ header: DialogHeader {
+ //: Dialog button
+ //% "Save"
+ acceptText: qsTrId("foilauth-edit_token-save")
+ //: Dialog title
+ //% "Select tokens to add"
+ title: qsTrId("foilauth-select_tokens-title-add_tokens")
+ }
+
+ delegate: ListItem {
+ id: delegate
+
+ contentHeight: Theme.itemSizeMedium
+
+ readonly property int itemIndex: model.index
+ readonly property bool itemSelected: model.selected
+
+ Separator {
+ width: parent.width
+ color: Theme.highlightColor
+ horizontalAlignment: Qt.AlignHCenter
+ anchors.top: parent.top
+ }
+
+ Rectangle {
+ width: parent.width
+ height: delegate.contentHeight
+ color: (delegate.itemSelected && !delegate.highlighted) ? _selectionBackground : "transparent"
+ }
+
+ Column {
+ spacing: Theme.paddingMedium
+ anchors {
+ left: parent.left
+ leftMargin: Theme.horizontalPageMargin
+ right: icon.left
+ rightMargin: Theme.paddingLarge
+ verticalCenter: parent.verticalCenter
+ }
+
+ Label {
+ width: parent.width
+ color: delegate.itemSelected ? Theme.highlightColor : Theme.secondaryHighlightColor
+ truncationMode: TruncationMode.Fade
+ font.bold: delegate.itemSelected
+ text: model.label
+ }
+
+ Label {
+ width: parent.width
+ color: Theme.secondaryHighlightColor
+ truncationMode: TruncationMode.Fade
+ font.pixelSize: Theme.fontSizeExtraSmall
+ text: model.issuer
+ visible: text !== ""
+ }
+ }
+
+ HarbourHighlightIcon {
+ id: icon
+
+ source: model.selected ? "images/checked.svg" : "images/unchecked.svg"
+ sourceSize.width: Theme.iconSizeMedium
+ highlightColor: delegate.down ? Theme.highlightColor : Theme.primaryColor
+ anchors {
+ right: parent.right
+ rightMargin: Theme.horizontalPageMargin
+ verticalCenter: parent.verticalCenter
+ }
+ }
+
+ menu: Component {
+ ContextMenu {
+ hasContent: delegate.itemSelected
+ MenuItem {
+ //: Generic menu item
+ //% "Edit"
+ text: qsTrId("foilauth-menu-edit")
+ onClicked: {
+ var token = list.model.getToken(delegate.itemIndex)
+ pageStack.push(Qt.resolvedUrl("EditAuthTokenDialog.qml"), {
+ "allowedOrientations": allowedOrientations,
+ "type": token.type,
+ "label": token.label,
+ "issuer": token.issuer,
+ "secret": token.secret,
+ "digits": token.digits,
+ "counter": token.counter,
+ "timeshift": token.timeshift,
+ "algorithm": token.algorithm
+ }).tokenAccepted.connect(delegate.applyChanges)
+ }
+ }
+ }
+ }
+
+ onClicked: model.selected = !model.selected
+
+ function applyChanges(dialog) {
+ // Leave issuer as is
+ list.model.setToken(itemIndex, dialog.type, dialog.algorithm,
+ dialog.label, dialog.issuer, dialog.secret, dialog.digits,
+ dialog.counter, dialog.timeshift)
+ }
+ }
+ }
+}
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilauth-1.1.3.tar.gz/qml/TokenListView.qml
^
|
@@ -155,32 +155,43 @@
//% "Add token"
text: qsTrId("foilauth-menu-new_auth_token")
onClicked: {
- pageStack.push("ScanPage.qml", {
+ var page = pageStack.push("ScanPage.qml", {
"allowedOrientations": allowedOrientations
- }).done.connect(function(token) {
- var props = {
- //: Dialog button
- //% "Save"
- acceptText: qsTrId("foilauth-edit_token-save"),
+ })
+
+ page.skip.connect(function() {
+ pageStack.replace(editAuthTokenDialogComponent, {
+ //% "Add token"
+ "dialogTitle": qsTrId("foilauth-add_token-title")
+ }).tokenAccepted.connect(function(dialog) {
+ FoilAuthModel.addToken(dialog.type, dialog.secret, dialog.label, dialog.issuer,
+ dialog.digits, dialog.counter, dialog.timeshift, dialog.algorithm)
+ })
+ })
+ page.tokenDetected.connect(function(token) {
+ pageStack.replace(editAuthTokenDialogComponent, {
//: Dialog title
//% "Add token"
- dialogTitle: qsTrId("foilauth-add_token-title")
- }
- if (token.valid) {
- props["type"] = token.type
- props["label"] = token.label
- props["issuer"] = token.issuer
- props["secret"] = token.secret
- props["digits"] = token.digits
- props["counter"] = token.counter
- props["timeShift"] = token.timeshift
- props["algorithm"] = token.algorithm
- }
- pageStack.replace(editAuthTokenDialogComponent, props).tokenAccepted.connect(function(dialog) {
+ "dialogTitle": qsTrId("foilauth-add_token-title"),
+ "type": token.type,
+ "label": token.label,
+ "issuer": token.issuer,
+ "secret": token.secret,
+ "digits": token.digits,
+ "counter": token.counter,
+ "timeshift": token.timeshift,
+ "algorithm": token.algorithm
+ }).tokenAccepted.connect(function(dialog) {
FoilAuthModel.addToken(dialog.type, dialog.secret, dialog.label, dialog.issuer,
dialog.digits, dialog.counter, dialog.timeshift, dialog.algorithm)
})
})
+ page.tokensDetected.connect(function(model) {
+ pageStack.replace(Qt.resolvedUrl("SelectTokensPage.qml"), {
+ "allowedOrientations": thisPage.allowedOrientations,
+ "tokens": model.getTokens()
+ }).tokensAccepted.connect(FoilAuthModel.addTokens)
+ })
}
}
}
@@ -240,7 +251,7 @@
pageStack.push(Qt.resolvedUrl("QRCodePage.qml"), {
allowedOrientations: mainPage.allowedOrientations,
uri: FoilAuth.toUri(model.type, model.secret, model.label, model.issuer,
- model.digits, model.counter, model.timeShift, model.algorithm)
+ model.digits, model.counter, model.timeshift, model.algorithm)
})
}
}
@@ -251,9 +262,6 @@
onClicked: {
var item = tokenListDelegate
pageStack.push(editAuthTokenDialogComponent, {
- //: Dialog button
- //% "Save"
- acceptText: qsTrId("foilauth-edit_token-save"),
//: Dialog title
//% "Edit token"
dialogTitle: qsTrId("foilauth-edit_token-title"),
@@ -264,7 +272,7 @@
algorithm: model.algorithm,
digits: model.digits,
counter: model.counter,
- timeShift: model.timeShift
+ timeshift: model.timeshift
}).tokenAccepted.connect(function(dialog) {
item.updateToken(dialog)
})
@@ -391,7 +399,7 @@
model.algorithm = token.algorithm
model.digits = token.digits
model.counter = token.counter
- model.timeShift = token.timeShift
+ model.timeshift = token.timeshift
}
property real pressX
|
[-]
[+]
|
Added |
_service:tar_git:harbour-foilauth-1.1.3.tar.gz/qml/images/checked.svg
^
|
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<svg
+ version="1.1"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:xlink="http://www.w3.org/1999/xlink"
+ x="0px"
+ y="0px"
+ width="64px"
+ height="64px"
+ viewBox="0 0 64 64"
+ style="enable-background:new 0 0 64 64"
+ xml:space="preserve">
+ <g>
+ <rect
+ style="opacity:0;fill:#ffffff"
+ width="64"
+ height="64"/>
+ <circle
+ style="opacity:0.2;fill:none;stroke:#ffffff;stroke-opacity:1;stroke-width:2;stroke-miterlimit:4;stroke-dasharray:none"
+ cx="32"
+ cy="32"
+ r="24"/>
+ <path
+ style="fill:#ffffff;stroke-width:0"
+ d="M 28.46611,43 H 28.44073 C 27.83965,42.9909 27.272618,42.664 26.886342,42.1 L 19.1,30.819337 c -0.191281,-0.276737 0.04332,-0.93 0.326828,-1.116433 0.283517,-0.1861 0.965214,-0.195319 1.155876,0.08142 L 27.913315,40.629 c 0.16,0.230816 0.353467,0.368583 0.546605,0.371 0.278195,0 0.41378,-0.265627 0.557757,-0.355 L 43.44965,21.035359 c 0.198709,-0.270695 0.902641,-0.306581 1.179967,-0.111415 0.277945,0.194562 0.453774,0.76186 0.253827,1.033159 l -14.86,20.19335 C 29.624318,42.691239 29.058523,43 28.46611,43 Z"/>
+ </g>
+</svg>
|
[-]
[+]
|
Added |
_service:tar_git:harbour-foilauth-1.1.3.tar.gz/qml/images/unchecked.svg
^
|
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<svg
+ version="1.1"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:xlink="http://www.w3.org/1999/xlink"
+ x="0px"
+ y="0px"
+ width="64px"
+ height="64px"
+ viewBox="0 0 64 64"
+ style="enable-background:new 0 0 64 64"
+ xml:space="preserve">
+ <g>
+ <rect
+ style="opacity:0;fill:#ffffff"
+ width="64"
+ height="64"/>
+ <circle
+ style="opacity:0.2;fill:none;stroke:#ffffff;stroke-opacity:1;stroke-width:2;stroke-miterlimit:4;stroke-dasharray:none"
+ cx="32"
+ cy="32"
+ r="24"/>
+ </g>
+</svg>
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilauth-1.1.3.tar.gz/settings/settings.qml
^
|
@@ -26,7 +26,7 @@
description: applicationName ?
//: Settings page header description (app version)
//% "Version %1"
- qsTrId("foilauth-settings_page-header-version").arg("1.1.2") : ""
+ qsTrId("foilauth-settings_page-header-version").arg("1.1.3") : ""
Image {
id: appIcon
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilauth-1.1.3.tar.gz/src/FoilAuth.cpp
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2019-2021 Jolla Ltd.
- * Copyright (C) 2019-2021 Slava Monich <slava@monich.com>
+ * Copyright (C) 2019-2022 Jolla Ltd.
+ * Copyright (C) 2019-2022 Slava Monich <slava@monich.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -61,11 +61,13 @@
// FoilAuth::Private
// ==========================================================================
-class FoilAuth::Private : public QObject {
+class FoilAuth::Private :
+ public QObject
+{
Q_OBJECT
public:
- Private(FoilAuth* aParent);
+ Private(FoilAuth*);
static bool foilPicsInstalled();
static bool foilNotesInstalled();
@@ -92,31 +94,37 @@
iOtherFoilAppsInstalled = otherFoilAppsInstalled();
}
-inline FoilAuth* FoilAuth::Private::foilAuth() const
+inline
+FoilAuth*
+FoilAuth::Private::foilAuth() const
{
return qobject_cast<FoilAuth*>(parent());
}
-bool FoilAuth::Private::foilPicsInstalled()
+bool
+FoilAuth::Private::foilPicsInstalled()
{
const bool installed = QFile::exists(FOILPICS_PATH);
HDEBUG("FoilPics is" << (installed ? "installed" : "not installed"));
return installed;
}
-bool FoilAuth::Private::foilNotesInstalled()
+bool
+FoilAuth::Private::foilNotesInstalled()
{
const bool installed = QFile::exists(FOILNOTES_PATH);
HDEBUG("FoilNotes is" << (installed ? "installed" : "not installed"));
return installed;
}
-bool FoilAuth::Private::otherFoilAppsInstalled()
+bool
+FoilAuth::Private::otherFoilAppsInstalled()
{
return foilPicsInstalled() || foilNotesInstalled();
}
-void FoilAuth::Private::checkFoilAppsInstalled()
+void
+FoilAuth::Private::checkFoilAppsInstalled()
{
const bool haveOtherFoilApps = otherFoilAppsInstalled();
if (iOtherFoilAppsInstalled != haveOtherFoilApps) {
@@ -136,17 +144,23 @@
}
// Callback for qmlRegisterSingletonType<FoilAuth>
-QObject* FoilAuth::createSingleton(QQmlEngine* aEngine, QJSEngine* aScript)
+QObject*
+FoilAuth::createSingleton(
+ QQmlEngine*,
+ QJSEngine*)
{
return new FoilAuth;
}
-bool FoilAuth::otherFoilAppsInstalled() const
+bool
+FoilAuth::otherFoilAppsInstalled() const
{
return iPrivate->iOtherFoilAppsInstalled;
}
-QSize FoilAuth::toSize(QVariant aVariant)
+QSize
+FoilAuth::toSize(
+ QVariant aVariant)
{
// e.g. "1920x1080"
if (aVariant.isValid()) {
@@ -165,22 +179,24 @@
return QSize();
}
-bool FoilAuth::isValidBase32(QString aBase32)
+bool
+FoilAuth::isValidBase32(
+ const QString aBase32)
{
return HarbourBase32::isValidBase32(aBase32);
}
-QByteArray FoilAuth::fromBase32(QString aBase32)
-{
- return HarbourBase32::fromBase32(aBase32);
-}
-
-QString FoilAuth::toBase32(QByteArray aBinary, bool aLowerCase)
+QString
+FoilAuth::toBase32(
+ const QByteArray aBinary,
+ bool aLowerCase)
{
return HarbourBase32::toBase32(aBinary, aLowerCase);
}
-QByteArray FoilAuth::toByteArray(GBytes* aData)
+QByteArray
+FoilAuth::toByteArray(
+ GBytes* aData)
{
if (aData) {
gsize size;
@@ -194,13 +210,19 @@
// QStringList is an array like object, but it is not an array in QML.
// Couldn't figure out how to modify it from QML
-QStringList FoilAuth::stringListRemove(QStringList aList, QString aString)
+QStringList
+FoilAuth::stringListRemove(
+ QStringList aList,
+ const QString aString)
{
aList.removeOne(aString);
return aList;
}
-FoilOutput* FoilAuth::createFoilFile(QString aDestDir, GString* aOutPath)
+FoilOutput*
+FoilAuth::createFoilFile(
+ const QString aDestDir,
+ GString* aOutPath)
{
// Generate random name for the encrypted file
FoilOutput* out = NULL;
@@ -222,7 +244,9 @@
return out;
}
-QString FoilAuth::createEmptyFoilFile(QString aDestDir)
+QString
+FoilAuth::createEmptyFoilFile(
+ const QString aDestDir)
{
GString* dest = g_string_sized_new(aDestDir.size() + 9);
FoilOutput* out = createFoilFile(aDestDir, dest);
@@ -236,19 +260,26 @@
return path;
}
-uint FoilAuth::TOTP(QByteArray aSecret, quint64 aTime, uint aMaxPass, DigestAlgorithm aAlgorithm)
+uint
+FoilAuth::TOTP(
+ const QByteArray aSecret,
+ quint64 aTime,
+ uint aMaxPass,
+ DigestAlgorithm aAlgorithm)
{
return FoilAuth::HOTP(aSecret, aTime/PERIOD, aMaxPass, aAlgorithm);
}
-uint FoilAuth::HOTP(QByteArray aSecret, quint64 aCounter, uint aMaxPass, DigestAlgorithm aAlgorithm)
+uint
+FoilAuth::HOTP(
+ const QByteArray aSecret,
+ quint64 aCounter,
+ uint aMaxPass,
+ DigestAlgorithm aAlgorithm)
{
const guint64 msg = htobe64(aCounter);
GType (*digest_type)(void) = foil_impl_digest_sha1_get_type;
switch (aAlgorithm) {
- case DigestAlgorithmMD5:
- digest_type = foil_impl_digest_md5_get_type;
- break;
case DigestAlgorithmSHA1:
digest_type = foil_impl_digest_sha1_get_type;
break;
@@ -272,14 +303,18 @@
return mini_hash % aMaxPass;
}
-QString FoilAuth::toUri(Type aType, QString aSecretBase32, QString aLabel,
+QString
+FoilAuth::toUri(
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilauth-1.1.3.tar.gz/src/FoilAuth.h
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2019-2021 Jolla Ltd.
- * Copyright (C) 2019-2021 Slava Monich <slava@monich.com>
+ * Copyright (C) 2019-2022 Jolla Ltd.
+ * Copyright (C) 2019-2022 Slava Monich <slava@monich.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -34,7 +34,7 @@
#ifndef FOILAUTH_H
#define FOILAUTH_H
-#include "FoilAuthTypes.h"
+#include "FoilAuthToken.h"
#include "foil_types.h"
@@ -48,7 +48,10 @@
class QJSEngine;
// Static utilities
-class FoilAuth : public QObject, public FoilAuthTypes {
+class FoilAuth :
+ public QObject,
+ public FoilAuthTypes
+{
Q_OBJECT
Q_PROPERTY(bool otherFoilAppsInstalled READ otherFoilAppsInstalled NOTIFY otherFoilAppsInstalledChanged)
Q_DISABLE_COPY(FoilAuth)
@@ -60,7 +63,6 @@
// Export these to QML
enum Algorithm {
- AlgorithmMD5 = DigestAlgorithmMD5,
AlgorithmSHA1 = DigestAlgorithmSHA1,
AlgorithmSHA256 = DigestAlgorithmSHA256,
AlgorithmSHA512 = DigestAlgorithmSHA512,
@@ -76,31 +78,30 @@
explicit FoilAuth(QObject* aParent = Q_NULLPTR);
// Callback for qmlRegisterSingletonType<FoilAuth>
- static QObject* createSingleton(QQmlEngine* aEngine, QJSEngine* aScript);
+ static QObject* createSingleton(QQmlEngine*, QJSEngine*);
bool otherFoilAppsInstalled() const;
// Static utilities
- static QSize toSize(QVariant aVariant);
- static QByteArray fromBase32(QString aBase32);
- static QString toBase32(QByteArray aBinary, bool aLowerCase = true);
- static QByteArray toByteArray(GBytes* aData);
- static FoilOutput* createFoilFile(QString aDestDir, GString* aOutPath);
- static QString createEmptyFoilFile(QString aDestDir);
- static QString migrationUri(QByteArray aData);
- static uint TOTP(QByteArray aSecret, quint64 aTime, uint aMaxPass,
+ static QSize toSize(QVariant);
+ static QString toBase32(QByteArray, bool aLowerCase = true);
+ static QByteArray toByteArray(GBytes*);
+ static FoilOutput* createFoilFile(const QString, GString*);
+ static QString createEmptyFoilFile(const QString);
+ static QString migrationUri(const QByteArray);
+ static uint TOTP(const QByteArray, quint64 aTime, uint aMaxPass,
DigestAlgorithm aAlgorithm = DEFAULT_ALGORITHM);
- static uint HOTP(QByteArray aSecret, quint64 aCounter, uint aMaxPass,
+ static uint HOTP(const QByteArray, quint64 aCounter, uint aMaxPass,
DigestAlgorithm aAlgorithm = DEFAULT_ALGORITHM);
// Invokable from QML
- Q_INVOKABLE static QString toUri(Type aType, QString aSecretBase32,
- QString aLabel, QString aIssuer, int aDigits, quint64 aCounter,
- int aTimeShift, Algorithm aAlgorithm);
- Q_INVOKABLE static QVariantMap parseUri(QString aUri);
- Q_INVOKABLE static QVariantList parseMigrationUri(QString aUri);
- Q_INVOKABLE static bool isValidBase32(QString aBase32);
- Q_INVOKABLE static QStringList stringListRemove(QStringList aList, QString aString);
+ Q_INVOKABLE static QString toUri(Type aType, const QString aSecretBase32,
+ const QString aLabel, const QString aIssuer, int aDigits,
+ quint64 aCounter, int aTimeShift, Algorithm);
+ Q_INVOKABLE static FoilAuthToken parseUri(const QString);
+ Q_INVOKABLE static QList<FoilAuthToken> parseMigrationUri(const QString);
+ Q_INVOKABLE static bool isValidBase32(const QString);
+ Q_INVOKABLE static QStringList stringListRemove(QStringList, const QString);
Q_SIGNALS:
void otherFoilAppsInstalledChanged();
|
[-]
[+]
|
Added |
_service:tar_git:harbour-foilauth-1.1.3.tar.gz/src/FoilAuthImportModel.cpp
^
|
@@ -0,0 +1,587 @@
+/*
+ * Copyright (C) 2022 Jolla Ltd.
+ * Copyright (C) 2022 Slava Monich <slava@monich.com>
+ *
+ * You may use this file under the terms of BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "FoilAuthImportModel.h"
+#include "FoilAuth.h"
+
+#include "HarbourBase32.h"
+#include "HarbourDebug.h"
+
+#include <gutil_misc.h>
+
+#include <foil_input.h>
+#include <foil_util.h>
+
+#include <QUrl>
+
+// Model roles
+#define MODEL_ROLES_(first,role,last) \
+ first(Type,type) \
+ role(Algorithm,algorithm) \
+ role(Label,label) \
+ role(Issuer,issuer) \
+ role(Secret,secret) \
+ role(Digits,digits) \
+ role(Counter,counter) \
+ role(Timeshift,timeshift) \
+ last(Selected,selected)
+
+#define MODEL_ROLES(role) \
+ MODEL_ROLES_(role,role,role)
+
+// ==========================================================================
+// FoilAuthImportModel::ModelData
+// ==========================================================================
+
+class FoilAuthImportModel::ModelData
+{
+public:
+ typedef QList<ModelData*> List;
+
+ enum Role {
+#define FIRST(X,x) FirstRole = Qt::UserRole, X##Role = FirstRole,
+#define ROLE(X,x) X##Role,
+#define LAST(X,x) X##Role, LastRole = X##Role
+ MODEL_ROLES_(FIRST,ROLE,LAST)
+#undef FIRST
+#undef ROLE
+#undef LAST
+ };
+
+ ModelData(FoilAuthToken);
+
+ QVariant get(Role) const;
+
+public:
+ bool iSelected;
+ FoilAuthToken iToken;
+};
+
+FoilAuthImportModel::ModelData::ModelData(
+ FoilAuthToken aToken) :
+ iSelected(true),
+ iToken(aToken)
+{
+}
+
+QVariant
+FoilAuthImportModel::ModelData::get(
+ Role aRole) const
+{
+ switch (aRole) {
+ case TypeRole: return (int) iToken.type();
+ case AlgorithmRole: return (int) iToken.algorithm();
+ case LabelRole: return iToken.label();
+ case IssuerRole: return iToken.issuer();
+ case SecretRole: return iToken.secretBase32();
+ case DigitsRole: return iToken.digits();
+ case CounterRole: return iToken.counter();
+ case TimeshiftRole: return iToken.timeshift();
+ case SelectedRole: return iSelected;
+ }
+ return QVariant();
+}
+
+// ==========================================================================
+// FoilAuthImportModel::Private
+// ==========================================================================
+
+class FoilAuthImportModel::Private
+{
+public:
+ Private(FoilAuthImportModel*);
+ ~Private();
+
+ ModelData* dataAt(int);
+ void setItems(const ModelData::List);
+ void updateSelectedTokens();
+
+public:
+ FoilAuthImportModel* iModel;
+ ModelData::List iList;
+ QList<FoilAuthToken> iSelectedTokens;
+};
+
+FoilAuthImportModel::Private::Private(
+ FoilAuthImportModel* aModel) :
+ iModel(aModel)
+{
+}
+
+FoilAuthImportModel::Private::~Private()
+{
+ qDeleteAll(iList);
+}
+
+inline
+FoilAuthImportModel::ModelData*
+FoilAuthImportModel::Private::dataAt(
+ int aIndex)
+{
+ return (aIndex >= 0 && aIndex < iList.count()) ?
+ iList.at(aIndex) : Q_NULLPTR;
+}
+
+void
+FoilAuthImportModel::Private::setItems(
+ const ModelData::List aList)
+{
+ const int prevCount = iList.count();
+ const int newCount = aList.count();
+ const int changed = qMin(prevCount, newCount);
+ const QList<FoilAuthToken> prevSelectedTokens(iSelectedTokens);
+
+ if (newCount < prevCount) {
+ iModel->beginRemoveRows(QModelIndex(), newCount, prevCount - 1);
+ qDeleteAll(iList);
+ iList = aList;
+ iModel->endRemoveRows();
+ } else if (newCount > prevCount) {
+ iModel->beginInsertRows(QModelIndex(), prevCount, newCount - 1);
+ qDeleteAll(iList);
+ iList = aList;
+ iModel->endInsertRows();
+ } else {
+ qDeleteAll(iList);
+ iList = aList;
+ }
+
+ updateSelectedTokens();
+ if (prevSelectedTokens != iSelectedTokens) {
+ if (!prevSelectedTokens.count() != !iSelectedTokens.count()) {
+ Q_EMIT iModel->haveSelectedTokensChanged();
+ }
+ Q_EMIT iModel->selectedTokensChanged();
+ }
+ if (changed > 0) {
+ Q_EMIT iModel->dataChanged(iModel->index(0), iModel->index(changed - 1));
+ }
+}
+
+void
+FoilAuthImportModel::Private::updateSelectedTokens()
+{
+ QList<FoilAuthToken> list;
+ const int n = iList.count();
+
+ for (int i = 0; i < n; i++) {
+ const ModelData* entry = iList.at(i);
+
|
[-]
[+]
|
Added |
_service:tar_git:harbour-foilauth-1.1.3.tar.gz/src/FoilAuthImportModel.h
^
|
@@ -0,0 +1,83 @@
+/*
+ * Copyright (C) 2022 Jolla Ltd.
+ * Copyright (C) 2022 Slava Monich <slava@monich.com>
+ *
+ * You may use this file under the terms of BSD license as follows:
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the names of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef FOILAUTH_IMPORT_MODEL_H
+#define FOILAUTH_IMPORT_MODEL_H
+
+#include "FoilAuthToken.h"
+
+#include <QAbstractListModel>
+
+class FoilAuthImportModel :
+ public QAbstractListModel
+{
+ Q_OBJECT
+ Q_DISABLE_COPY(FoilAuthImportModel)
+ Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
+ Q_PROPERTY(QList<FoilAuthToken> selectedTokens READ selectedTokens NOTIFY selectedTokensChanged)
+ Q_PROPERTY(bool haveSelectedTokens READ haveSelectedTokens NOTIFY haveSelectedTokensChanged)
+
+public:
+ FoilAuthImportModel(QObject* aParent = Q_NULLPTR);
+ ~FoilAuthImportModel();
+
+ QList<FoilAuthToken> selectedTokens() const;
+ bool haveSelectedTokens() const;
+
+ Q_INVOKABLE void setUri(const QString);
+ Q_INVOKABLE void setToken(FoilAuthToken);
+ Q_INVOKABLE void setTokens(const QList<FoilAuthToken>);
+
+ Q_INVOKABLE FoilAuthToken getToken(int) const;
+ Q_INVOKABLE QList<FoilAuthToken> getTokens() const;
+ Q_INVOKABLE void setToken(int, int, int, const QString, const QString, const QString, int, int, int);
+
+ // QAbstractItemModel
+ Qt::ItemFlags flags(const QModelIndex&) const Q_DECL_OVERRIDE;
+ QHash<int,QByteArray> roleNames() const Q_DECL_OVERRIDE;
+ int rowCount(const QModelIndex& aParent = QModelIndex()) const Q_DECL_OVERRIDE;
+ QVariant data(const QModelIndex&, int) const Q_DECL_OVERRIDE;
+ bool setData(const QModelIndex&, const QVariant&, int) Q_DECL_OVERRIDE;
+
+Q_SIGNALS:
+ void countChanged();
+ void selectedTokensChanged();
+ void haveSelectedTokensChanged();
+
+private:
+ class ModelData;
+ class Private;
+ Private* iPrivate;
+};
+
+#endif // FOILAUTH_IMPORT_MODEL_H
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilauth-1.1.3.tar.gz/src/FoilAuthModel.cpp
^
|
@@ -35,6 +35,7 @@
#include "FoilAuthToken.h"
#include "FoilAuth.h"
+#include "HarbourBase32.h"
#include "HarbourDebug.h"
#include "HarbourTask.h"
@@ -96,7 +97,7 @@
role(Digits,digits) \
role(Algorithm,algorithm) \
role(Counter,counter) \
- role(TimeShift,timeShift) \
+ role(Timeshift,timeshift) \
role(Label,label) \
role(PrevPassword,prevPassword) \
role(CurrentPassword,currentPassword) \
@@ -113,23 +114,27 @@
private:
Util();
public:
- static const FoilMsgEncryptOptions* encryptionOptions(FoilMsgEncryptOptions* opt);
+ static const FoilMsgEncryptOptions* encryptionOptions(FoilMsgEncryptOptions*);
};
-const FoilMsgEncryptOptions* FoilAuthModel::Util::encryptionOptions(FoilMsgEncryptOptions* opt)
-{
- foilmsg_encrypt_defaults(opt);
- opt->key_type = ENCRYPT_KEY_TYPE;
- opt->signature = SIGNATURE_TYPE;
- return opt;
+const FoilMsgEncryptOptions*
+FoilAuthModel::Util::encryptionOptions(
+ FoilMsgEncryptOptions* aOpt)
+{
+ foilmsg_encrypt_defaults(aOpt);
+ aOpt->key_type = ENCRYPT_KEY_TYPE;
+ aOpt->signature = SIGNATURE_TYPE;
+ return aOpt;
}
// ==========================================================================
// FoilAuthModel::ModelData
// ==========================================================================
-class FoilAuthModel::ModelData : public FoilAuthTypes {
+class FoilAuthModel::ModelData :
+ public FoilAuthTypes
+{
public:
enum Role {
#define FIRST(X,x) FirstRole = Qt::UserRole, X##Role = FirstRole,
@@ -143,80 +148,89 @@
typedef QList<ModelData*> List;
- ModelData(QString aPath, AuthType aType,
- QByteArray aSecret, QString aLabel, QString aIssuer,
- int aDigits = FoilAuthToken::DEFAULT_DIGITS,
- int aCounter = FoilAuthToken::DEFAULT_COUNTER,
- int aTimeShift = FoilAuthToken::DEFAULT_TIMESHIFT,
+ ModelData(const QString aPath, AuthType aType,
+ const QByteArray aSecret, const QString aLabel, const QString aIssuer,
+ int aDigits = DEFAULT_DIGITS, int aCounter = DEFAULT_COUNTER,
+ int aTimeShift = DEFAULT_TIMESHIFT,
DigestAlgorithm aAlgorithm = DEFAULT_ALGORITHM,
bool aFavorite = true);
- ModelData(QString aPath, const FoilAuthToken& aToken, bool aFavorite = true);
+ ModelData(const QString, const FoilAuthToken&, bool aFavorite = true);
QVariant get(Role aRole) const;
- QString label() { return iToken.iLabel; }
+ const QString label() { return iToken.label(); }
void setTokenPath(QString aPath);
- static AuthType headerAuthType(const FoilMsg* aMsg);
- static DigestAlgorithm headerAlgorithm(const FoilMsg* aMsg);
- static QString headerString(const FoilMsg* aMsg, const char* aKey);
- static quint64 headerUint64(const FoilMsg* aMsg, const char* aKey, quint64 aDefault);
- static int headerInt(const FoilMsg* aMsg, const char* aKey, int aDefault);
- static bool headerBool(const FoilMsg* aMsg, const char* aKey, bool aDefault);
+ static AuthType headerAuthType(const FoilMsg*);
+ static DigestAlgorithm headerAlgorithm(const FoilMsg*);
+ static QString headerString(const FoilMsg*, const char*);
+ static quint64 headerUint64(const FoilMsg*, const char*, quint64);
+ static int headerInt(const FoilMsg*, const char*, int);
+ static bool headerBool(const FoilMsg*, const char*, bool);
public:
QString iPath;
QString iId;
bool iFavorite;
FoilAuthToken iToken;
- QString iSecretBase32;
QString iPrevPassword;
QString iCurrentPassword;
QString iNextPassword;
};
-FoilAuthModel::ModelData::ModelData(QString aPath, AuthType aType,
- QByteArray aSecret, QString aLabel, QString aIssuer, int aDigits,
- int aCounter, int aTimeShift, DigestAlgorithm aAlgorithm,
+FoilAuthModel::ModelData::ModelData(
+ const QString aPath,
+ AuthType aType,
+ const QByteArray aSecret,
+ const QString aLabel,
+ const QString aIssuer,
+ int aDigits,
+ int aCounter,
+ int aTimeShift,
+ DigestAlgorithm aAlgorithm,
bool aFavorite) :
iPath(aPath),
iId(QFileInfo(aPath).fileName()),
iFavorite(aFavorite),
- iToken(aType, aSecret, aLabel, aIssuer, aDigits, aCounter, aTimeShift, aAlgorithm),
- iSecretBase32(FoilAuth::toBase32(aSecret))
+ iToken(aType, aSecret, aLabel, aIssuer, aDigits, aCounter, aTimeShift, aAlgorithm)
{
- HDEBUG(iSecretBase32 << aLabel);
+ HDEBUG(iToken.secretBase32() << iToken.label());
}
-FoilAuthModel::ModelData::ModelData(QString aPath, const FoilAuthToken& aToken,
+FoilAuthModel::ModelData::ModelData(
+ const QString aPath,
+ const FoilAuthToken& aToken,
bool aFavorite) :
iPath(aPath),
iId(QFileInfo(aPath).fileName()),
iFavorite(aFavorite),
- iToken(aToken),
- iSecretBase32(FoilAuth::toBase32(iToken.iBytes))
+ iToken(aToken)
{
- HDEBUG(iSecretBase32 << iToken.iLabel);
+ HDEBUG(iToken.secretBase32() << iToken.label());
}
-void FoilAuthModel::ModelData::setTokenPath(QString aPath)
+void
+FoilAuthModel::ModelData::setTokenPath(
+ QString aPath)
{
iPath = aPath;
iId = QFileInfo(aPath).fileName();
}
-QVariant FoilAuthModel::ModelData::get(Role aRole) const
+QVariant
+FoilAuthModel::ModelData::get(
+ Role aRole) const
{
switch (aRole) {
case ModelIdRole: return iId;
case FavoriteRole: return iFavorite;
- case SecretRole: return iSecretBase32;
- case IssuerRole: return iToken.iIssuer;
- case DigitsRole: return iToken.iDigits;
- case TypeRole: return (int)iToken.iType;
- case AlgorithmRole: return (int)iToken.iAlgorithm;
- case CounterRole: return iToken.iCounter;
- case TimeShiftRole: return iToken.iTimeShift;
- case LabelRole: return iToken.iLabel;
+ case SecretRole: return iToken.secretBase32();
+ case IssuerRole: return iToken.issuer();
+ case DigitsRole: return iToken.digits();
+ case TypeRole: return (int)iToken.type();
+ case AlgorithmRole: return (int)iToken.algorithm();
+ case CounterRole: return iToken.counter();
+ case TimeshiftRole: return iToken.timeshift();
+ case LabelRole: return iToken.label();
case PrevPasswordRole: return iPrevPassword;
case CurrentPasswordRole: return iCurrentPassword;
case NextPasswordRole: return iNextPassword;
@@ -224,7 +238,9 @@
return QVariant();
}
-FoilAuthTypes::AuthType FoilAuthModel::ModelData::headerAuthType(const FoilMsg* aMsg)
+FoilAuthTypes::AuthType
+FoilAuthModel::ModelData::headerAuthType(
+ const FoilMsg* aMsg)
{
const char* value = foilmsg_get_value(aMsg, HEADER_TYPE);
if (value) {
@@ -237,13 +253,13 @@
return DEFAULT_AUTH_TYPE;
}
-FoilAuthTypes::DigestAlgorithm FoilAuthModel::ModelData::headerAlgorithm(const FoilMsg* aMsg)
+FoilAuthTypes::DigestAlgorithm
+FoilAuthModel::ModelData::headerAlgorithm(
+ const FoilMsg* aMsg)
{
const char* value = foilmsg_get_value(aMsg, HEADER_ALGORITHM);
if (value) {
- if (!g_ascii_strcasecmp(value, FOILAUTH_ALGORITHM_MD5)) {
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilauth-1.1.3.tar.gz/src/FoilAuthModel.h
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2019-2021 Jolla Ltd.
- * Copyright (C) 2019-2021 Slava Monich <slava@monich.com>
+ * Copyright (C) 2019-2022 Jolla Ltd.
+ * Copyright (C) 2019-2022 Slava Monich <slava@monich.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -34,6 +34,8 @@
#ifndef FOILAUTH_MODEL_H
#define FOILAUTH_MODEL_H
+#include "FoilAuthToken.h"
+
#include "foil_types.h"
#include <QAbstractListModel>
@@ -81,7 +83,7 @@
FoilModelReady
};
- FoilAuthModel(QObject* aParent = NULL);
+ FoilAuthModel(QObject* aParent = Q_NULLPTR);
static int typeRole();
static int favoriteRole();
@@ -93,39 +95,37 @@
bool timerActive() const;
FoilState foilState() const;
- int indexOf(const FoilAuthToken* aToken) const;
- bool contains(const FoilAuthToken* aToken) const;
- bool containsSecret(QByteArray aToken) const;
- void addToken(const FoilAuthToken* aToken, bool aFavorite);
-
- Q_INVOKABLE void generateKey(int aBits, QString aPassword);
- Q_INVOKABLE bool checkPassword(QString aPassword);
- Q_INVOKABLE bool changePassword(QString aOld, QString aNew);
+ int indexOf(FoilAuthToken) const;
+ bool contains(FoilAuthToken) const;
+ bool containsSecret(QByteArray) const;
+ void addToken(FoilAuthToken, bool aFavorite);
+
+ Q_INVOKABLE void generateKey(int, QString);
+ Q_INVOKABLE bool checkPassword(const QString);
+ Q_INVOKABLE bool changePassword(const QString aOld, const QString aNew);
Q_INVOKABLE void lock(bool aTimeout);
- Q_INVOKABLE bool unlock(QString aPassword);
- Q_INVOKABLE int millisecondsLeft();
+ Q_INVOKABLE bool unlock(const QString aPassword);
- Q_INVOKABLE bool addToken(int aType, QString aTokenBase32,
- QString aLabel, QString aIssuer, int aDigits, int aCounter,
- int aTimeShift, int aAlgorithm);
- Q_INVOKABLE bool addTokenUri(QString aUri);
- Q_INVOKABLE void deleteToken(QString aId);
- Q_INVOKABLE void deleteTokens(QStringList aIds);
+ Q_INVOKABLE bool addToken(int aType, const QString aTokenBase32,
+ const QString aLabel, const QString aIssuer, int aDigits,
+ int aCounter, int aTimeShift, int aAlgorithm);
+ Q_INVOKABLE void addTokens(const QList<FoilAuthToken>);
+ Q_INVOKABLE void deleteToken(const QString);
+ Q_INVOKABLE void deleteTokens(const QStringList);
Q_INVOKABLE void deleteAll();
- Q_INVOKABLE QStringList getIdsAt(const QList<int> aRows) const;
- Q_INVOKABLE QStringList generateMigrationUris(const QList<int> aRows) const;
+ Q_INVOKABLE QStringList getIdsAt(const QList<int>) const;
+ Q_INVOKABLE QStringList generateMigrationUris(const QList<int>) const;
// QAbstractItemModel
- Qt::ItemFlags flags(const QModelIndex& aIndex) const Q_DECL_OVERRIDE;
+ Qt::ItemFlags flags(const QModelIndex&) const Q_DECL_OVERRIDE;
QHash<int,QByteArray> roleNames() const Q_DECL_OVERRIDE;
int rowCount(const QModelIndex& aParent = QModelIndex()) const Q_DECL_OVERRIDE;
- QVariant data(const QModelIndex& aIndex, int aRole) const Q_DECL_OVERRIDE;
- bool setData(const QModelIndex& aIndex, const QVariant& aValue, int aRole) Q_DECL_OVERRIDE;
- bool moveRows(const QModelIndex &aSrcParent, int aSrcRow, int aCount,
- const QModelIndex &aDestParent, int aDestRow) Q_DECL_OVERRIDE;
+ QVariant data(const QModelIndex&, int) const Q_DECL_OVERRIDE;
+ bool setData(const QModelIndex&, const QVariant&, int) Q_DECL_OVERRIDE;
+ bool moveRows(const QModelIndex&, int, int, const QModelIndex&, int) Q_DECL_OVERRIDE;
// Callback for qmlRegisterSingletonType<FoilAuthModel>
- static QObject* createSingleton(QQmlEngine* aEngine, QJSEngine* aScript);
+ static QObject* createSingleton(QQmlEngine*, QJSEngine*);
Q_SIGNALS:
void countChanged();
@@ -143,7 +143,7 @@
};
// Inline wrappers
-inline bool FoilAuthModel::contains(const FoilAuthToken* aToken) const
+inline bool FoilAuthModel::contains(const FoilAuthToken aToken) const
{ return indexOf(aToken) >= 0; }
#endif // FOILAUTH_MODEL_H
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilauth-1.1.3.tar.gz/src/FoilAuthToken.cpp
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2019-2021 Jolla Ltd.
- * Copyright (C) 2019-2021 Slava Monich <slava@monich.com>
+ * Copyright (C) 2019-2022 Jolla Ltd.
+ * Copyright (C) 2019-2022 Slava Monich <slava@monich.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -34,13 +34,17 @@
#include "FoilAuthToken.h"
#include "FoilAuth.h"
+#include "HarbourBase32.h"
#include "HarbourDebug.h"
+#include "HarbourProtoBuf.h"
#include "qrencode.h"
-#include <foil_util.h>
#include <foil_random.h>
+#include <gutil_misc.h>
+
+#include <QAtomicInt>
#include <QUrl>
#define FOILAUTH_KEY_TYPE "type"
@@ -65,293 +69,15 @@
const QString FoilAuthToken::TYPE_TOTP(FOILAUTH_TYPE_TOTP);
const QString FoilAuthToken::TYPE_HOTP(FOILAUTH_TYPE_HOTP);
-const QString FoilAuthToken::ALGORITHM_MD5(FOILAUTH_ALGORITHM_MD5);
const QString FoilAuthToken::ALGORITHM_SHA1(FOILAUTH_ALGORITHM_SHA1);
const QString FoilAuthToken::ALGORITHM_SHA256(FOILAUTH_ALGORITHM_SHA256);
const QString FoilAuthToken::ALGORITHM_SHA512(FOILAUTH_ALGORITHM_SHA512);
#define FOILAUTH_SCHEME "otpauth"
-FoilAuthToken::FoilAuthToken() :
- iType(DEFAULT_AUTH_TYPE),
- iAlgorithm(DEFAULT_ALGORITHM),
- iCounter(DEFAULT_COUNTER),
- iDigits(DEFAULT_DIGITS),
- iTimeShift(DEFAULT_TIMESHIFT)
-{
-}
-
-FoilAuthToken::FoilAuthToken(const FoilAuthToken& aToken) :
- iType(aToken.iType),
- iAlgorithm(aToken.iAlgorithm),
- iBytes(aToken.iBytes),
- iLabel(aToken.iLabel),
- iIssuer(aToken.iIssuer),
- iCounter(aToken.iCounter),
- iDigits(aToken.iDigits),
- iTimeShift(aToken.iTimeShift)
-{
-}
-
-FoilAuthToken::FoilAuthToken(AuthType aType, QByteArray aBytes, QString aLabel,
- QString aIssuer, int aDigits, quint64 aCounter, int aTimeShift,
- DigestAlgorithm aAlgorithm) :
- iType(AuthTypeTOTP),
- iAlgorithm(DEFAULT_ALGORITHM),
- iBytes(aBytes),
- iLabel(aLabel),
- iIssuer(aIssuer),
- iCounter(aCounter),
- iDigits(DEFAULT_DIGITS),
- iTimeShift(aTimeShift)
-{
- setType(aType);
- setDigits(aDigits);
- setAlgorithm(aAlgorithm);
-}
-
-FoilAuthToken& FoilAuthToken::operator=(const FoilAuthToken& aToken)
-{
- iType = aToken.iType;
- iAlgorithm = aToken.iAlgorithm;
- iBytes = aToken.iBytes;
- iLabel = aToken.iLabel;
- iIssuer = aToken.iIssuer;
- iCounter = aToken.iCounter;
- iDigits = aToken.iDigits;
- iTimeShift = aToken.iTimeShift;
- return *this;
-}
-
-bool FoilAuthToken::equals(const FoilAuthToken& aToken) const
-{
- return iType == aToken.iType &&
- iAlgorithm == aToken.iAlgorithm &&
- iDigits == aToken.iDigits &&
- iCounter == aToken.iCounter &&
- iTimeShift == aToken.iTimeShift &&
- iBytes == aToken.iBytes &&
- iLabel == aToken.iLabel &&
- iIssuer == aToken.iIssuer;
-}
-
-uint FoilAuthToken::password(quint64 aTime) const
-{
- uint maxPass = 10;
- for (int i = 1; i < iDigits; i++) {
- maxPass *= 10;
- }
- return (iType == AuthTypeHOTP) ?
- FoilAuth::HOTP(iBytes, iCounter, maxPass, iAlgorithm) :
- FoilAuth::TOTP(iBytes, aTime, maxPass, iAlgorithm);
-}
-
-QString FoilAuthToken::passwordString(quint64 aTime) const
-{
- return QString().sprintf("%0*u", iDigits, password(aTime));
-}
-
-bool FoilAuthToken::setDigits(int aDigits)
-{
- if (aDigits >= 1 && aDigits <= MAX_DIGITS) {
- iDigits = aDigits;
- return true;
- }
- return false;
-}
-
-bool FoilAuthToken::setType(AuthType aType)
-{
- switch (aType) {
- case AuthTypeTOTP:
- case AuthTypeHOTP:
- iType = aType;
- return true;
- }
- return false;
-}
-
-bool FoilAuthToken::setAlgorithm(DigestAlgorithm aAlgorithm)
-{
- switch (aAlgorithm) {
- case DigestAlgorithmMD5:
- case DigestAlgorithmSHA1:
- case DigestAlgorithmSHA256:
- case DigestAlgorithmSHA512:
- iAlgorithm = aAlgorithm;
- return true;
- }
- return false;
-}
-
-bool FoilAuthToken::parseUri(QString aUri)
-{
- const QByteArray uri(aUri.trimmed().toUtf8());
-
- FoilParsePos pos;
- pos.ptr = (guint8*)uri.constData();
- pos.end = pos.ptr + uri.size();
-
- // Check scheme + type prefix
- FoilBytes prefixBytes;
- AuthType type = AuthTypeTOTP;
- foil_bytes_from_string(&prefixBytes, FOILAUTH_SCHEME "://"
- FOILAUTH_TYPE_TOTP "/");
- bool prefixOK = foil_parse_skip_bytes(&pos, &prefixBytes);
- if (!prefixOK) {
- type = AuthTypeHOTP;
- foil_bytes_from_string(&prefixBytes, FOILAUTH_SCHEME "://"
- FOILAUTH_TYPE_HOTP "/");
- prefixOK = foil_parse_skip_bytes(&pos, &prefixBytes);
- }
-
- if (prefixOK) {
- QByteArray label, secret, issuer, algorithm, digits, counter;
- while (pos.ptr < pos.end && pos.ptr[0] != '?') {
- label.append(*pos.ptr++);
- }
-
- FoilBytes secretTag;
- FoilBytes issuerTag;
- FoilBytes digitsTag;
- FoilBytes counterTag;
- FoilBytes algorithmTag;
- foil_bytes_from_string(&secretTag, FOILAUTH_KEY_SECRET "=");
- foil_bytes_from_string(&issuerTag, FOILAUTH_KEY_ISSUER "=");
- foil_bytes_from_string(&digitsTag, FOILAUTH_KEY_DIGITS "=");
- foil_bytes_from_string(&counterTag, FOILAUTH_KEY_COUNTER "=");
- foil_bytes_from_string(&algorithmTag, FOILAUTH_KEY_ALGORITHM "=");
-
- while (pos.ptr < pos.end) {
- pos.ptr++;
-
- QByteArray* value =
- foil_parse_skip_bytes(&pos, &secretTag) ? &secret :
- foil_parse_skip_bytes(&pos, &issuerTag) ? &issuer :
- foil_parse_skip_bytes(&pos, &digitsTag) ? &digits :
- foil_parse_skip_bytes(&pos, &counterTag) ? &counter :
- foil_parse_skip_bytes(&pos, &algorithmTag) ? &algorithm :
- Q_NULLPTR;
-
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilauth-1.1.3.tar.gz/src/FoilAuthToken.h
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2019-2021 Jolla Ltd.
- * Copyright (C) 2019-2021 Slava Monich <slava@monich.com>
+ * Copyright (C) 2019-2022 Jolla Ltd.
+ * Copyright (C) 2019-2022 Slava Monich <slava@monich.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -36,15 +36,31 @@
#include "FoilAuthTypes.h"
-#include <QString>
#include <QByteArray>
-#include <QVariantMap>
+#include <QDebug>
#include <QList>
+#include <QMetaType>
+#include <QString>
+#include <QVariantMap>
+
+// Read-only token object, cheap to copy
+class FoilAuthToken
+{
+ Q_GADGET
+ Q_PROPERTY(bool valid READ isValid CONSTANT)
+ Q_PROPERTY(int type READ type CONSTANT)
+ Q_PROPERTY(int algorithm READ algorithm CONSTANT)
+ Q_PROPERTY(QString label READ label CONSTANT)
+ Q_PROPERTY(QString issuer READ issuer CONSTANT)
+ Q_PROPERTY(QString secret READ secretBase32 CONSTANT)
+ Q_PROPERTY(int digits READ digits CONSTANT)
+ Q_PROPERTY(int counter READ counter CONSTANT)
+ Q_PROPERTY(int timeshift READ timeshift CONSTANT)
+
+ class Private;
+ FoilAuthToken(Private*);
-class FoilAuthToken : public FoilAuthTypes {
-class Private;
public:
- static const QString ALGORITHM_MD5;
static const QString ALGORITHM_SHA1;
static const QString ALGORITHM_SHA256;
static const QString ALGORITHM_SHA512;
@@ -67,53 +83,64 @@
FoilAuthToken();
FoilAuthToken(const FoilAuthToken& aToken);
- FoilAuthToken(AuthType aType, QByteArray aBytes, QString aLabel,
- QString aIssuer, int aDigits = DEFAULT_DIGITS,
- quint64 aCounter = DEFAULT_COUNTER,
- int aTimeShift = DEFAULT_TIMESHIFT,
- DigestAlgorithm aAlgorithm = DEFAULT_ALGORITHM);
+ FoilAuthToken(FoilAuthTypes::AuthType, QByteArray, QString, QString,
+ int aDigits = FoilAuthTypes::DEFAULT_DIGITS,
+ quint64 aCounter = FoilAuthTypes::DEFAULT_COUNTER,
+ int aTimeshift = FoilAuthTypes::DEFAULT_TIMESHIFT,
+ FoilAuthTypes::DigestAlgorithm aAlgorithm = FoilAuthTypes::DEFAULT_ALGORITHM);
+ ~FoilAuthToken();
+
+ Q_REQUIRED_RESULT static FoilAuthToken fromUri(const QString);
+ Q_REQUIRED_RESULT FoilAuthToken withType(FoilAuthTypes::AuthType) const;
+ Q_REQUIRED_RESULT FoilAuthToken withAlgorithm(FoilAuthTypes::DigestAlgorithm) const;
+ Q_REQUIRED_RESULT FoilAuthToken withSecret(const QByteArray) const;
+ Q_REQUIRED_RESULT FoilAuthToken withLabel(const QString) const;
+ Q_REQUIRED_RESULT FoilAuthToken withIssuer(const QString) const;
+ Q_REQUIRED_RESULT FoilAuthToken withCounter(quint64) const;
+ Q_REQUIRED_RESULT FoilAuthToken withDigits(int) const;
+ Q_REQUIRED_RESULT FoilAuthToken withTimeshift(int) const;
FoilAuthToken& operator=(const FoilAuthToken& aToken);
bool operator==(const FoilAuthToken& aToken) const;
bool operator!=(const FoilAuthToken& aToken) const;
+ bool equals(const FoilAuthToken&) const;
bool isValid() const;
- bool setDigits(int aDigits);
- bool setType(AuthType aType);
- bool setAlgorithm(DigestAlgorithm aAlgorithm);
- bool parseUri(QString aUri);
+ FoilAuthTypes::AuthType type() const;
+ FoilAuthTypes::DigestAlgorithm algorithm() const;
+ QString label() const;
+ QString issuer() const;
+ QString secretBase32() const;
+ const QByteArray secret() const;
+ quint64 counter() const;
+ int digits() const;
+ int timeshift() const;
uint password(quint64 aTime) const;
- QString passwordString(quint64 aTime) const;
- bool equals(const FoilAuthToken& aToken) const;
- bool equals(const FoilAuthToken* aToken) const;
-
- QString toUri() const;
- QVariantMap toVariantMap() const;
- QByteArray toProtoBuf() const;
-
- static QList<FoilAuthToken> fromProtoBuf(const QByteArray& aData);
- static QByteArray toProtoBuf(const QList<FoilAuthToken>& aTokens);
- static QList<QByteArray> toProtoBufs(const QList<FoilAuthToken>& aTokens,
+ Q_REQUIRED_RESULT QString passwordString(quint64) const;
+ Q_REQUIRED_RESULT QString toUri() const;
+ Q_REQUIRED_RESULT QVariantMap toVariantMap() const;
+ Q_REQUIRED_RESULT QByteArray toProtoBuf() const;
+
+ Q_REQUIRED_RESULT static FoilAuthTypes::AuthType validType(int);
+ Q_REQUIRED_RESULT static FoilAuthTypes::DigestAlgorithm validAlgorithm(int);
+ Q_REQUIRED_RESULT static int validDigits(int);
+ Q_REQUIRED_RESULT static QList<FoilAuthToken> fromProtoBuf(const QByteArray&);
+ Q_REQUIRED_RESULT static QByteArray toProtoBuf(const QList<FoilAuthToken>&);
+ Q_REQUIRED_RESULT static QList<QByteArray> toProtoBufs(const QList<FoilAuthToken>&,
int aPrefBatchSize = 1000, int aMaxBatchSize = 2000);
public:
- AuthType iType;
- DigestAlgorithm iAlgorithm;
- QByteArray iBytes;
- QString iLabel;
- QString iIssuer;
- quint64 iCounter;
- int iDigits;
- int iTimeShift; // Seconds
+ Private* iPrivate;
};
-inline bool FoilAuthToken::isValid() const
- { return !iBytes.isEmpty(); }
inline bool FoilAuthToken::operator==(const FoilAuthToken& aToken) const
{ return equals(aToken); }
inline bool FoilAuthToken::operator!=(const FoilAuthToken& aToken) const
{ return !equals(aToken); }
-inline bool FoilAuthToken::equals(const FoilAuthToken* aToken) const
- { return (this == aToken) || (aToken && equals(*aToken)); }
+
+// Debug output
+QDebug operator<<(QDebug, const FoilAuthToken&);
+
+Q_DECLARE_METATYPE(FoilAuthToken)
#endif // FOILAUTH_TOKEN_H
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilauth-1.1.3.tar.gz/src/FoilAuthTypes.h
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2021 Jolla Ltd.
- * Copyright (C) 2021 Slava Monich <slava@monich.com>
+ * Copyright (C) 2021-2022 Jolla Ltd.
+ * Copyright (C) 2021-2022 Slava Monich <slava@monich.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -38,7 +38,6 @@
#define FOILAUTH_TYPE_HOTP "hotp"
#define FOILAUTH_TYPE_DEFAULT FOILAUTH_TYPE_TOTP
-#define FOILAUTH_ALGORITHM_MD5 "MD5"
#define FOILAUTH_ALGORITHM_SHA1 "SHA1"
#define FOILAUTH_ALGORITHM_SHA256 "SHA256"
#define FOILAUTH_ALGORITHM_SHA512 "SHA512"
@@ -52,7 +51,6 @@
};
enum DigestAlgorithm {
- DigestAlgorithmMD5,
DigestAlgorithmSHA1,
DigestAlgorithmSHA256,
DigestAlgorithmSHA512
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilauth-1.1.3.tar.gz/src/SailOTP.cpp
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2019-2021 Jolla Ltd.
- * Copyright (C) 2019-2021 Slava Monich <slava@monich.com>
+ * Copyright (C) 2019-2022 Jolla Ltd.
+ * Copyright (C) 2019-2022 Slava Monich <slava@monich.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -52,7 +52,8 @@
// SailOTP::Private
// ==========================================================================
-class SailOTP::Private {
+class SailOTP::Private :
+ public FoilAuthTypes {
public:
class Token {
public:
@@ -78,13 +79,13 @@
static const QString COL_LEN;
static const QString COL_DIFF;
- Private(QStringList aImportedTokens, FoilAuthModel* aDestModel);
+ Private(QStringList, FoilAuthModel*);
private:
static QString databaseDir();
static QString databasePath();
- void fetchTokens(FoilAuthModel* aDestModel);
+ void fetchTokens(FoilAuthModel*);
public:
QList<Token> iTokens;
@@ -109,14 +110,16 @@
const QString SailOTP::Private::COL_LEN("len"); // INTEGER
const QString SailOTP::Private::COL_DIFF("diff"); // INTEGER
-QString SailOTP::Private::databaseDir()
+QString
+SailOTP::Private::databaseDir()
{
QDir dir(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) +
"/harbour-sailotp/harbour-sailotp/QML/OfflineStorage/Databases");
return dir.path();
}
-QString SailOTP::Private::databasePath()
+QString
+SailOTP::Private::databasePath()
{
// This is how LocalStorage plugin generates database file name
return databaseDir() + QDir::separator() +
@@ -124,7 +127,9 @@
".sqlite";
}
-SailOTP::Private::Private(QStringList aImportedTokens, FoilAuthModel* aDestModel) :
+SailOTP::Private::Private(
+ QStringList aImportedTokens,
+ FoilAuthModel* aDestModel) :
iImportedTokens(aImportedTokens)
{
// SqlDatabase object needs to go out of scope before we can
@@ -133,7 +138,9 @@
QSqlDatabase::removeDatabase(DB_NAME);
}
-void SailOTP::Private::fetchTokens(FoilAuthModel* aDestModel)
+void
+SailOTP::Private::fetchTokens(
+ FoilAuthModel* aDestModel)
{
QSqlDatabase db(QSqlDatabase::database(Private::DB_NAME));
if (!db.isValid()) {
@@ -161,22 +168,20 @@
(aDestModel && aDestModel->containsSecret(secret))) {
HDEBUG("SailOTP token" << title << "is already imported");
} else {
- bool ok;
- int value;
+ bool lenOk, diffOk, counterOk;
+ const int lenVal = query.value(COL_LEN).toInt(&lenOk);
+ const int diffVal = query.value(COL_DIFF).toInt(&diffOk);
+ const int counterVal = query.value(COL_COUNTER).toInt(&counterOk);
Token token;
- token.iToken.iBytes = secret;
- token.iToken.iLabel = title;
- token.iToken.setType(isHOTP ?
- FoilAuthToken::AuthTypeHOTP :
- FoilAuthToken::AuthTypeTOTP);
- value = query.value(COL_FAV).toInt(&ok);
- if (ok) token.iFavorite = value != 0;
- value = query.value(COL_LEN).toInt(&ok);
- if (ok && value > 0) token.iToken.setDigits(value);
- value = query.value(COL_DIFF).toInt(&ok);
- if (ok) token.iToken.iTimeShift = value;
- HDEBUG(token.iToken.iLabel << type << base32 << token.iToken.iDigits);
+ token.iFavorite = (query.value(COL_FAV).toInt() != 0);
+ token.iToken = FoilAuthToken(isHOTP ? FoilAuthTypes::AuthTypeHOTP :
+ FoilAuthTypes::AuthTypeTOTP, secret, title, QString(),
+ (lenVal && lenVal > 0) ? lenVal : DEFAULT_DIGITS,
+ (counterOk && counterVal > 0) ? counterVal : DEFAULT_COUNTER,
+ diffOk ? diffVal : DEFAULT_TIMESHIFT, DEFAULT_ALGORITHM);
+
+ HDEBUG(token.iToken << token.iFavorite);
iTokens.append(token);
iImportedTokens.append(secretHash);
}
@@ -204,12 +209,15 @@
delete iPrivate;
}
-QStringList SailOTP::importedTokens() const
+QStringList
+SailOTP::importedTokens() const
{
return iImportedTokens;
}
-void SailOTP::setImportedTokens(QStringList aList)
+void
+SailOTP::setImportedTokens(
+ QStringList aList)
{
if (iImportedTokens != aList) {
iImportedTokens = aList;
@@ -218,12 +226,17 @@
}
// Callback for qmlRegisterSingletonType<SailOTP>
-QObject* SailOTP::createSingleton(QQmlEngine* aEngine, QJSEngine* aScript)
+QObject*
+SailOTP::createSingleton(
+ QQmlEngine*,
+ QJSEngine*)
{
return new SailOTP;
}
-int SailOTP::fetchNewTokens(QObject* aDestModel)
+int
+SailOTP::fetchNewTokens(
+ QObject* aDestModel)
{
delete iPrivate;
if (QFile(Private::DB_PATH).exists()) {
@@ -240,7 +253,9 @@
return 0;
}
-void SailOTP::importTokens(QObject* aDestModel)
+void
+SailOTP::importTokens(
+ QObject* aDestModel)
{
if (iPrivate) {
FoilAuthModel* model = qobject_cast<FoilAuthModel*>(aDestModel);
@@ -248,11 +263,10 @@
const int n = iPrivate->iTokens.count();
for (int i = 0; i < n; i++) {
const Private::Token& token(iPrivate->iTokens.at(i));
- const FoilAuthToken* authToken = &token.iToken;
- if (model->contains(authToken)) {
- HDEBUG(token.iToken.iLabel << "is already there");
+ if (model->contains(token.iToken)) {
+ HDEBUG(token.iToken.label() << "is already there");
} else {
- model->addToken(authToken, token.iFavorite);
+ model->addToken(token.iToken, token.iFavorite);
}
}
}
@@ -261,7 +275,8 @@
}
}
-void SailOTP::dropTokens()
+void
+SailOTP::dropTokens()
{
delete iPrivate;
iPrivate = Q_NULLPTR;
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilauth-1.1.3.tar.gz/src/main.cpp
^
|
@@ -32,8 +32,9 @@
*/
#include "FoilAuthDefs.h"
-#include "FoilAuthModel.h"
#include "FoilAuthFavoritesModel.h"
+#include "FoilAuthImportModel.h"
+#include "FoilAuthModel.h"
#include "FoilAuthSettings.h"
#include "FoilAuthToken.h"
#include "FoilAuth.h"
@@ -64,18 +65,27 @@
static void register_types(const char* uri, int v1 = 1, int v2 = 0)
{
- qmlRegisterSingletonType<HarbourProcessState>(uri, v1, v2, "HarbourProcessState", HarbourProcessState::createSingleton);
- qmlRegisterSingletonType<HarbourSystemState>(uri, v1, v2, "HarbourSystemState", HarbourSystemState::createSingleton);
- qmlRegisterSingletonType<FoilAuthSettings>(uri, v1, v2, "FoilAuthSettings", FoilAuthSettings::createSingleton);
- qmlRegisterSingletonType<FoilAuthModel>(uri, v1, v2, "FoilAuthModel", FoilAuthModel::createSingleton);
- qmlRegisterSingletonType<FoilAuth>(uri, v1, v2, "FoilAuth", FoilAuth::createSingleton);
- qmlRegisterSingletonType<SailOTP>(uri, v1, v2, "SailOTP", SailOTP::createSingleton);
- qmlRegisterType<FoilAuthFavoritesModel>(uri, v1, v2, "FoilAuthFavoritesModel");
- qmlRegisterType<HarbourOrganizeListModel>(uri, v1, v2, "HarbourOrganizeListModel");
- qmlRegisterType<HarbourQrCodeGenerator>(uri, v1, v2, "HarbourQrCodeGenerator");
- qmlRegisterType<HarbourSelectionListModel>(uri, v1, v2, "HarbourSelectionListModel");
- qmlRegisterType<HarbourSingleImageProvider>(uri, v1, v2, "HarbourSingleImageProvider");
- qmlRegisterType<QrCodeScanner>(uri, v1, v2, "QrCodeScanner");
+#define REGISTER_TYPE(uri, v1, v2, Class) \
+ qmlRegisterType<Class>(uri, v1, v2, #Class)
+#define REGISTER_SINGLETON_TYPE(uri, v1, v2, Class) \
+ qmlRegisterSingletonType<Class>(uri, v1, v2, #Class, \
+ Class::createSingleton)
+
+ REGISTER_SINGLETON_TYPE(uri, v1, v2, HarbourProcessState);
+ REGISTER_SINGLETON_TYPE(uri, v1, v2, HarbourSystemState);
+ REGISTER_SINGLETON_TYPE(uri, v1, v2, FoilAuthSettings);
+ REGISTER_SINGLETON_TYPE(uri, v1, v2, FoilAuthModel);
+ REGISTER_SINGLETON_TYPE(uri, v1, v2, FoilAuth);
+ REGISTER_SINGLETON_TYPE(uri, v1, v2, SailOTP);
+ REGISTER_TYPE(uri, v1, v2, FoilAuthFavoritesModel);
+ REGISTER_TYPE(uri, v1, v2, FoilAuthImportModel);
+ REGISTER_TYPE(uri, v1, v2, HarbourOrganizeListModel);
+ REGISTER_TYPE(uri, v1, v2, HarbourQrCodeGenerator);
+ REGISTER_TYPE(uri, v1, v2, HarbourSelectionListModel);
+ REGISTER_TYPE(uri, v1, v2, HarbourSingleImageProvider);
+ REGISTER_TYPE(uri, v1, v2, QrCodeScanner);
+ qRegisterMetaType<FoilAuthToken>();
+ qRegisterMetaType<QList<FoilAuthToken> >();
}
int main(int argc, char *argv[])
@@ -156,11 +166,11 @@
context->setContextProperty("FoilAuthAppName", QString(FOILAUTH_APP_NAME));
context->setContextProperty("TorchSupported", torchSupported);
context->setContextProperty("FoilAuthDefaultDigits",
- QVariant::fromValue((int)FoilAuthToken::DEFAULT_DIGITS));
+ QVariant::fromValue((int)FoilAuthTypes::DEFAULT_DIGITS));
context->setContextProperty("FoilAuthDefaultCounter",
- QVariant::fromValue((int)FoilAuthToken::DEFAULT_COUNTER));
+ QVariant::fromValue((int)FoilAuthTypes::DEFAULT_COUNTER));
context->setContextProperty("FoilAuthDefaultTimeShift",
- QVariant::fromValue((int)FoilAuthToken::DEFAULT_TIMESHIFT));
+ QVariant::fromValue((int)FoilAuthTypes::DEFAULT_TIMESHIFT));
if (res_4_3.isValid()) {
context->setContextProperty("ViewfinderResolution_4_3", res_4_3);
}
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilauth-1.1.3.tar.gz/test/Makefile.common
^
|
@@ -131,6 +131,9 @@
$(SRC:%.cpp=$(COVERAGE_BUILD_DIR)/%.o) \
$(HARBOUR_SRC:%.cpp=$(COVERAGE_BUILD_DIR)/harbour_%.o) \
$(QRENCODE_SRC:%.c=$(COVERAGE_BUILD_DIR)/qrencode_%.o)
+GEN_FILES = \
+ $(MOC_H:%.h=$(BUILD_DIR)/moc_%.cpp) \
+ $(MOC_CPP:%.cpp=$(BUILD_DIR)/%.moc)
#
# Dependencies
@@ -147,6 +150,7 @@
RELEASE_EXE = $(RELEASE_BUILD_DIR)/$(EXE)
COVERAGE_EXE = $(COVERAGE_BUILD_DIR)/$(EXE)
+$(GEN_FILES): | $(BUILD_DIR)
$(DEBUG_OBJS): | $(DEBUG_BUILD_DIR)
$(RELEASE_OBJS): | $(RELEASE_BUILD_DIR)
$(COVERAGE_OBJS): | $(COVERAGE_BUILD_DIR)
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilauth-1.1.3.tar.gz/test/TestFoilAuth/Makefile
^
|
@@ -6,7 +6,8 @@
MOC_H = FoilAuth.h
HARBOUR_SRC = \
- HarbourBase32.cpp
+ HarbourBase32.cpp \
+ HarbourProtoBuf.cpp
QRENCODE_SRC = \
bitstream.c \
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilauth-1.1.3.tar.gz/test/TestFoilAuth/TestFoilAuth.cpp
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2019-2021 Jolla Ltd.
- * Copyright (C) 2019-2021 Slava Monich <slava@monich.com>
+ * Copyright (C) 2019-2022 Jolla Ltd.
+ * Copyright (C) 2019-2022 Slava Monich <slava@monich.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -34,6 +34,7 @@
#include "FoilAuth.h"
#include "FoilAuthToken.h"
+#include "HarbourBase32.h"
#include "HarbourDebug.h"
#include <QCoreApplication>
@@ -108,68 +109,6 @@
}
/*==========================================================================*
- * fromBase32
- *==========================================================================*/
-
-static
-void
-test_fromBase32(
- void)
-{
- static const char out[] = {
- 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A,
- 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14,
- 0x15, 0x16, 0x17, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F
- };
- QString in1("AEBAGBAFAYDQQCIKBMGA2DQPCAIREEYUCULBOGI2DMOB2HQ7");
- QString in2("aebagbaf aydqqcik bmga2dqp caireeyu culbogi2 dmob2hq7");
- QByteArray out1(FoilAuth::fromBase32(in1));
- QByteArray out2(FoilAuth::fromBase32(in2));
- g_assert(out1 == out2);
- g_assert(out1 == QByteArray(out, sizeof(out)));
- g_assert(FoilAuth::fromBase32("ae") == QByteArray(out, 1));
- g_assert(FoilAuth::fromBase32("aeb").isEmpty());
- g_assert(FoilAuth::fromBase32("aeba") == QByteArray(out, 2));
- g_assert(FoilAuth::fromBase32("aebag") == QByteArray(out, 3));
- g_assert(FoilAuth::fromBase32("aebagb").isEmpty());
- g_assert(FoilAuth::fromBase32("aebagba") == QByteArray(out, 4));
- g_assert(FoilAuth::fromBase32("aebagbaf") == QByteArray(out, 5));
- g_assert(FoilAuth::fromBase32("aebagbafa") == QByteArray(out, 5));
- g_assert(FoilAuth::fromBase32("aebagbafay") == QByteArray(out, 6));
- g_assert(FoilAuth::fromBase32(QString()).isEmpty());
- g_assert(FoilAuth::fromBase32(" ").isEmpty());
- g_assert(FoilAuth::fromBase32("01234567").isEmpty());
- g_assert(FoilAuth::fromBase32("88888888").isEmpty());
- g_assert(FoilAuth::fromBase32("{}").isEmpty());
- g_assert(FoilAuth::fromBase32("[]").isEmpty());
-}
-
-/*==========================================================================*
- * base32pad
- *==========================================================================*/
-
-static
-void
-test_base32pad(
- void)
-{
- static const char out[] = {
- 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23
- };
- QString in1("DMOB2HQ7EA====="); // One pad character missing
- QString in2("DMOB2HQ7EAQQ====="); // One extra pagging character
- QString in3("DMOB2HQ7EAQSE== ="); // Space is ignored
- QString in4("DMOB2HQ7EAQSEIY=");
- g_assert(FoilAuth::fromBase32(in1) == QByteArray(out, sizeof(out) - 3));
- g_assert(FoilAuth::fromBase32(in2) == QByteArray(out, sizeof(out) - 2));
- g_assert(FoilAuth::fromBase32(in3) == QByteArray(out, sizeof(out) - 1));
- g_assert(FoilAuth::fromBase32(in4) == QByteArray(out, sizeof(out)));
- g_assert(FoilAuth::fromBase32(QString("=================")).isEmpty());
- g_assert(FoilAuth::fromBase32(QString("=DMOB2HQ7EAQSEIY=")).isEmpty());
- g_assert(FoilAuth::fromBase32(QString("DMOB2HQ7EB=")).isEmpty());
-}
-
-/*==========================================================================*
* toBase32
*==========================================================================*/
@@ -189,34 +128,6 @@
}
/*==========================================================================*
- * rfc4648
- *==========================================================================*/
-
-static
-void
-test_rfc4648(
- void)
-{
- // Test vectors from RFC 4648
- static const char* test[][2] = {
- { "f", "MY======" },
- { "fo", "MZXQ====" },
- { "foo", "MZXW6===" },
- { "foob", "MZXW6YQ=" },
- { "fooba", "MZXW6YTB" },
- { "foobar", "MZXW6YTBOI======" }
- };
-
- for (guint i = 0; i < G_N_ELEMENTS(test); i++) {
- QByteArray data(test[i][0]);
- QString base32(test[i][1]);
- g_assert(FoilAuth::isValidBase32(base32));
- g_assert(FoilAuth::fromBase32(base32) == data);
- g_assert(FoilAuth::toBase32(data, false) == base32);
- }
-}
-
-/*==========================================================================*
* byteArray
*==========================================================================*/
@@ -264,7 +175,7 @@
test_totp(
void)
{
- QByteArray secret = FoilAuth::fromBase32("VHIIKTVJC6MEOFTJ");
+ const QByteArray secret(HarbourBase32::fromBase32("VHIIKTVJC6MEOFTJ"));
g_assert_cmpuint(FoilAuth::TOTP(secret, 1548529350, 1000000), == ,38068);
}
@@ -277,9 +188,23 @@
test_hotp(
void)
{
- QByteArray secret = FoilAuth::fromBase32("MHGU3YYJJD6W44KUVED4FODUNN4JHJNQ");
- g_assert_cmpuint(FoilAuth::HOTP(secret, 0, 1000000), == ,207601);
- g_assert_cmpuint(FoilAuth::HOTP(secret, 1, 1000000), == ,444239);
+ const QByteArray secret(HarbourBase32::fromBase32("MHGU3YYJJD6W44KUVED4FODUNN4JHJNQ"));
+ g_assert_cmpuint(FoilAuth::HOTP(secret, 0, 1000000,
+ (FoilAuth::DigestAlgorithm)-1 /* DigestAlgorithmSHA1 */), == ,207601);
+ g_assert_cmpuint(FoilAuth::HOTP(secret, 1, 1000000,
+ (FoilAuth::DigestAlgorithm)-1 /* DigestAlgorithmSHA1 */), == ,444239);
+ g_assert_cmpuint(FoilAuth::HOTP(secret, 0, 1000000,
+ FoilAuth::DigestAlgorithmSHA1), == ,207601);
+ g_assert_cmpuint(FoilAuth::HOTP(secret, 1, 1000000,
+ FoilAuth::DigestAlgorithmSHA1), == ,444239);
+ g_assert_cmpuint(FoilAuth::HOTP(secret, 0, 1000000,
+ FoilAuth::DigestAlgorithmSHA256), == , 367047);
+ g_assert_cmpuint(FoilAuth::HOTP(secret, 1, 1000000,
+ FoilAuth::DigestAlgorithmSHA256), == , 714922);
+ g_assert_cmpuint(FoilAuth::HOTP(secret, 0, 1000000,
+ FoilAuth::DigestAlgorithmSHA512), == , 308534);
+ g_assert_cmpuint(FoilAuth::HOTP(secret, 1, 1000000,
+ FoilAuth::DigestAlgorithmSHA512), == , 899828);
}
/*==========================================================================*
@@ -360,23 +285,19 @@
void)
{
// Invalid token
- QVariantMap map = FoilAuth::parseUri(QString());
- g_assert_cmpint(map.count(), == ,1);
- g_assert(map.contains(FoilAuthToken::KEY_VALID));
- g_assert(!map.value(FoilAuthToken::KEY_VALID).toBool());
+ g_assert(!FoilAuth::parseUri(QString()).isValid());
// Valid token
- map = FoilAuth::parseUri("otpauth://totp/Test?secret=vhiiktvjc6meoftj&issuer=Issuer&digits=5");
- g_assert(map.count() == 9);
- g_assert(map.value(FoilAuthToken::KEY_VALID).toBool());
- g_assert_cmpint(map.value(FoilAuthToken::KEY_TYPE).toInt(), == ,FoilAuthToken::AuthTypeTOTP);
- g_assert(map.value(FoilAuthToken::KEY_LABEL).toString() == QString("Test"));
- g_assert(map.value(FoilAuthToken::KEY_SECRET).toString() == QString("vhiiktvjc6meoftj"));
- g_assert(map.value(FoilAuthToken::KEY_ISSUER).toString() == QString("Issuer"));
- g_assert_cmpint(map.value(FoilAuthToken::KEY_DIGITS).toInt(), == ,5);
- g_assert_cmpint(map.value(FoilAuthToken::KEY_COUNTER).toInt(), == ,FoilAuthToken::DEFAULT_COUNTER);
- g_assert_cmpint(map.value(FoilAuthToken::KEY_TIMESHIFT).toInt(), == ,FoilAuthToken::DEFAULT_TIMESHIFT);
- g_assert_cmpint(map.value(FoilAuthToken::KEY_ALGORITHM).toInt(), == ,FoilAuthToken::DEFAULT_ALGORITHM);
+ FoilAuthToken token = FoilAuth::parseUri("otpauth://totp/Test?secret=vhiiktvjc6meoftj&issuer=Issuer&digits=5");
+ g_assert(token.isValid());
+ g_assert_cmpint(token.type(), == ,FoilAuthTypes::AuthTypeTOTP);
+ g_assert(token.secretBase32() == QString("vhiiktvjc6meoftj"));
+ g_assert(token.label() == QString("Test"));
+ g_assert(token.issuer() == QString("Issuer"));
+ g_assert_cmpint(token.digits(), == ,5);
+ g_assert_cmpint(token.counter(), == ,FoilAuthTypes::DEFAULT_COUNTER);
+ g_assert_cmpint(token.timeshift(), == ,FoilAuthTypes::DEFAULT_TIMESHIFT);
+ g_assert_cmpint(token.algorithm(), == ,FoilAuthTypes::DEFAULT_ALGORITHM);
}
/*==========================================================================*
@@ -388,63 +309,60 @@
test_parseMigrationUri(
void)
{
- QVariantList list = FoilAuth::parseMigrationUri(QString());
+ QList<FoilAuthToken> list = FoilAuth::parseMigrationUri(QString());
g_assert_cmpint(list.count(), == ,0);
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilauth-1.1.3.tar.gz/test/TestFoilAuthToken/Makefile
^
|
@@ -6,7 +6,8 @@
MOC_H = FoilAuth.h
HARBOUR_SRC = \
- HarbourBase32.cpp
+ HarbourBase32.cpp \
+ HarbourProtoBuf.cpp
QRENCODE_SRC = \
bitstream.c \
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilauth-1.1.3.tar.gz/test/TestFoilAuthToken/TestFoilAuthToken.cpp
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2019-2021 Jolla Ltd.
- * Copyright (C) 2019-2021 Slava Monich <slava@monich.com>
+ * Copyright (C) 2019-2022 Jolla Ltd.
+ * Copyright (C) 2019-2022 Slava Monich <slava@monich.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -34,6 +34,7 @@
#include "FoilAuthToken.h"
#include "FoilAuth.h"
+#include "HarbourBase32.h"
#include "HarbourDebug.h"
#include <QCoreApplication>
@@ -51,37 +52,119 @@
test_basic(
void)
{
- QByteArray data("secret");
- FoilAuthToken token1(FoilAuthToken::AuthTypeTOTP, data, "Label",
- "Issuer", 1, FoilAuthToken::DEFAULT_COUNTER, 10);
+ static const uchar secret[] = {
+ 0xA9, 0xD0, 0x85, 0x4E, 0xA9, 0x17, 0x98, 0x47, 0x16, 0x69
+ };
+ const QByteArray secretData((char*)secret, sizeof(secret));
+ const QByteArray secretData2((char*)secret, sizeof(secret)/2);
+
+ FoilAuthToken token1(FoilAuthTypes::AuthTypeTOTP, secretData, "Label",
+ "Issuer", 1, FoilAuthTypes::DEFAULT_COUNTER, 10);
FoilAuthToken token2(token1);
FoilAuthToken token3;
+ g_assert(token1.isValid());
g_assert(token1 == token2);
g_assert(token1 != token3);
token3 = token2;
g_assert(token1 == token3);
+ g_assert(token1.secret() == secretData);
+ g_assert(token1.secretBase32() == QString("vhiiktvjc6meoftj"));
- g_assert(!token3.setDigits(0));
- g_assert(token1 == token3);
-
- g_assert(!token3.setDigits(FoilAuthToken::MAX_DIGITS + 1));
- g_assert(token1 == token3);
+ g_assert(token3.withType((FoilAuthTypes::AuthType)-1) == token3);
+ g_assert(token3.withDigits(0) == token3);
+ g_assert(token3.withDigits(FoilAuthToken::MAX_DIGITS + 1) == token3);
+ g_assert(token3.withAlgorithm((FoilAuthTypes::DigestAlgorithm)-1) == token3);
+ g_assert(token3.withType(token3.type()) == token3);
+ g_assert(token3.withAlgorithm(token3.algorithm()) == token3);
+ g_assert(token3.withDigits(token3.digits()) == token3);
+ g_assert(token3.withCounter(token3.counter()) == token3);
+ g_assert(token3.withSecret(token3.secret()) == token3);
+ g_assert(token3.withLabel(token3.label()) == token3);
+ g_assert(token3.withIssuer(token3.issuer()) == token3);
+ g_assert(token3.withTimeshift(token3.timeshift()) == token3);
+
+ token2 = token3.withType(FoilAuthTypes::AuthTypeHOTP);
+ g_assert(token2 != token3);
+ g_assert_cmpint(token2.type(), == ,FoilAuthTypes::AuthTypeHOTP);
+
+ token2 = token3.withAlgorithm(FoilAuthTypes::DigestAlgorithmSHA512);
+ g_assert(token2 != token3);
+ g_assert_cmpint(token2.algorithm(),==,FoilAuthTypes::DigestAlgorithmSHA512);
+
+ token2 = token3.withSecret(secretData2);
+ g_assert(token2 != token3);
+ g_assert(token2.secret() == secretData2);
+ g_assert(token2.secretBase32() == QString("vhiiktvj"));
+
+ token2 = token3.withLabel("Label2");
+ g_assert(token2 != token3);
+ g_assert(token2.label() == QString("Label2"));
+
+ token2 = token3.withIssuer("Issuer2");
+ g_assert(token2 != token3);
+ g_assert(token2.issuer() == QString("Issuer2"));
+
+ token2 = token3.withCounter(12345);
+ g_assert(token2 != token3);
+ g_assert_cmpint(token2.counter(), == ,12345);
+
+ token2 = token3.withDigits(token3.digits() + 1);
+ g_assert(token2 != token3);
+ g_assert_cmpint(token2.digits(), == ,token3.digits() + 1);
+
+ token2 = token3.withTimeshift(token3.timeshift() + 1);
+ g_assert(token2 != token3);
+ g_assert_cmpint(token2.timeshift(), == ,token3.timeshift() + 1);
+}
- g_assert(!token3.setAlgorithm((FoilAuthToken::DigestAlgorithm)-1));
- g_assert(token1 == token3);
+/*==========================================================================*
+ * validDigits
+ *==========================================================================*/
- g_assert(token3.setAlgorithm(token3.iAlgorithm));
- g_assert(token1 == token3);
+static
+void
+test_validDigits(
+ void)
+{
+ g_assert_cmpint(FoilAuthToken::validDigits(FoilAuthToken::MIN_DIGITS), == ,FoilAuthToken::MIN_DIGITS);
+ g_assert_cmpint(FoilAuthToken::validDigits(FoilAuthToken::MIN_DIGITS - 1), == ,FoilAuthTypes::DEFAULT_DIGITS);
+ g_assert_cmpint(FoilAuthToken::validDigits(FoilAuthToken::MAX_DIGITS), == ,FoilAuthToken::MAX_DIGITS);
+ g_assert_cmpint(FoilAuthToken::validDigits(FoilAuthToken::MAX_DIGITS + 1), == ,FoilAuthTypes::DEFAULT_DIGITS);
+}
- g_assert(!token3.setType((FoilAuthToken::AuthType)-1));
- g_assert(token1 == token3);
+/*==========================================================================*
+ * invalid
+ *==========================================================================*/
- g_assert(token3.setType(token3.iType));
- g_assert(token1 == token3);
+static
+void
+test_invalid(
+ void)
+{
+ FoilAuthToken invalid;
- g_assert(token3.setDigits(token3.iDigits + 1));
- g_assert(token1 != token3);
+ g_assert(!invalid.isValid());
+ g_assert_cmpint(invalid.type(), == ,FoilAuthTypes::DEFAULT_AUTH_TYPE);
+ g_assert_cmpint(invalid.algorithm(), == ,FoilAuthTypes::DEFAULT_ALGORITHM);
+ g_assert(invalid.label().isEmpty());
+ g_assert(invalid.issuer().isEmpty());
+ g_assert(invalid.secret().isEmpty());
+ g_assert(invalid.secretBase32().isEmpty());
+ g_assert_cmpint(invalid.timeshift(), == ,0);
+ g_assert_cmpint(invalid.counter(), == ,0);
+ g_assert_cmpint(invalid.digits(), == ,0);
+ g_assert_cmpint(invalid.password(123456789), == ,0);
+ g_assert(invalid.passwordString(123456789).isEmpty());
+
+ g_assert(invalid.withType(FoilAuthTypes::DEFAULT_AUTH_TYPE) == invalid);
+ g_assert(invalid.withAlgorithm(FoilAuthTypes::DEFAULT_ALGORITHM) == invalid);
+ g_assert(invalid.withLabel(QString("foo")) == invalid);
+ g_assert(invalid.withIssuer(QString("bar")) == invalid);
+ g_assert(invalid.withSecret(QByteArray()) == invalid);
+ g_assert(invalid.withTimeshift(1) == invalid);
+ g_assert(invalid.withCounter(1) == invalid);
+ g_assert(invalid.withDigits(FoilAuthTypes::DEFAULT_DIGITS) == invalid);
}
/*==========================================================================*
@@ -93,92 +176,97 @@
test_password(
void)
{
- QByteArray data = FoilAuth::fromBase32("VHIIKTVJC6MEOFTJ");
- FoilAuthToken token(FoilAuthToken::AuthTypeTOTP, data, "Label", "Issuer");
+ QByteArray data = HarbourBase32::fromBase32("VHIIKTVJC6MEOFTJ");
+ FoilAuthToken token(FoilAuthTypes::AuthTypeTOTP, data, "Label", "Issuer");
g_assert(token.passwordString(1548529350) == QString("038068"));
}
/*==========================================================================*
- * parseUri
+ * fromUri
*==========================================================================*/
static
void
-test_parseUri(
+test_fromUri(
void)
{
static const uchar bytes[] = {
0xA9, 0xD0, 0x85, 0x4E, 0xA9, 0x17, 0x98, 0x47, 0x16, 0x69
};
+ g_assert(!FoilAuthToken::fromUri("otpauth://totp/").isValid());
+ g_assert(!FoilAuthToken::fromUri("otpauth://totp/.....").isValid());
+ g_assert(!FoilAuthToken::fromUri("otpauth://totp/Test Secret?issuer=Test Issuer").isValid());
+ g_assert(!FoilAuthToken::fromUri("auth://totp/Test Secret?issuer=Test Issuer").isValid());
+
FoilAuthToken token;
- g_assert(!token.parseUri("otpauth://totp/"));
- g_assert(!token.parseUri("otpauth://totp/....."));
- g_assert(!token.parseUri("otpauth://totp/Test Secret?issuer=Test Issuer"));
- g_assert(!token.parseUri("auth://totp/Test Secret?issuer=Test Issuer"));
-
- g_assert(token.parseUri("otpauth://totp/Test Secret?secret=VHIIKTVJC6MEOFTJ&issuer=Test Issuer&foo=bar"));
- g_assert(token.iBytes == QByteArray((char*)bytes, sizeof(bytes)));
- g_assert(token.iLabel == QString("Test Secret"));
- g_assert(token.iIssuer == QString("Test Issuer"));
- g_assert_cmpint(token.iDigits, == ,FoilAuthToken::DEFAULT_DIGITS);
- g_assert_cmpint(token.iCounter, == ,FoilAuthToken::DEFAULT_COUNTER);
- g_assert_cmpint(token.iTimeShift, == ,FoilAuthToken::DEFAULT_TIMESHIFT);
- g_assert_cmpint(token.iAlgorithm, == ,FoilAuthToken::DEFAULT_ALGORITHM);
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilauth-1.1.3.tar.gz/translations/harbour-foilauth-de.ts
^
|
@@ -174,7 +174,7 @@
<message id="foilauth-scan-title">
<source>Scan QR code</source>
<extracomment>Page title (suggestion to scan QR code)</extracomment>
- <translation type="unfinished">Scannen Sie einen QR Code</translation>
+ <translation type="unfinished">Scannen einen QR Code</translation>
</message>
<message id="foilauth-scan-zoom_label">
<source>Zoom</source>
@@ -382,15 +382,10 @@
<extracomment>Dialog button</extracomment>
<translation>Speichern</translation>
</message>
- <message id="foilauth-select_token-title">
- <source>This QR code contains multiple tokens. Please select one:</source>
- <extracomment>Wrappable page title</extracomment>
- <translation type="unfinished">Dieser QR-Code enthält mehrere Token. Bitte wählen eine aus:</translation>
- </message>
<message id="foilauth-select_page-header">
<source>Select tokens</source>
<extracomment>Page title</extracomment>
- <translation type="unfinished">Wählen Sie Token</translation>
+ <translation type="unfinished">Wählen die Token</translation>
</message>
<message id="foilauth-select_page-hint_delete_selected">
<source>Delete selected tokens</source>
@@ -400,13 +395,18 @@
<message id="foilauth-select_page-hint_export_selected">
<source>Export selected tokens via QR code</source>
<extracomment>Hint text</extracomment>
- <translation type="unfinished">Ausgewählte Token per QR-Code exportieren</translation>
+ <translation type="unfinished">Ausgewählte die Token per QR-Code exportieren</translation>
</message>
<message id="foilauth-export_page-title">
<source>Code %1 of %2</source>
<extracomment>Page header</extracomment>
<translation type="unfinished">Code %1/%2</translation>
</message>
+ <message id="foilauth-select_tokens-title-add_tokens">
+ <source>Select tokens to add</source>
+ <extracomment>Dialog title</extracomment>
+ <translation type="unfinished">Wählen die hinzuzufügenden Token aus</translation>
+ </message>
<message id="foilauth-settings_page-header-version">
<source>Version %1</source>
<extracomment>Settings page header description (app version)</extracomment>
@@ -430,7 +430,7 @@
<message id="jail-terminal_hint">
<source>If you have developer mode enabled, you may also try running <b>%1</b> from the terminal. Sorry for the inconvenience!</source>
<extracomment>Hint suggesting to run the app from the terminal</extracomment>
- <translation type="unfinished">Wenn Sie den Entwicklermodus aktiviert haben, können Sie auch versuchen, <b>%1</b> vom Terminal aus auszuführen. Entschuldigen Sie die Unannehmlichkeiten!</translation>
+ <translation type="unfinished">Wenn den Entwicklermodus aktiviert haben, können auch versuchen, <b>%1</b> vom Terminal aus auszuführen. Entschuldigen die Unannehmlichkeiten!</translation>
</message>
</context>
</TS>
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilauth-1.1.3.tar.gz/translations/harbour-foilauth-fr.ts
^
|
@@ -357,11 +357,6 @@
<extracomment>Dialog button</extracomment>
<translation>Enregistrer</translation>
</message>
- <message id="foilauth-select_token-title">
- <source>This QR code contains multiple tokens. Please select one:</source>
- <extracomment>Wrappable page title</extracomment>
- <translation type="unfinished">Ce code QR contient plusieurs jetons. S'il vous plait sélectionner en un:</translation>
- </message>
<message id="foilauth-menu-select_tokens">
<source>Select</source>
<extracomment>Pulley menu item, opens selection page</extracomment>
@@ -407,6 +402,11 @@
<extracomment>Page header</extracomment>
<translation type="unfinished">Code %1/%2</translation>
</message>
+ <message id="foilauth-select_tokens-title-add_tokens">
+ <source>Select tokens to add</source>
+ <extracomment>Dialog title</extracomment>
+ <translation type="unfinished">Sélectionnez les jetons à ajouter</translation>
+ </message>
<message id="foilauth-settings_page-header-version">
<source>Version %1</source>
<extracomment>Settings page header description (app version)</extracomment>
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilauth-1.1.3.tar.gz/translations/harbour-foilauth-hu.ts
^
|
@@ -354,11 +354,6 @@
<extracomment>Dialog button</extracomment>
<translation>Mentés</translation>
</message>
- <message id="foilauth-select_token-title">
- <source>This QR code contains multiple tokens. Please select one:</source>
- <extracomment>Wrappable page title</extracomment>
- <translation type="unfinished">Ez a QR-kód több tokent tartalmaz. Kérlek válassz egyet:</translation>
- </message>
<message id="foilauth-menu-select_tokens">
<source>Select</source>
<extracomment>Pulley menu item, opens selection page</extracomment>
@@ -404,6 +399,11 @@
<extracomment>Page header</extracomment>
<translation type="unfinished">Kód %1/%2</translation>
</message>
+ <message id="foilauth-select_tokens-title-add_tokens">
+ <source>Select tokens to add</source>
+ <extracomment>Dialog title</extracomment>
+ <translation type="unfinished">Válassza ki a hozzáadni kívánt tokeneket</translation>
+ </message>
<message id="foilauth-settings_page-header-version">
<source>Version %1</source>
<extracomment>Settings page header description (app version)</extracomment>
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilauth-1.1.3.tar.gz/translations/harbour-foilauth-pl.ts
^
|
@@ -375,11 +375,6 @@
<extracomment>Dialog button</extracomment>
<translation>Zapisz</translation>
</message>
- <message id="foilauth-select_token-title">
- <source>This QR code contains multiple tokens. Please select one:</source>
- <extracomment>Wrappable page title</extracomment>
- <translation>Ten kod QR zawiera kilka tokenów. Wybierz jeden:</translation>
- </message>
<message id="foilauth-remorse-deleting_selected_tokens">
<source>Deleting selected tokens</source>
<extracomment>Remorse popup text (multiple tokens selected)</extracomment>
@@ -410,6 +405,11 @@
<extracomment>Page header</extracomment>
<translation>Kod %1 z %2</translation>
</message>
+ <message id="foilauth-select_tokens-title-add_tokens">
+ <source>Select tokens to add</source>
+ <extracomment>Dialog title</extracomment>
+ <translation type="unfinished">Wybierz żądane tokeny</translation>
+ </message>
<message id="foilauth-settings_page-header-version">
<source>Version %1</source>
<extracomment>Settings page header description (app version)</extracomment>
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilauth-1.1.3.tar.gz/translations/harbour-foilauth-ru.ts
^
|
@@ -375,11 +375,6 @@
<extracomment>Dialog button</extracomment>
<translation>Сохранить</translation>
</message>
- <message id="foilauth-select_token-title">
- <source>This QR code contains multiple tokens. Please select one:</source>
- <extracomment>Wrappable page title</extracomment>
- <translation>Этот QR-код содержит сразу несколько кодов авторизации. Выберите какой-нибудь один:</translation>
- </message>
<message id="foilauth-remorse-deleting_selected_token">
<source>Deleting selected token</source>
<extracomment>Remorse popup text (single token selected)</extracomment>
@@ -410,6 +405,11 @@
<extracomment>Page header</extracomment>
<translation>Код %1 из %2</translation>
</message>
+ <message id="foilauth-select_tokens-title-add_tokens">
+ <source>Select tokens to add</source>
+ <extracomment>Dialog title</extracomment>
+ <translation>Выберите нужные коды</translation>
+ </message>
<message id="foilauth-settings_page-header-version">
<source>Version %1</source>
<extracomment>Settings page header description (app version)</extracomment>
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilauth-1.1.3.tar.gz/translations/harbour-foilauth-sv.ts
^
|
@@ -358,11 +358,6 @@
<extracomment>Dialog button</extracomment>
<translation>Spara</translation>
</message>
- <message id="foilauth-select_token-title">
- <source>This QR code contains multiple tokens. Please select one:</source>
- <extracomment>Wrappable page title</extracomment>
- <translation type="unfinished">Denna QR-kod innehåller flera tokens. Välj en:</translation>
- </message>
<message id="foilauth-menu-select_tokens">
<source>Select</source>
<extracomment>Pulley menu item, opens selection page</extracomment>
@@ -408,6 +403,11 @@
<extracomment>Page header</extracomment>
<translation type="unfinished">Kod %1/%2</translation>
</message>
+ <message id="foilauth-select_tokens-title-add_tokens">
+ <source>Select tokens to add</source>
+ <extracomment>Dialog title</extracomment>
+ <translation type="unfinished">Välj tokens att lägga till</translation>
+ </message>
<message id="foilauth-settings_page-header-version">
<source>Version %1</source>
<extracomment>Settings page header description (app version)</extracomment>
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilauth-1.1.3.tar.gz/translations/harbour-foilauth-zh_CN.ts
^
|
@@ -355,11 +355,6 @@
<extracomment>Dialog button</extracomment>
<translation>保存</translation>
</message>
- <message id="foilauth-select_token-title">
- <source>This QR code contains multiple tokens. Please select one:</source>
- <extracomment>Wrappable page title</extracomment>
- <translation type="unfinished">此QR码包含多个令牌。 请选择一个:</translation>
- </message>
<message id="foilauth-menu-select_tokens">
<source>Select</source>
<extracomment>Pulley menu item, opens selection page</extracomment>
@@ -405,6 +400,11 @@
<extracomment>Page header</extracomment>
<translation type="unfinished">代码 %1/%2</translation>
</message>
+ <message id="foilauth-select_tokens-title-add_tokens">
+ <source>Select tokens to add</source>
+ <extracomment>Dialog title</extracomment>
+ <translation type="unfinished">选择要添加的令牌</translation>
+ </message>
<message id="foilauth-settings_page-header-version">
<source>Version %1</source>
<extracomment>Settings page header description (app version)</extracomment>
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilauth-1.1.3.tar.gz/translations/harbour-foilauth.ts
^
|
@@ -372,11 +372,6 @@
<extracomment>Dialog button</extracomment>
<translation>Save</translation>
</message>
- <message id="foilauth-select_token-title">
- <source>This QR code contains multiple tokens. Please select one:</source>
- <extracomment>Wrappable page title</extracomment>
- <translation>This QR code contains multiple tokens. Please select one:</translation>
- </message>
<message id="foilauth-remorse-deleting_selected_token">
<source>Deleting selected token</source>
<extracomment>Remorse popup text (single token selected)</extracomment>
@@ -407,6 +402,11 @@
<extracomment>Page header</extracomment>
<translation>Code %1 of %2</translation>
</message>
+ <message id="foilauth-select_tokens-title-add_tokens">
+ <source>Select tokens to add</source>
+ <extracomment>Dialog title</extracomment>
+ <translation>Select tokens to add</translation>
+ </message>
<message id="foilauth-settings_page-header-version">
<source>Version %1</source>
<extracomment>Settings page header description (app version)</extracomment>
|