[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes.changes
|
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes.spec
^
|
|
[-]
[+]
|
Changed |
_service
^
|
@@ -2,6 +2,6 @@
<service name="tar_git">
<param name="url">https://github.com/monich/harbour-foilnotes.git</param>
<param name="branch">master</param>
- <param name="revision">bc394d0</param>
+ <param name="revision">78b036e</param>
</service>
</services>
\ No newline at end of file
|
[-]
[+]
|
Deleted |
_service:tar_git:harbour-foilnotes-1.1.0.tar.gz/foil/VERSION
^
|
@@ -1 +0,0 @@
-1.0.23
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/.gitignore
^
|
@@ -1,2 +1,2 @@
build
-harbour-foilnotes.pro.user
+harbour-foilnotes.pro.user*
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/LICENSE
^
|
@@ -1,5 +1,5 @@
Copyright (C) 2018-2022 Jolla Ltd.
-Copyright (C) 2018-2022 Slava Monich <slava@monich.com>
+Copyright (C) 2018-2023 Slava Monich <slava@monich.com>
You may use this file under the terms of the BSD license as follows:
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/app.pro
^
|
@@ -1,10 +1,9 @@
+PREFIX = harbour
NAME = foilnotes
openrepos {
- PREFIX = openrepos
DEFINES += OPENREPOS
-} else {
- PREFIX = harbour
+ CONFIG += app_settings
}
TARGET = $${PREFIX}-$${NAME}
@@ -303,27 +302,29 @@
icon_dir = icons/$${s}x$${s}
$${icon_target}.files = $${icon_dir}/$${TARGET}.png
$${icon_target}.path = /usr/share/icons/hicolor/$${s}x$${s}/apps
- equals(PREFIX, "openrepos") {
- $${icon_target}.extra = cp $${icon_dir}/harbour-$${NAME}.png $$eval($${icon_target}.files)
- $${icon_target}.CONFIG += no_check_exist
- }
INSTALLS += $${icon_target}
}
-app_icon.files = icons/harbour-foilnotes.svg
-app_icon.path = /usr/share/$${TARGET}/qml/images
-INSTALLS += app_icon
-
-# Desktop file
-equals(PREFIX, "openrepos") {
- desktop.extra = sed s/harbour/openrepos/g harbour-$${NAME}.desktop > $${TARGET}.desktop
- desktop.CONFIG += no_check_exist
+# Settings
+
+app_settings {
+ settings_json.files = settings/$${TARGET}.json
+ settings_json.path = /usr/share/jolla-settings/entries/
+ settings_qml.files = settings/*.qml
+ settings_qml.path = /usr/share/$${TARGET}/qml/settings/
+ INSTALLS += settings_qml settings_json
}
+OTHER_FILES += \
+ settings/*.qml \
+ settings/*.json
+
# Translations
+
TRANSLATION_IDBASED=-idbased
TRANSLATION_SOURCES = \
- $${_PRO_FILE_PWD_}/qml
+ $${_PRO_FILE_PWD_}/qml \
+ $${_PRO_FILE_PWD_}/settings
defineTest(addTrFile) {
rel = translations/$${1}
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.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-foilnotes-1.1.1.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-foilnotes-1.1.1.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-foilnotes-1.1.1.tar.gz/foil-ui/FoilUiGenerateKeyView.qml
^
|
@@ -4,22 +4,23 @@
import "../harbour"
Item {
- id: view
+ id: thisView
property var foilUi
property var foilModel
property Page page
property alias prompt: promptLabel.text
- readonly property int minPassphraseLen: 8
- 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 _minPassphraseLen: 8
+ 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) {
+ if (_canGenerate) {
var dialog = pageStack.push(Qt.resolvedUrl("FoilUiConfirmPasswordDialog.qml"), {
- foilUi: view.foilUi,
+ foilUi: thisView.foilUi,
allowedOrientations: page.allowedOrientations,
password: inputField.text
})
@@ -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
@@ -65,16 +66,16 @@
id: keySize
label: foilUi.qsTrGenerateKeySizeLabel()
- enabled: !generating
- width: parent.width
+ enabled: !_generating
+ width: inputField.width
anchors {
top: promptLabel.bottom
topMargin: Theme.paddingLarge
}
menu: ContextMenu {
MenuItem { text: "1024" }
- MenuItem { text: "1500" }
MenuItem { text: "2048" }
+ MenuItem { text: "4096" }
}
Component.onCompleted: currentIndex = 2 // default
}
@@ -87,40 +88,30 @@
top: keySize.bottom
topMargin: Theme.paddingLarge
}
- label: text.length < minPassphraseLen ?
- foilUi.qsTrGenerateKeyPasswordDescription(minPassphraseLen) :
+ label: text.length < _minPassphraseLen ?
+ foilUi.qsTrGenerateKeyPasswordDescription(_minPassphraseLen) :
placeholderText
- enabled: !generating
- EnterKey.enabled: canGenerate
+ enabled: !_generating
+ EnterKey.enabled: _canGenerate
EnterKey.onClicked: generateKey()
}
Button {
id: button
- anchors.topMargin: Theme.paddingLarge
- text: generating ?
+ anchors.bottomMargin: Theme.paddingLarge
+ text: _generating ?
foilUi.qsTrGenerateKeyButtonGenerating() :
foilUi.qsTrGenerateKeyButtonGenerate()
- enabled: canGenerate
+ 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: [
State {
name: "portrait"
- when: !landscapeLayout
+ when: !_landscapeLayout
changes: [
AnchorChanges {
target: inputField
@@ -134,7 +125,9 @@
target: button
anchors {
top: inputField.bottom
+ right: undefined
horizontalCenter: parent.horizontalCenter
+ bottom: undefined
}
},
PropertyChanges {
@@ -145,7 +138,7 @@
},
State {
name: "landscape"
- when: landscapeLayout
+ when: _landscapeLayout
changes: [
AnchorChanges {
target: inputField
@@ -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-foilnotes-1.1.1.tar.gz/foil/LICENSE
^
|
@@ -1,4 +1,4 @@
-Copyright (C) 2016-2021 by Slava Monich
+Copyright (C) 2016-2022 by Slava Monich
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/debian/changelog
^
|
@@ -1,3 +1,43 @@
+libfoil (1.0.27) unstable; urgency=low
+
+ * Reduced log level for non-critical warnings
+ * Guard foil_log declaration with extern "C"
+ * Added foil_output_cipher variants with HMAC
+ * Added foil_output_write_byte()
+ * Added foil_hmac_reset()
+ * Added foil_digest_reset()
+ * Added foil_digest_data_buf()
+
+ -- Slava Monich <slava@monich.com> Wed, 23 Nov 2022 04:01:29 +0200
+
+libfoil (1.0.26) unstable; urgency=low
+
+ * Added foil_output_cipher_new()
+ * Added foil_key_to_binary_format()
+ * Fixed foil_output_write_bytes() error handling
+ * Fixed a few unit test dependency issues
+ * Don't update finished digest
+ * Compatibility with GNU Make 4
+ * Compatibility with OpenSSL 3
+ * Bumped debhelper compat level to 7
+ * Housekeeping
+
+ -- Slava Monich <slava@monich.com> Mon, 17 Oct 2022 21:44:29 +0300
+
+libfoil (1.0.25) unstable; urgency=low
+
+ * Added foil_kdf_pbkdf2()
+
+ -- Slava Monich <slava@monich.com> Sat, 28 May 2022 01:05:31 +0300
+
+libfoil (1.0.24) unstable; urgency=low
+
+ * Added version macros for compile-time version detection
+ * Added foil_version() for run-time version detection
+ * Made internal functions truly internal
+
+ -- Slava Monich <slava@monich.com> Fri, 27 May 2022 14:41:08 +0300
+
libfoil (1.0.23) unstable; urgency=low
* Replaced FoilParsePos with GUtilRange
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/debian/compat
^
|
@@ -1 +1 @@
-5
+7
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/debian/copyright
^
|
@@ -1,4 +1,4 @@
-Copyright (C) 2016-2021 by Slava Monich
+Copyright (C) 2016-2022 by Slava Monich
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/libfoil/Makefile
^
|
@@ -43,13 +43,30 @@
all: debug release pkgconfig
#
+# Directories
+#
+
+SRC_DIR = src
+IMPL_SRC_DIR = src/$(IMPL)
+INCLUDE_DIR = include
+BUILD_DIR = build
+DEBUG_BUILD_DIR = $(BUILD_DIR)/debug
+RELEASE_BUILD_DIR = $(BUILD_DIR)/release
+COVERAGE_BUILD_DIR = $(BUILD_DIR)/coverage
+IMPL_DEBUG_BUILD_DIR = $(DEBUG_BUILD_DIR)/$(IMPL)
+IMPL_RELEASE_BUILD_DIR = $(RELEASE_BUILD_DIR)/$(IMPL)
+IMPL_COVERAGE_BUILD_DIR = $(COVERAGE_BUILD_DIR)/$(IMPL)
+
+#
# Library version
#
-VERSION_FILE = ../VERSION
-VERSION_MAJOR = $(shell head -1 $(VERSION_FILE) | cut -f1 -d.)
-VERSION_MINOR = $(shell head -1 $(VERSION_FILE) | cut -f2 -d.)
-VERSION_RELEASE = $(shell head -1 $(VERSION_FILE) | cut -f3 -d.)
+VERSION_FILE = $(INCLUDE_DIR)/foil_version.h
+get_version = $(shell grep -E '^ *\#define +FOIL_VERSION_$1 +[0-9]+$$' $(VERSION_FILE) | sed 's/ */ /g' | cut -d ' ' -f 3)
+
+VERSION_MAJOR = $(call get_version,MAJOR)
+VERSION_MINOR = $(call get_version,MINOR)
+VERSION_RELEASE = $(call get_version,RELEASE)
# Version for pkg-config
PCVERSION = $(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_RELEASE)
@@ -90,6 +107,7 @@
foil_input_file.c \
foil_input_mem.c \
foil_input_range.c \
+ foil_kdf.c \
foil_key.c \
foil_key_aes.c \
foil_key_des.c \
@@ -97,6 +115,8 @@
foil_key_rsa_public.c \
foil_output.c \
foil_output_base64.c \
+ foil_output_cipher.c \
+ foil_output_cipher_mem.c \
foil_output_digest.c \
foil_output_file.c \
foil_output_mem.c \
@@ -104,7 +124,8 @@
foil_private_key.c \
foil_random.c \
foil_sign.c \
- foil_util.c
+ foil_util.c \
+ foil_version.c
IMPL_SRC = \
foil_openssl_cipher_des_cbc.c \
@@ -124,21 +145,6 @@
foil_openssl_rsa.c
#
-# Directories
-#
-
-SRC_DIR = src
-IMPL_SRC_DIR = src/$(IMPL)
-INCLUDE_DIR = include
-BUILD_DIR = build
-DEBUG_BUILD_DIR = $(BUILD_DIR)/debug
-RELEASE_BUILD_DIR = $(BUILD_DIR)/release
-COVERAGE_BUILD_DIR = $(BUILD_DIR)/coverage
-IMPL_DEBUG_BUILD_DIR = $(DEBUG_BUILD_DIR)/$(IMPL)
-IMPL_RELEASE_BUILD_DIR = $(RELEASE_BUILD_DIR)/$(IMPL)
-IMPL_COVERAGE_BUILD_DIR = $(COVERAGE_BUILD_DIR)/$(IMPL)
-
-#
# Tools and flags
#
@@ -337,7 +343,7 @@
INSTALL_PKGCONFIG_DIR = $(DESTDIR)$(ALIBDIR)/pkgconfig
install: $(INSTALL_LIB_DIR)
- $(INSTALL_FILES) $(RELEASE_SO) $(INSTALL_LIB_DIR)
+ $(INSTALL) -m 755 $(RELEASE_SO) $(INSTALL_LIB_DIR)
ln -sf $(LIB_SO) $(INSTALL_LIB_DIR)/$(LIB_SYMLINK2)
ln -sf $(LIB_SYMLINK2) $(INSTALL_LIB_DIR)/$(LIB_SYMLINK1)
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/libfoil/include/foil_digest.h
^
|
@@ -1,29 +1,31 @@
/*
- * Copyright (C) 2016-2021 by Slava Monich
+ * Copyright (C) 2016-2022 by Slava Monich <slava@monich.com>
*
* 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.
+ * 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 ``AS IS'' AND ANY EXPRESSED 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 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) ARISING
- * IN ANY WAY OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN
- * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 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.
*
* The views and conclusions contained in the software and documentation
* are those of the authors and should not be interpreted as representing
@@ -54,6 +56,13 @@
const void* data,
gsize size);
+gboolean
+foil_digest_data_buf(
+ GType type,
+ const void* data,
+ gsize size,
+ void* digest); /* Since 1.0.27 */
+
GBytes*
foil_digest_bytes(
GType type,
@@ -83,23 +92,27 @@
FoilDigest*
foil_digest_clone(
- FoilDigest* digest); /* Since 1.0.8 */
+ FoilDigest* digest); /* Since 1.0.8 */
gboolean
foil_digest_copy(
FoilDigest* digest,
- FoilDigest* source); /* Since 1.0.8 */
+ FoilDigest* source); /* Since 1.0.8 */
-void
+gboolean
+foil_digest_reset(
+ FoilDigest* digest); /* Since 1.0.27 */
+
+gboolean
foil_digest_update(
FoilDigest* digest,
const void* data,
- gsize size);
+ gsize size); /* Has return value since 1.0.26 */
-void
+gboolean
foil_digest_update_bytes(
FoilDigest* self,
- GBytes* bytes);
+ GBytes* bytes); /* Has return value since 1.0.26 */
GBytes*
foil_digest_finish(
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/libfoil/include/foil_hmac.h
^
|
@@ -1,26 +1,31 @@
/*
- * Copyright (C) 2018 by Slava Monich
+ * Copyright (C) 2018-2022 by Slava Monich <slava@monich.com>
*
* 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.
+ * 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 ``AS IS'' AND ANY EXPRESSED 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 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) ARISING
- * IN ANY WAY OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN
- * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 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.
*
* The views and conclusions contained in the software and documentation
* are those of the authors and should not be interpreted as representing
@@ -71,6 +76,10 @@
const void* data,
gsize size);
+void
+foil_hmac_reset(
+ FoilHmac* hmac); /* Since 1.0.27 */
+
GBytes*
foil_hmac_finish(
FoilHmac* hmac);
|
[-]
[+]
|
Added |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/libfoil/include/foil_kdf.h
^
|
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2022 by Slava Monich <slava@monich.com>
+ *
+ * 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.
+ *
+ * The views and conclusions contained in the software and documentation
+ * are those of the authors and should not be interpreted as representing
+ * any official policies, either expressed or implied.
+ */
+
+#ifndef FOIL_KDF_H
+#define FOIL_KDF_H
+
+#include "foil_types.h"
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+/*
+ * KDF: Key Derivation Functions (RFC 2898)
+ *
+ * Since 1.0.25
+ */
+
+GBytes*
+foil_kdf_pbkdf2(
+ GType digest, /* HMAC digest algorithm, e.g. FOIL_DIGEST_SHA1 */
+ const char* pw, /* UTF-8 encoded password from which to derive the key */
+ gssize pwlen, /* Negative to strlen() the password */
+ const FoilBytes* salt,
+ guint iter, /* Number of iterations */
+ guint dklen); /* Derived key length, zero for auto (digest length) */
+
+G_END_DECLS
+
+#endif /* FOIL_KDF_H */
+
+/*
+ * Local Variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/libfoil/include/foil_key.h
^
|
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016-2019 by Slava Monich
+ * Copyright (C) 2016-2022 by Slava Monich <slava@monich.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -64,6 +64,13 @@
FOIL_KEY_EXPORT_FORMAT_PKCS8 /* Since 1.0.7 */
} FoilKeyExportFormat;
+/* Format of binary key data */
+typedef enum foil_key_binary_format { /* Since 1.0.26 */
+ FOIL_KEY_BINARY_FORMAT_DEFAULT, /* Valid for all key formats */
+ FOIL_KEY_EXPORT_FORMAT_RSA_PKCS1, /* RFC 3447 (Appendix A) */
+ FOIL_KEY_BINARY_FORMAT_RSA_SSH /* RFC 4253 (ssh-rsa format) */
+} FoilKeyBinaryFormat;
+
FoilKey*
foil_key_new_from_data(
GType type,
@@ -171,6 +178,11 @@
foil_key_to_bytes(
FoilKey* key);
+GBytes*
+foil_key_to_binary_format(
+ FoilKey* key,
+ FoilKeyBinaryFormat format); /* Since 1.0.26 */
+
gboolean
foil_key_export(
FoilKey* key,
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/libfoil/include/foil_log.h
^
|
@@ -1,16 +1,19 @@
/*
- * Copyright (C) 2016-2019 by Slava Monich
+ * Copyright (C) 2016-2022 by Slava Monich <slava@monich.com>
*
* 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
+ * 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
+ * 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 ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
@@ -44,8 +47,12 @@
log(foil_log_output) \
log(foil_log_random)
+G_BEGIN_DECLS
+
FOIL_LOG_MODULES(GLOG_MODULE_DECL)
+G_END_DECLS
+
#endif /* FOIL_LOG_H */
/*
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/libfoil/include/foil_output.h
^
|
@@ -1,26 +1,31 @@
/*
- * Copyright (C) 2016-2018 by Slava Monich
+ * Copyright (C) 2016-2022 by Slava Monich <slava@monich.com>
*
* 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.
+ * 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 ``AS IS'' AND ANY EXPRESSED 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 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) ARISING
- * IN ANY WAY OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN
- * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 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.
*
* The views and conclusions contained in the software and documentation
* are those of the authors and should not be interpreted as representing
@@ -62,10 +67,14 @@
FoilOutput* out,
GBytes* bytes);
-/* Since 1.0.9 */
guint
foil_output_write_eol(
- FoilOutput* out);
+ FoilOutput* out); /* Since 1.0.9 */
+
+gboolean
+foil_output_write_byte(
+ FoilOutput* out,
+ guint8 byte); /* Since 1.0.27 */
#define foil_output_write_all(out,buf,size) \
(foil_output_write(out,buf,size) == (gssize)(size))
@@ -93,6 +102,30 @@
GByteArray* buf);
FoilOutput*
+foil_output_cipher_new(
+ FoilOutput* out,
+ FoilCipher* cipher,
+ FoilDigest* digest); /* Since 1.0.26 */
+
+FoilOutput*
+foil_output_cipher_new2(
+ FoilOutput* out,
+ FoilCipher* cipher,
+ FoilHmac* hmac); /* Since 1.0.27 */
+
+FoilOutput*
+foil_output_cipher_mem_new(
+ GByteArray* buf,
+ FoilCipher* cipher,
+ FoilDigest* digest); /* Since 1.0.26 */
+
+FoilOutput*
+foil_output_cipher_mem_new2(
+ GByteArray* buf,
+ FoilCipher* cipher,
+ FoilHmac* hmac); /* Since 1.0.27 */
+
+FoilOutput*
foil_output_digest_new(
FoilOutput* out,
FoilDigest* digest);
@@ -110,11 +143,10 @@
#define FOIL_OUTPUT_BASE64_CLOSE (0x01) /* Close the target stream */
#define FOIL_OUTPUT_BASE64_FILESAFE (0x02) /* Use filename safe enciding */
-/* Since 1.0.1 */
FoilOutput*
foil_output_file_new(
FILE* file,
- guint flags);
+ guint flags); /* Since 1.0.1 */
#define FOIL_OUTPUT_FILE_CLOSE (0x01) /* Close the file when done */
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/libfoil/include/foil_types.h
^
|
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016-2021 by Slava Monich <slava@monich.com>
+ * Copyright (C) 2016-2022 by Slava Monich <slava@monich.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -37,6 +37,8 @@
#include <gutil_types.h>
+#include <foil_version.h>
+
G_BEGIN_DECLS
typedef struct foil_digest FoilDigest;
@@ -44,6 +46,7 @@
typedef struct foil_cmac FoilCmac;
typedef struct foil_hmac FoilHmac;
typedef struct foil_input FoilInput;
+typedef struct foil_kdf FoilKdf; /* Since 1.0.25 */
typedef struct foil_key FoilKey;
typedef struct foil_output FoilOutput;
typedef struct foil_private_key FoilPrivateKey;
|
[-]
[+]
|
Added |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/libfoil/include/foil_version.h
^
|
@@ -0,0 +1,100 @@
+/*
+ * Copyright (C) 2022 by Slava Monich <slava@monich.com>
+ *
+ * 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.
+ *
+ * The views and conclusions contained in the software and documentation
+ * are those of the authors and should not be interpreted as representing
+ * any official policies, either expressed or implied.
+ */
+
+#ifndef FOIL_VERSION_H
+#define FOIL_VERSION_H
+
+/*
+ * This header first appeared in version 1.0.24 therefore version checks
+ * in the code which is supposed to be compilable against earlier versions
+ * of libfoil should look like this:
+ *
+ * #if defined(FOIL_CORE_VERSION) && \
+ * FOIL_CORE_VERSION > FOIL_VERSION_WORD(1,0,24)
+ * ...
+ * #endif
+ *
+ * of better like this:
+ *
+ * #ifdef FOIL_VERSION_1_0_24
+ * ...
+ * #endif
+ *
+ * FOIL_VERSION_X_Y_Z macros will be added with each release. The fact that
+ * such macro is defined means that you're compiling against libfoil version
+ * X.Y.Z or greater.
+ */
+
+#define FOIL_VERSION_MAJOR 1
+#define FOIL_VERSION_MINOR 0
+#define FOIL_VERSION_RELEASE 27
+#define FOIL_VERSION_STRING "1.0.27"
+
+/* Version as a single word */
+#define FOIL_VERSION_WORD(v1,v2,v3) \
+ ((((v1) & 0x7f) << 24) | \
+ (((v2) & 0xfff) << 12) | \
+ ((v3) & 0xfff))
+
+#define FOIL_VERSION_GET_MAJOR(v) (((v) >> 24) & 0x7f)
+#define FOIL_VERSION_GET_MINOR(v) (((v) >> 12) & 0xfff)
+#define FOIL_VERSION_GET_RELEASE(v) ((v) & 0xfff)
+
+/*
+ * Function for run-time version detection in case if you're linking
+ * against a dynamic library.
+ */
+unsigned int
+foil_version(
+ void); /* Since 1.0.24 */
+
+/* Current version as a single word */
+#define FOIL_VERSION FOIL_VERSION_WORD \
+ (FOIL_VERSION_MAJOR, FOIL_VERSION_MINOR, FOIL_VERSION_RELEASE)
+
+/* Specific versions */
+#define FOIL_VERSION_1_0_24 FOIL_VERSION_WORD(1,0,24)
+#define FOIL_VERSION_1_0_25 FOIL_VERSION_WORD(1,0,25)
+#define FOIL_VERSION_1_0_26 FOIL_VERSION_WORD(1,0,26)
+#define FOIL_VERSION_1_0_27 FOIL_VERSION_WORD(1,0,27)
+
+#endif /* FOIL_VERSION_H */
+
+/*
+ * Local Variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/libfoil/src/foil_cipher_aes.h
^
|
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016-2019 by Slava Monich
+ * Copyright (C) 2016-2022 by Slava Monich
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -42,7 +42,7 @@
guint8 block[FOIL_AES_BLOCK_SIZE];
} FoilCipherAes;
-GType foil_cipher_aes_get_type(void);
+GType foil_cipher_aes_get_type(void) FOIL_INTERNAL;
#define FOIL_TYPE_CIPHER_AES (foil_cipher_aes_get_type())
#define FOIL_CIPHER_AES(obj) (G_TYPE_CHECK_INSTANCE_CAST(obj, \
FOIL_TYPE_CIPHER_AES, FoilCipherAes))
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/libfoil/src/foil_cipher_p.h
^
|
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016-2019 by Slava Monich
+ * Copyright (C) 2016-2022 by Slava Monich
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -85,14 +85,16 @@
foil_cipher_default_padding_func(
guint8* block,
gsize data_size,
- gsize block_size);
+ gsize block_size)
+ FOIL_INTERNAL;
int
foil_cipher_symmetric_finish(
FoilCipher* cipher,
const void* from,
int flen,
- void* to);
+ void* to)
+ FOIL_INTERNAL;
#endif /* FOIL_CIPHER_P_H */
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/libfoil/src/foil_cipher_sync.h
^
|
@@ -1,26 +1,31 @@
/*
- * Copyright (C) 2016-2017 by Slava Monich
+ * Copyright (C) 2016-2022 by Slava Monich
*
* 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.
+ * 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 ``AS IS'' AND ANY EXPRESSED 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 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) ARISING
- * IN ANY WAY OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN
- * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 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.
*
* The views and conclusions contained in the software and documentation
* are those of the authors and should not be interpreted as representing
@@ -46,7 +51,7 @@
gint priority;
} FoilCipherSync;
-GType foil_cipher_sync_get_type(void);
+GType foil_cipher_sync_get_type(void) FOIL_INTERNAL;
#define FOIL_TYPE_CIPHER_SYNC (foil_cipher_sync_get_type())
#define FOIL_CIPHER_SYNC(obj) (G_TYPE_CHECK_INSTANCE_CAST(obj, \
FOIL_TYPE_CIPHER_SYNC, FoilCipherSync))
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/libfoil/src/foil_digest.c
^
|
@@ -1,26 +1,31 @@
/*
- * Copyright (C) 2016-2018 by Slava Monich
+ * Copyright (C) 2016-2022 by Slava Monich <slava@monich.com>
*
* 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.
+ * 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 ``AS IS'' AND ANY EXPRESSED 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 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) ARISING
- * IN ANY WAY OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN
- * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 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.
*
* The views and conclusions contained in the software and documentation
* are those of the authors and should not be interpreted as representing
@@ -51,6 +56,7 @@
{
gsize size = 0;
FoilDigestClass* klass = foil_digest_class_ref(type);
+
if (G_LIKELY(klass)) {
size = klass->size;
g_type_class_unref(klass);
@@ -64,6 +70,7 @@
{
gsize size = 0;
FoilDigestClass* klass = foil_digest_class_ref(type);
+
if (G_LIKELY(klass)) {
size = klass->block_size;
g_type_class_unref(klass);
@@ -77,6 +84,7 @@
{
const char* name = NULL;
FoilDigestClass* klass = foil_digest_class_ref(type);
+
if (G_LIKELY(klass)) {
name = klass->name;
g_type_class_unref(klass);
@@ -91,10 +99,13 @@
gsize size)
{
GBytes* result = NULL;
+
if (G_LIKELY(data || !size)) {
FoilDigestClass* klass = foil_digest_class_ref(type);
+
if (G_LIKELY(klass)) {
void* digest = klass->fn_digest_alloc();
+
klass->fn_digest(data, size, digest);
result = g_bytes_new_with_free_func(digest, klass->size,
klass->fn_digest_free, digest);
@@ -104,18 +115,39 @@
return result;
}
+gboolean
+foil_digest_data_buf(
+ GType type,
+ const void* data,
+ gsize size,
+ void* digest) /* Since 1.0.27 */
+{
+ /* The output buffer is supposed to be large enough */
+ if (G_LIKELY(data || !size) && G_LIKELY(digest)) {
+ FoilDigestClass* klass = foil_digest_class_ref(type);
+
+ if (G_LIKELY(klass)) {
+ klass->fn_digest(data, size, digest);
+ g_type_class_unref(klass);
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
GBytes*
foil_digest_bytes(
GType type,
GBytes* bytes)
{
- GBytes* result = NULL;
if (G_LIKELY(bytes)) {
gsize size = 0;
const void* data = g_bytes_get_data(bytes, &size);
- result = foil_digest_data(type, data, size);
+
+ return foil_digest_data(type, data, size);
+ } else {
+ return NULL;
}
- return result;
}
gsize
@@ -145,6 +177,7 @@
{
FoilDigest* digest = NULL;
FoilDigestClass* klass = foil_digest_class_ref(type);
+
if (G_LIKELY(klass)) {
digest = g_object_new(type, NULL);
g_type_class_unref(klass);
@@ -175,11 +208,12 @@
FoilDigest*
foil_digest_clone(
- FoilDigest* self)
+ FoilDigest* self) /* Since 1.0.8 */
{
if (G_LIKELY(self)) {
GType type = G_TYPE_FROM_INSTANCE(self);
FoilDigest* clone = foil_digest_new(type);
+
if (foil_digest_copy(clone, self)) {
return clone;
}
@@ -191,7 +225,7 @@
gboolean
foil_digest_copy(
FoilDigest* self,
- FoilDigest* source)
+ FoilDigest* source) /* Since 1.0.8 */
{
if (G_LIKELY(self) && G_LIKELY(source)) {
if (self == source) {
@@ -200,6 +234,7 @@
} else {
/* Both must be of the same class */
FoilDigestClass* klass = FOIL_DIGEST_GET_CLASS(self);
+
if (klass == FOIL_DIGEST_GET_CLASS(source) && klass->fn_copy) {
klass->fn_copy(self, source);
if (self->result) {
@@ -216,27 +251,52 @@
return FALSE;
}
-void
+gboolean
+foil_digest_reset(
+ FoilDigest* self) /* Since 1.0.27 */
+{
+ if (G_LIKELY(self)) {
+ FoilDigestClass* klass = FOIL_DIGEST_GET_CLASS(self);
+
+ if (klass->fn_reset) {
+ klass->fn_reset(self);
+ if (self->result) {
+ g_bytes_unref(self->result);
+ self->result = NULL;
+ }
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+gboolean
foil_digest_update(
FoilDigest* self,
const void* data,
- gsize size)
+ gsize size) /* Has return value since 1.0.26 */
{
- if (G_LIKELY(self)) {
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/libfoil/src/foil_digest_p.h
^
|
@@ -1,29 +1,31 @@
/*
- * Copyright (C) 2016-2021 by Slava Monich
+ * Copyright (C) 2016-2022 by Slava Monich <slava@monich.com>
*
* 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.
+ * 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 ``AS IS'' AND ANY EXPRESSED 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 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) ARISING
- * IN ANY WAY OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN
- * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 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.
*
* The views and conclusions contained in the software and documentation
* are those of the authors and should not be interpreted as representing
@@ -50,6 +52,7 @@
void* (*fn_digest_alloc)(void);
void (*fn_digest_free)(void* md);
void (*fn_digest)(const void* in, gsize n, void* md);
+ void (*fn_reset)(FoilDigest* digest);
void (*fn_copy)(FoilDigest* digest, FoilDigest* source);
void (*fn_update)(FoilDigest* digest, const void* data, gsize size);
void (*fn_finish)(FoilDigest* digest, void* md);
@@ -66,11 +69,11 @@
typedef FoilDigestClass FoilDigestSHA512Class;
/* Abstract types */
-GType foil_digest_get_type(void);
-GType foil_digest_md5_get_type(void);
-GType foil_digest_sha1_get_type(void);
-GType foil_digest_sha256_get_type(void);
-GType foil_digest_sha512_get_type(void);
+GType foil_digest_get_type(void) FOIL_INTERNAL;
+GType foil_digest_md5_get_type(void) FOIL_INTERNAL;
+GType foil_digest_sha1_get_type(void) FOIL_INTERNAL;
+GType foil_digest_sha256_get_type(void) FOIL_INTERNAL;
+GType foil_digest_sha512_get_type(void) FOIL_INTERNAL;
#define FOIL_TYPE_DIGEST (foil_digest_get_type())
#define FOIL_TYPE_DIGEST_MD5 (foil_digest_md5_get_type())
#define FOIL_TYPE_DIGEST_SHA1 (foil_digest_sha1_get_type())
@@ -84,11 +87,51 @@
gsize
foil_digest_type_block_size(
- GType type);
+ GType type)
+ FOIL_INTERNAL;
gsize
foil_digest_block_size(
- FoilDigest* digest);
+ FoilDigest* digest)
+ FOIL_INTERNAL;
+
+/* Callbacks for generic FoilDigest/FoilHmac actions (all ignore NULL) */
+
+typedef
+void
+(*FoilDigestGenericUpdateFunc)(
+ void* digest,
+ const void* data,
+ gsize size);
+
+void
+foil_digest_update_digest(
+ void* digest, /* FoilDigest */
+ const void* data,
+ gsize size)
+ FOIL_INTERNAL;
+
+void
+foil_digest_update_hmac(
+ void* digest, /* FoilHmac */
+ const void* data,
+ gsize size)
+ FOIL_INTERNAL;
+
+typedef
+void
+(*FoilDigestGenericUnrefFunc)(
+ void* digest);
+
+void
+foil_digest_unref_digest(
+ void* digest) /* FoilDigest */
+ FOIL_INTERNAL;
+
+void
+foil_digest_unref_hmac(
+ void* digest) /* FoilHmac */
+ FOIL_INTERNAL;
#endif /* FOIL_DIGEST_P_H */
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/libfoil/src/foil_hmac.c
^
|
@@ -1,26 +1,31 @@
/*
- * Copyright (C) 2018 by Slava Monich
+ * Copyright (C) 2018-2022 by Slava Monich <slava@monich.com>
*
* 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.
- *
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 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) ARISING
- * IN ANY WAY OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN
- * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 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.
*
* The views and conclusions contained in the software and documentation
* are those of the authors and should not be interpreted as representing
@@ -42,30 +47,64 @@
* ipad is the byte 0x36 repeated 64 times
* opad is the byte 0x5c repeated 64 times
* and text is the data being protected
+ *
+ * Since 1.0.8
*/
struct foil_hmac {
gint ref_count;
FoilDigest* digest;
+ void* key;
+ gsize keylen;
guint8* k_opad;
GBytes* result;
};
static
void
+foil_hmac_init(
+ FoilHmac* self)
+{
+ const gsize keylen = self->keylen;
+ const gsize blocksize = foil_digest_block_size(self->digest);
+ guint8* k_ipad = g_slice_alloc(blocksize);
+ gsize i;
+
+ /* XOR key with ipad and opad values */
+ if (keylen) {
+ memcpy(k_ipad, self->key, keylen);
+ memcpy(self->k_opad, self->key, keylen);
+ }
+ if (blocksize > keylen) {
+ memset(k_ipad + keylen, 0, blocksize - keylen);
+ memset(self->k_opad + keylen, 0, blocksize - keylen);
+ }
+ for (i = 0; i < blocksize; i++) {
+ k_ipad[i] ^= 0x36;
+ self->k_opad[i] ^= 0x5c;
+ }
+
+ /* Perform inner digest */
+ foil_digest_update(self->digest, k_ipad, blocksize);
+ memset(k_ipad, 0, blocksize);
+ g_slice_free1(blocksize, k_ipad);
+}
+
+static
+void
foil_hmac_finalize(
FoilHmac* self)
{
+ const gsize blocksize = foil_digest_block_size(self->digest);
+
if (self->result) {
g_bytes_unref(self->result);
- GASSERT(!self->digest);
- GASSERT(!self->k_opad);
- } else {
- const gsize blocksize = foil_digest_block_size(self->digest);
- memset(self->k_opad, 0, blocksize);
- g_slice_free1(blocksize, self->k_opad);
- foil_digest_unref(self->digest);
}
+ memset(self->key, 0, self->keylen);
+ memset(self->k_opad, 0, blocksize);
+ g_slice_free1(self->keylen, self->key);
+ g_slice_free1(blocksize, self->k_opad);
+ foil_digest_unref(self->digest);
}
FoilHmac*
@@ -99,12 +138,10 @@
gsize keylen)
{
FoilDigest* digest = foil_digest_new(digest_type);
- if (digest) {
+
+ if (G_LIKELY(digest)) {
FoilHmac* hmac = g_slice_new0(FoilHmac);
const gsize blocksize = foil_digest_block_size(digest);
- guint8* k_ipad = g_slice_alloc0(blocksize);
- GBytes* tmp_key = NULL;
- gsize i;
g_atomic_int_set(&hmac->ref_count, 1);
hmac->digest = digest;
@@ -112,25 +149,16 @@
/* If key is longer than digest block size, reset it to H(key) */
if (keylen > blocksize) {
- tmp_key = foil_digest_data(digest_type, key, keylen);
- key = g_bytes_get_data(tmp_key, &keylen);
+ hmac->keylen = blocksize;
+ hmac->key = g_slice_alloc0(blocksize);
+ foil_digest_data_buf(digest_type, key, keylen, hmac->key);
+ } else if (keylen > 0) {
+ hmac->keylen = keylen;
+ hmac->key = g_slice_alloc(keylen);
+ memcpy(hmac->key, key, keylen);
}
- /* XOR key with ipad and opad values */
- memcpy(k_ipad, key, keylen);
- memcpy(hmac->k_opad, key, keylen);
- for (i = 0; i < blocksize; i++) {
- k_ipad[i] ^= 0x36;
- hmac->k_opad[i] ^= 0x5c;
- }
-
- /* Perform inner digest */
- foil_digest_update(digest, k_ipad, blocksize);
- memset(k_ipad, 0, blocksize);
- g_slice_free1(blocksize, k_ipad);
- if (tmp_key) {
- g_bytes_unref(tmp_key);
- }
+ foil_hmac_init(hmac);
return hmac;
}
return NULL;
@@ -142,16 +170,17 @@
{
if (G_LIKELY(self)) {
FoilHmac* hmac = g_slice_new0(FoilHmac);
+ const gsize blocksize = foil_digest_block_size(self->digest);
+
g_atomic_int_set(&hmac->ref_count, 1);
+ hmac->digest = foil_digest_clone(self->digest);
+ hmac->keylen = self->keylen;
+ hmac->key = g_slice_alloc(self->keylen);
+ hmac->k_opad = g_slice_alloc(blocksize);
+ memcpy(hmac->key, self->key, self->keylen);
+ memcpy(hmac->k_opad, self->k_opad, blocksize);
if (self->result) {
hmac->result = g_bytes_ref(self->result);
- GASSERT(!self->digest);
- GASSERT(!self->k_opad);
- } else {
- const gsize blocksize = foil_digest_block_size(self->digest);
- hmac->digest = foil_digest_clone(self->digest);
- hmac->k_opad = g_slice_alloc0(blocksize);
- memcpy(hmac->k_opad, self->k_opad, blocksize);
}
return hmac;
}
@@ -167,6 +196,7 @@
/* Clean up the old state but don't deallocate k_opad just yet */
FoilDigest* prev_digest = self->digest;
guint8* prev_k_opad = self->k_opad;
+
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/libfoil/src/foil_input_p.h
^
|
@@ -1,26 +1,31 @@
/*
- * Copyright (C) 2016-2017 by Slava Monich
+ * Copyright (C) 2016-2022 by Slava Monich
*
* 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.
+ * 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 ``AS IS'' AND ANY EXPRESSED 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 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) ARISING
- * IN ANY WAY OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN
- * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 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.
*
* The views and conclusions contained in the software and documentation
* are those of the authors and should not be interpreted as representing
@@ -30,6 +35,7 @@
#ifndef FOIL_INPUT_P_H
#define FOIL_INPUT_P_H
+#include "foil_types_p.h"
#include "foil_input.h"
typedef struct foil_input_func {
@@ -51,17 +57,20 @@
FoilInput*
foil_input_init(
FoilInput* in,
- const FoilInputFunc* fn);
+ const FoilInputFunc* fn)
+ FOIL_INTERNAL;
void
foil_input_finalize(
- FoilInput* in);
+ FoilInput* in)
+ FOIL_INTERNAL;
void
foil_input_push_back(
FoilInput* in,
const void* buf,
- gsize size);
+ gsize size)
+ FOIL_INTERNAL;
#endif /* FOIL_INPUT_P_H */
|
[-]
[+]
|
Added |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/libfoil/src/foil_kdf.c
^
|
@@ -0,0 +1,187 @@
+/*
+ * Copyright (C) 2022 by Slava Monich <slava@monich.com>
+ *
+ * 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.
+ *
+ * The views and conclusions contained in the software and documentation
+ * are those of the authors and should not be interpreted as representing
+ * any official policies, either expressed or implied.
+ */
+
+#include "foil_kdf.h"
+#include "foil_hmac.h"
+#include "foil_digest.h"
+
+/*
+ * KDF: Key Derivation Functions (RFC 2898)
+ *
+ * Since 1.0.25
+ */
+
+/*
+ * RFC 2898
+ *
+ * 5.2 PBKDF2
+ *
+ * ...
+ *
+ * PBKDF2 (P, S, c, dkLen)
+ *
+ * Options: PRF underlying pseudorandom function (hLen
+ * denotes the length in octets of the
+ * pseudorandom function output)
+ *
+ * Input: P password, an octet string
+ * S salt, an octet string
+ * c iteration count, a positive integer
+ * dkLen intended length in octets of the derived
+ * key, a positive integer, at most
+ * (2^32 - 1) * hLen
+ *
+ * Output: DK derived key, a dkLen-octet string
+ */
+GBytes*
+foil_kdf_pbkdf2(
+ GType digest, /* HMAC digest algorithm, e.g. FOIL_DIGEST_SHA1 */
+ const char* pw, /* UTF-8 encoded password from which to derive the key */
+ gssize pwlen, /* Negative to strlen() the password */
+ const FoilBytes* salt,
+ guint iter, /* Number of iterations */
+ guint dlen) /* Derived key length, zero for auto (digest length) */
+{
+ const gsize hlen = foil_digest_type_size(digest);
+ const gsize dklen = dlen ? dlen : hlen;
+
+ /*
+ * 1. If dkLen > (2^32 - 1) * hLen, output "derived key too long" and
+ * stop. (we skip that because our dlen won't exceed 0xffffffff)
+ */
+ if ((pw || !pwlen) && salt && iter && hlen) {
+ /*
+ * This one must succeed because non-zero hlen guarantees that
+ * the digest type is valid.
+ */
+ FoilHmac* pmac = foil_hmac_new(digest, pw, (pwlen >= 0) ?
+ (gsize) pwlen : strlen(pw));
+
+ /*
+ * 2. Let l be the number of hLen-octet blocks in the derived key,
+ * rounding up, and let r be the number of octets in the last
+ * block:
+ *
+ * l = CEIL (dkLen / hLen) ,
+ * r = dkLen - (l - 1) * hLen .
+ *
+ * Here, CEIL (x) is the "ceiling" function, i.e. the smallest
+ * integer greater than, or equal to, x.
+ *
+ * 3. For each block of the derived key apply the function F defined
+ * below to the password P, the salt S, the iteration count c, and
+ * the block index to compute the block:
+ *
+ * T_1 = F (P, S, c, 1) ,
+ * T_2 = F (P, S, c, 2) ,
+ * ...
+ * T_l = F (P, S, c, l) ,
+ *
+ * where the function F is defined as the exclusive-or sum of the
+ * first c iterates of the underlying pseudorandom function PRF
+ * applied to the password P and the concatenation of the salt S
+ * and the block index i:
+ *
+ * F (P, S, c, i) = U_1 \xor U_2 \xor ... \xor U_c
+ *
+ * where
+ *
+ * U_1 = PRF (P, S || INT (i)) ,
+ * U_2 = PRF (P, U_1) ,
+ * ...
+ * U_c = PRF (P, U_{c-1}) .
+ *
+ * Here, INT (i) is a four-octet encoding of the integer i, most
+ * significant octet first.
+ */
+ guint8* key = g_malloc(dklen);
+ gsize offset = 0;
+ guint i = 1;
+
+ while (offset < dklen) {
+ const gsize remaining = dklen - offset;
+ const gsize blocklen = MIN(remaining, hlen);
+ const guint32 ibuf = htobe32(i);
+ guint8* block = key + offset;
+ FoilHmac* prf;
+ const guint8* prev;
+ GBytes* prev_bytes;
+ guint m;
+
+ /* U_1 = PRF (P, S || INT (i)) */
+ prf = foil_hmac_clone(pmac);
+ foil_hmac_update(prf, salt->val, salt->len);
+ foil_hmac_update(prf, &ibuf, sizeof(ibuf));
+ prev_bytes = foil_hmac_free_to_bytes(prf);
+ prev = g_bytes_get_data(prev_bytes, NULL);
+ memcpy(block, prev, blocklen);
+
+ for (m = 1; m < iter; m++) {
+ GBytes* next_bytes;
+ const guint8* next;
+ guint k;
+
+ /* U_m = PRF (P, U_{m-1}) */
+ prf = foil_hmac_clone(pmac);
+ foil_hmac_update(prf, prev, hlen);
+ next_bytes = foil_hmac_free_to_bytes(prf);
+ next = g_bytes_get_data(next_bytes, NULL);
+ for (k = 0; k < blocklen; k++) {
+ block[k] ^= next[k];
+ }
+
+ g_bytes_unref(prev_bytes);
+ prev_bytes = next_bytes;
+ prev = next;
+ }
+
+ g_bytes_unref(prev_bytes);
+ offset += blocklen;
+ i++;
+ }
+
+ foil_hmac_unref(pmac);
+ return g_bytes_new_take(key, dklen);
+ } else {
+ return NULL;
+ }
+}
+
+/*
+ * Local Variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/libfoil/src/foil_key.c
^
|
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016-2021 by Slava Monich <slava@monich.com>
+ * Copyright (C) 2016-2022 by Slava Monich <slava@monich.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -121,10 +121,18 @@
foil_key_to_bytes(
FoilKey* self)
{
+ return foil_key_to_binary_format(self, FOIL_KEY_BINARY_FORMAT_DEFAULT);
+}
+
+GBytes*
+foil_key_to_binary_format(
+ FoilKey* self,
+ FoilKeyBinaryFormat format) /* Since 1.0.26 */
+{
GBytes* bytes = NULL;
if (G_LIKELY(self)) {
FoilKeyClass* klass = FOIL_KEY_GET_CLASS(self);
- bytes = klass->fn_to_bytes(self);
+ bytes = klass->fn_to_bytes(self, format);
}
return bytes;
}
@@ -496,7 +504,7 @@
FoilKey* self)
{
FoilKeyClass* klass = FOIL_KEY_GET_CLASS(self);
- GBytes* bytes = klass->fn_to_bytes(self);
+ GBytes* bytes = klass->fn_to_bytes(self, FOIL_KEY_BINARY_FORMAT_DEFAULT);
GBytes* fingerprint = foil_digest_bytes(FOIL_DIGEST_MD5, bytes);
GASSERT(!self->priv->fingerprint);
g_bytes_unref(bytes);
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/libfoil/src/foil_key_aes.c
^
|
@@ -1,29 +1,31 @@
/*
- * Copyright (C) 2016-2020 by Slava Monich
+ * Copyright (C) 2016-2022 by Slava Monich <slava@monich.com>
*
* 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.
+ * 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 ``AS IS'' AND ANY EXPRESSED 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 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) ARISING
- * IN ANY WAY OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN
- * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 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.
*
* The views and conclusions contained in the software and documentation
* are those of the authors and should not be interpreted as representing
@@ -183,7 +185,7 @@
FOIL_ERROR_KEY_UNRECOGNIZED_FORMAT,
"Unsupported AES%d key format", klass->size*8));
}
- GWARN("Unsupported AES%d key format", klass->size*8);
+ GDEBUG("Unsupported AES%d key format", klass->size*8);
return NULL;
}
}
@@ -209,10 +211,9 @@
static
GBytes*
-foil_key_aes_to_bytes(
- FoilKey* key)
+foil_key_aes_default_bytes(
+ FoilKeyAes* self)
{
- FoilKeyAes* self = FOIL_KEY_AES_(key);
FoilKeyAesClass* klass = FOIL_KEY_AES_GET_CLASS(self);
guint8* bytes = g_malloc(klass->size + FOIL_AES_BLOCK_SIZE);
memcpy(bytes, self->key, klass->size);
@@ -221,6 +222,23 @@
}
static
+GBytes*
+foil_key_aes_to_bytes(
+ FoilKey* key,
+ FoilKeyBinaryFormat format)
+{
+ switch (format) {
+ case FOIL_KEY_BINARY_FORMAT_DEFAULT:
+ return foil_key_aes_default_bytes(FOIL_KEY_AES_(key));
+ case FOIL_KEY_BINARY_FORMAT_RSA_SSH:
+ case FOIL_KEY_EXPORT_FORMAT_RSA_PKCS1:
+ break;
+ }
+ /* Invalid/unsupported format */
+ return NULL;
+}
+
+static
FoilKey*
foil_key_aes_set_iv(
FoilKey* key,
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/libfoil/src/foil_key_des.c
^
|
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2019-2021 by Slava Monich
+ * Copyright (C) 2019-2022 by Slava Monich <slava@monich.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -269,10 +269,9 @@
static
GBytes*
-foil_key_des_to_bytes(
- FoilKey* key)
+foil_key_des_default_bytes(
+ FoilKeyDes* self)
{
- FoilKeyDes* self = FOIL_KEY_DES_(key);
guint8* bytes;
gsize size = FOIL_DES_IV_SIZE + FOIL_DES_KEY_SIZE;
if (self->key2) {
@@ -296,6 +295,23 @@
}
static
+GBytes*
+foil_key_des_to_bytes(
+ FoilKey* key,
+ FoilKeyBinaryFormat format)
+{
+ switch (format) {
+ case FOIL_KEY_BINARY_FORMAT_DEFAULT:
+ return foil_key_des_default_bytes(FOIL_KEY_DES_(key));
+ case FOIL_KEY_BINARY_FORMAT_RSA_SSH:
+ case FOIL_KEY_EXPORT_FORMAT_RSA_PKCS1:
+ break;
+ }
+ /* Invalid/unsupported format */
+ return NULL;
+}
+
+static
FoilKey*
foil_key_des_set_iv(
FoilKey* key,
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/libfoil/src/foil_key_des_p.h
^
|
@@ -33,8 +33,8 @@
#ifndef FOIL_KEY_DES_P_H
#define FOIL_KEY_DES_P_H
-#include "foil_key_des.h"
#include "foil_key_p.h"
+#include "foil_key_des.h"
typedef struct foil_key_des_class FoilKeyDesClass;
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/libfoil/src/foil_key_p.h
^
|
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016-2019 by Slava Monich
+ * Copyright (C) 2016-2022 by Slava Monich <slava@monich.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -51,7 +51,7 @@
GHashTable* param, GError** error);
FoilKey* (*fn_set_iv)(FoilKey* key1, const void* iv, gsize len);
gboolean (*fn_equal)(FoilKey* key1, FoilKey* key2);
- GBytes* (*fn_to_bytes)(FoilKey* key);
+ GBytes* (*fn_to_bytes)(FoilKey* key, FoilKeyBinaryFormat format);
gboolean (*fn_export)(FoilKey* key, FoilOutput* out,
FoilKeyExportFormat format, GHashTable* param, GError** error);
GBytes* (*fn_fingerprint)(FoilKey* key);
@@ -71,7 +71,8 @@
foil_key_set_iv(
FoilKey* key,
const void* iv,
- gsize len);
+ gsize len)
+ FOIL_INTERNAL;
#endif /* FOIL_KEY_P_H */
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/libfoil/src/foil_key_rsa_private.c
^
|
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016-2021 by Slava Monich <slava@monich.com>
+ * Copyright (C) 2016-2022 by Slava Monich <slava@monich.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -35,6 +35,7 @@
#include "foil_key_rsa_private.h"
#include "foil_key_rsa_public.h"
#include "foil_key_aes.h"
+#include "foil_kdf.h"
#include "foil_random.h"
#include "foil_cipher.h"
#include "foil_digest.h"
@@ -191,13 +192,29 @@
static
GBytes*
-foil_key_rsa_private_to_bytes(
- FoilKey* key)
+foil_key_rsa_private_bytes_pkcs1(
+ FoilKeyRsaPrivate* self)
{
- FoilKeyRsaPrivate* self = FOIL_KEY_RSA_PRIVATE_(key);
return foil_key_rsa_private_data_to_bytes(self->data);
}
+static
+GBytes*
+foil_key_rsa_private_to_bytes(
+ FoilKey* key,
+ FoilKeyBinaryFormat format)
+{
+ switch (format) {
+ case FOIL_KEY_BINARY_FORMAT_DEFAULT:
+ case FOIL_KEY_EXPORT_FORMAT_RSA_PKCS1:
+ return foil_key_rsa_private_bytes_pkcs1(FOIL_KEY_RSA_PRIVATE_(key));
+ case FOIL_KEY_BINARY_FORMAT_RSA_SSH:
+ break;
+ }
+ /* Invalid/unsupported format */
+ return NULL;
+}
+
/*
* AlgorithmIdentifier is defined in RFC 5280 as follows:
*
@@ -446,7 +463,6 @@
return decrypted;
}
-/* PBKDF2 defined in RFC 2898 */
static
GBytes*
foil_key_rsa_private_pbkdf2(
@@ -457,64 +473,15 @@
GType digest,
FoilBytes* iv)
{
- const gsize hlen = foil_digest_type_size(digest);
- const gsize pass_len = pass ? strlen(pass) : 0;
- FoilHmac* tmpl = foil_hmac_new(digest, pass, pass_len);
- FoilHmac* hmac = foil_hmac_clone(tmpl);
const gsize key_size = bits/8;
- const guint total = key_size + iv->len;
+ const gsize total = key_size + iv->len;
guint8* data = g_malloc(total);
- guint8* ptr = data;
- gsize bytesleft = key_size;
- gsize i = 1;
-
- while (bytesleft > 0) {
- const gsize cplen = MIN(bytesleft, hlen);
- const guint8* h;
- guint8 itmp[4];
- GBytes* b;
- gsize j;
-
- itmp[0] = (unsigned char)((i >> 24) & 0xff);
- itmp[1] = (unsigned char)((i >> 16) & 0xff);
- itmp[2] = (unsigned char)((i >> 8) & 0xff);
- itmp[3] = (unsigned char)(i & 0xff);
-
- /* First time doesn't need a copy, it's already a clone */
- if (ptr != data) {
- foil_hmac_copy(hmac, tmpl);
- }
- foil_hmac_update(hmac, salt->val, salt->len);
- foil_hmac_update(hmac, itmp, 4);
-
- b = g_bytes_ref(foil_hmac_finish(hmac));
- h = g_bytes_get_data(b, NULL);
- memcpy(ptr, h, cplen);
-
- for (j = 1; j < count; j++) {
- gsize k;
-
- foil_hmac_copy(hmac, tmpl);
- foil_hmac_update(hmac, h, hlen);
-
- g_bytes_unref(b);
- b = g_bytes_ref(foil_hmac_finish(hmac));
- h = g_bytes_get_data(b, NULL);
-
- for (k = 0; k < cplen; k++) {
- ptr[k] ^= h[k];
- }
- }
-
- g_bytes_unref(b);
- bytesleft -= cplen;
- ptr += cplen;
- i++;
- }
+ GBytes* key = foil_kdf_pbkdf2(digest, pass, pass ? strlen(pass) : 0,
+ salt, count, key_size);
- foil_hmac_unref(hmac);
- foil_hmac_unref(tmpl);
- memcpy(ptr, iv->val, iv->len);
+ memcpy(data, g_bytes_get_data(key, NULL), key_size);
+ memcpy(data + key_size, iv->val, iv->len);
+ g_bytes_unref(key);
return g_bytes_new_take(data, total);
}
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/libfoil/src/foil_key_rsa_private.h
^
|
@@ -1,26 +1,31 @@
/*
- * Copyright (C) 2016-2019 by Slava Monich
+ * Copyright (C) 2016-2022 by Slava Monich
*
* 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.
+ * 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 ``AS IS'' AND ANY EXPRESSED 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 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) ARISING
- * IN ANY WAY OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN
- * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 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.
*
* The views and conclusions contained in the software and documentation
* are those of the authors and should not be interpreted as representing
@@ -77,7 +82,8 @@
void
foil_key_rsa_private_get_public_data(
FoilKeyRsaPrivate* priv,
- FoilKeyRsaPublicData* pub_data);
+ FoilKeyRsaPublicData* pub_data)
+ FOIL_INTERNAL;
#endif /* FOIL_KEY_PRIVATE_H */
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/libfoil/src/foil_key_rsa_public.c
^
|
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016-2021 by Slava Monich <slava@monich.com>
+ * Copyright (C) 2016-2022 by Slava Monich <slava@monich.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -174,7 +174,7 @@
static
GBytes*
-foil_key_rsa_public_data_to_bytes(
+foil_key_rsa_public_data_ssh_rsa(
const FoilKeyRsaPublicData* data)
{
GBytes* bytes = NULL;
@@ -192,15 +192,6 @@
}
static
-GBytes*
-foil_key_rsa_public_to_bytes(
- FoilKey* key)
-{
- FoilKeyRsaPublic* self = FOIL_KEY_RSA_PUBLIC_(key);
- return foil_key_rsa_public_data_to_bytes(self->data);
-}
-
-static
gboolean
foil_key_rsa_public_parse_ssh_rsa_binary(
FoilKeyRsaPublicData* key,
@@ -261,7 +252,9 @@
}
/*
- * Format defined in RFC 2313:
+ * PKCS #1
+ *
+ * https://www.ietf.org/rfc/rfc3447 (Appendix A)
*
* RSAPublicKey ::= SEQUENCE {
* modulus INTEGER, -- n
@@ -269,7 +262,7 @@
*/
static
gboolean
-foil_key_rsa_public_parse_asn1(
+foil_key_rsa_public_parse_pkcs1(
FoilKeyRsaPublicData* key,
const FoilBytes* bytes)
{
@@ -306,6 +299,24 @@
return NULL;
}
+static
+GBytes*
+foil_key_rsa_public_to_bytes(
+ FoilKey* key,
+ FoilKeyBinaryFormat format)
+{
+ FoilKeyRsaPublic* self = FOIL_KEY_RSA_PUBLIC_(key);
+ switch (format) {
+ case FOIL_KEY_BINARY_FORMAT_DEFAULT: /* fallthrough */
+ case FOIL_KEY_BINARY_FORMAT_RSA_SSH:
+ return foil_key_rsa_public_data_ssh_rsa(self->data);
+ case FOIL_KEY_EXPORT_FORMAT_RSA_PKCS1:
+ return foil_key_rsa_public_data_to_asn1(self->data);
+ }
+ /* Invalid/unsupported format */
+ return NULL;
+}
+
/*
* Format defined in RFC 5208:
*
@@ -345,7 +356,7 @@
if (foil_asn1_parse_object_id(&aid, &oid) &&
foil_bytes_equal(&oid, &oid_rsa) &&
foil_asn1_parse_bit_string(&pos, &bits, &unused) && !unused) {
- return foil_key_rsa_public_parse_asn1(key, &bits);
+ return foil_key_rsa_public_parse_pkcs1(key, &bits);
}
}
}
@@ -449,7 +460,8 @@
if (foil_key_rsa_public_parse_ssh_rsa_text(&key, &data, &pool) ||
foil_key_rsa_public_parse_pkcs8(&key, &data, &pool) ||
foil_key_rsa_public_parse_rfc4716(&key, &data, &pool) ||
- foil_key_rsa_public_parse_ssh_rsa_binary(&key, &data)) {
+ foil_key_rsa_public_parse_ssh_rsa_binary(&key, &data) ||
+ foil_key_rsa_public_parse_pkcs1(&key, &data)) {
FoilKeyRsaPublic* pub = g_object_new(G_TYPE_FROM_CLASS(klass), NULL);
foil_key_rsa_public_set_data(pub, &key);
g_clear_error(error);
@@ -460,7 +472,7 @@
FOIL_ERROR_KEY_UNRECOGNIZED_FORMAT,
"Unrecognized RSA public key format"));
}
- GWARN("Unsupported RSA public key format");
+ GDEBUG("Unsupported RSA public key format");
}
foil_pool_drain(&pool);
return result;
@@ -478,7 +490,7 @@
gboolean ok = foil_output_write_all(out, ssh_rsa_text_prefix,
sizeof(ssh_rsa_text_prefix)) && foil_output_write_all(out, &space, 1);
if (ok) {
- GBytes* bytes = foil_key_rsa_public_data_to_bytes(self->data);
+ GBytes* bytes = foil_key_rsa_public_data_ssh_rsa(self->data);
FoilOutput* base64 = foil_output_base64_new(out);
ok = foil_output_write_bytes_all(base64, bytes) &&
foil_output_flush(base64);
@@ -517,7 +529,7 @@
}
}
if (ok) {
- GBytes* bytes = foil_key_rsa_public_data_to_bytes(self->data);
+ GBytes* bytes = foil_key_rsa_public_data_ssh_rsa(self->data);
FoilOutput* base64 = foil_output_base64_new_full(out, 0, 70);
ok = foil_output_write_bytes_all(base64, bytes) &&
foil_output_flush(base64);
@@ -641,7 +653,7 @@
foil_key_rsa_public_data_fingerprint(
const FoilKeyRsaPublicData* data)
{
- GBytes* bytes = foil_key_rsa_public_data_to_bytes(data);
+ GBytes* bytes = foil_key_rsa_public_data_ssh_rsa(data);
GBytes* fingerprint = foil_digest_bytes(FOIL_DIGEST_MD5, bytes);
g_bytes_unref(bytes);
return fingerprint;
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/libfoil/src/foil_key_rsa_public.h
^
|
@@ -5,22 +5,27 @@
* 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.
+ * 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 ``AS IS'' AND ANY EXPRESSED 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 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) ARISING
- * IN ANY WAY OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN
- * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 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.
*
* The views and conclusions contained in the software and documentation
* are those of the authors and should not be interpreted as representing
@@ -58,11 +63,13 @@
void
foil_key_rsa_public_set_data(
FoilKeyRsaPublic* pub,
- const FoilKeyRsaPublicData* data);
+ const FoilKeyRsaPublicData* data)
+ FOIL_INTERNAL;
GBytes*
foil_key_rsa_public_data_fingerprint(
- const FoilKeyRsaPublicData* data);
+ const FoilKeyRsaPublicData* data)
+ FOIL_INTERNAL;
#endif /* FOIL_KEY_PUBLIC_H */
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/libfoil/src/foil_output.c
^
|
@@ -1,26 +1,31 @@
/*
- * Copyright (C) 2016-2018 by Slava Monich
+ * Copyright (C) 2016-2022 by Slava Monich
*
* 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.
+ * 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 ``AS IS'' AND ANY EXPRESSED 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 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) ARISING
- * IN ANY WAY OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN
- * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 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.
*
* The views and conclusions contained in the software and documentation
* are those of the authors and should not be interpreted as representing
@@ -102,7 +107,7 @@
gsize size;
const void* data = g_bytes_get_data(bytes, &size);
if (size > 0) {
- const gsize written = out->fn->fn_write(out, data, size);
+ const gssize written = out->fn->fn_write(out, data, size);
if (written > 0) {
GASSERT((gsize)written <= size);
out->bytes_written += written;
@@ -126,7 +131,7 @@
gsize size;
const void* data = g_bytes_get_data(bytes, &size);
if (size > 0) {
- const gsize written = out->fn->fn_write(out, data, size);
+ const gssize written = out->fn->fn_write(out, data, size);
if (written > 0) {
GASSERT((gsize)written <= size);
out->bytes_written += written;
@@ -148,7 +153,7 @@
*/
guint
foil_output_write_eol(
- FoilOutput* out)
+ FoilOutput* out) /* Since 1.0.9 */
{
static const char eol = '\n';
gssize written = foil_output_write(out, &eol, 1);
@@ -156,6 +161,14 @@
}
gboolean
+foil_output_write_byte(
+ FoilOutput* out,
+ guint8 byte) /* Since 1.0.27 */
+{
+ return foil_output_write(out, &byte, 1) == 1;
+}
+
+gboolean
foil_output_flush(
FoilOutput* out)
{
|
[-]
[+]
|
Added |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/libfoil/src/foil_output_cipher.c
^
|
@@ -0,0 +1,260 @@
+/*
+ * Copyright (C) 2022 by Slava Monich <slava@monich.com>
+ *
+ * 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.
+ *
+ * The views and conclusions contained in the software and documentation
+ * are those of the authors and should not be interpreted as representing
+ * any official policies, either expressed or implied.
+ */
+
+#include "foil_cipher.h"
+#include "foil_digest_p.h"
+#include "foil_hmac.h"
+#include "foil_output_p.h"
+
+#include <gutil_macros.h>
+
+/* Logging */
+#define GLOG_MODULE_NAME foil_log_output
+#include "foil_log_p.h"
+
+typedef struct foil_output_cipher {
+ FoilOutput parent;
+ FoilOutput* out;
+ FoilCipher* cipher;
+ gsize in_block_size;
+ gsize in_block_used;
+ guint8* in_block;
+ guint8* out_block;
+ void* digest;
+ FoilDigestGenericUpdateFunc digest_update;
+ FoilDigestGenericUnrefFunc digest_unref;
+} FoilOutputCipher;
+
+static
+gssize
+foil_output_cipher_write(
+ FoilOutput* out,
+ const void* data,
+ gsize size)
+{
+ FoilOutputCipher* self = G_CAST(out, FoilOutputCipher, parent);
+ const guint8* ptr = data;
+ gsize left = size;
+
+ while (self->in_block_used + left >= self->in_block_size) {
+ int encrypted;
+
+ if (self->in_block_used) {
+ const guint remaining = self->in_block_size - self->in_block_used;
+
+ memcpy(self->in_block + self->in_block_used, ptr, remaining);
+ encrypted = foil_cipher_step(self->cipher, self->in_block,
+ self->out_block);
+ self->digest_update(self->digest, self->in_block,
+ self->in_block_size);
+ self->in_block_used = 0;
+ left -= remaining;
+ ptr += remaining;
+ } else {
+ encrypted = foil_cipher_step(self->cipher, ptr, self->out_block);
+ self->digest_update(self->digest, ptr, self->in_block_size);
+ left -= self->in_block_size;
+ ptr += self->in_block_size;
+ }
+
+ if (encrypted < 0 || !foil_output_write_all(self->out,
+ self->out_block, encrypted)) {
+ return -1;
+ }
+ }
+
+ /* Stash the remaining non-encrypted bytes */
+ if (left > 0) {
+ if (!self->in_block) {
+ self->in_block = g_malloc(self->in_block_size);
+ }
+ memcpy(self->in_block + self->in_block_used, ptr, left);
+ self->in_block_used += left;
+ }
+
+ return size;
+}
+
+static
+gboolean
+foil_output_cipher_finish(
+ FoilOutputCipher* self)
+{
+ const int nout = foil_cipher_finish(self->cipher, self->in_block,
+ self->in_block_used, self->out_block);
+ const gboolean ok = ((nout == 0) || ((nout > 0) &&
+ foil_output_write_all(self->out, self->out_block, nout)));
+
+ /* Leave self->out to the caller */
+ self->digest_update(self->digest, self->in_block, self->in_block_used);
+ self->digest_unref(self->digest);
+ foil_cipher_unref(self->cipher);
+ g_free(self->in_block);
+ g_free(self->out_block);
+ self->in_block_used = 0;
+ self->in_block = NULL;
+ self->out_block = NULL;
+ self->cipher = NULL;
+ return ok;
+}
+
+static
+gboolean
+foil_output_cipher_flush(
+ FoilOutput* out)
+{
+ return TRUE;
+}
+
+static
+gboolean
+foil_output_cipher_reset(
+ FoilOutput* out)
+{
+ return FALSE;
+}
+
+static
+GBytes*
+foil_output_cipher_to_bytes(
+ FoilOutput* out)
+{
+ FoilOutputCipher* self = G_CAST(out, FoilOutputCipher, parent);
+ GBytes* bytes;
+
+ if (foil_output_cipher_finish(self)) {
+ bytes = foil_output_free_to_bytes(self->out);
+ } else {
+ foil_output_close(self->out);
+ foil_output_unref(self->out);
+ bytes = NULL;
+ }
+ self->out = NULL;
+ return bytes;
+}
+
+static
+void
+foil_output_cipher_close(
+ FoilOutput* out)
+{
+ FoilOutputCipher* self = G_CAST(out, FoilOutputCipher, parent);
+
+ foil_output_cipher_finish(self);
+ foil_output_close(self->out);
+ foil_output_unref(self->out);
+ self->out = NULL;
+}
+
+static
+void
+foil_output_cipher_free(
+ FoilOutput* out)
+{
+ g_slice_free(FoilOutputCipher, G_CAST(out, FoilOutputCipher, parent));
+}
+
+static
+FoilOutput*
+foil_output_cipher_internal_new(
+ FoilOutput* out,
+ FoilCipher* cipher,
+ gsize in_size,
+ gsize out_size,
+ void* digest_ref,
+ FoilDigestGenericUpdateFunc digest_update,
+ FoilDigestGenericUnrefFunc digest_unref)
+{
+ static const FoilOutputFunc foil_output_cipher_fn = {
|
[-]
[+]
|
Added |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/libfoil/src/foil_output_cipher_mem.c
^
|
@@ -0,0 +1,287 @@
+/*
+ * Copyright (C) 2022 by Slava Monich <slava@monich.com>
+ *
+ * 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.
+ *
+ * The views and conclusions contained in the software and documentation
+ * are those of the authors and should not be interpreted as representing
+ * any official policies, either expressed or implied.
+ */
+
+#include "foil_cipher.h"
+#include "foil_digest_p.h"
+#include "foil_hmac.h"
+#include "foil_output_p.h"
+
+#include <gutil_macros.h>
+
+/* Logging */
+#define GLOG_MODULE_NAME foil_log_output
+#include "foil_log_p.h"
+
+typedef struct foil_output_cipher_mem {
+ FoilOutput parent;
+ FoilCipher* cipher;
+ GByteArray* buf;
+ gsize offset;
+ gsize out_block_size;
+ gsize in_block_size;
+ gsize in_block_used;
+ guint8* in_block;
+ void* digest;
+ FoilDigestGenericUpdateFunc digest_update;
+ FoilDigestGenericUnrefFunc digest_unref;
+} FoilOutputCipherMem;
+
+static
+gssize
+foil_output_cipher_mem_write(
+ FoilOutput* out,
+ const void* data,
+ gsize size)
+{
+ FoilOutputCipherMem* self = G_CAST(out, FoilOutputCipherMem, parent);
+ GByteArray* buf = self->buf;
+ const guint8* ptr = data;
+ gsize left = size;
+
+ while (self->in_block_used + left >= self->in_block_size) {
+ const guint prev_len = buf->len;
+ const void* in_block;
+ int nout;
+
+ if (self->in_block_used) {
+ const guint remaining = self->in_block_size - self->in_block_used;
+
+ in_block = self->in_block;
+ memcpy(self->in_block + self->in_block_used, ptr, remaining);
+ self->in_block_used = 0;
+ left -= remaining;
+ ptr += remaining;
+ } else {
+ /* Can write directly into the output buffer */
+ in_block = ptr;
+ left -= self->in_block_size;
+ ptr += self->in_block_size;
+ }
+
+ g_byte_array_set_size(buf, prev_len + self->out_block_size);
+ nout = foil_cipher_step(self->cipher, in_block, buf->data + prev_len);
+ if (nout < 0) {
+ g_byte_array_set_size(buf, prev_len);
+ return -1;
+ } else {
+ g_byte_array_set_size(buf, prev_len + nout);
+ }
+ }
+
+ /* Stash the remaining non-encrypted bytes */
+ if (left > 0) {
+ if (!self->in_block) {
+ self->in_block = g_malloc(self->in_block_size);
+ }
+ memcpy(self->in_block + self->in_block_used, ptr, left);
+ self->in_block_used += left;
+ }
+
+ self->digest_update(self->digest, data, size);
+ return size;
+}
+
+static
+gboolean
+foil_output_cipher_mem_finish(
+ FoilOutputCipherMem* self)
+{
+ GByteArray* buf = self->buf;
+ const guint prev_len = buf->len;
+ int nout;
+
+ /* Cipher the remaining data */
+ g_byte_array_set_size(buf, prev_len + self->out_block_size);
+ nout = foil_cipher_finish(self->cipher, self->in_block,
+ self->in_block_used, buf->data + prev_len);
+ if (nout < 0) {
+ g_byte_array_set_size(buf, prev_len);
+ } else {
+ g_byte_array_set_size(buf, prev_len + nout);
+ }
+
+ /* Leave self->buf to the caller */
+ self->digest_unref(self->digest);
+ foil_cipher_unref(self->cipher);
+ g_free(self->in_block);
+ self->in_block_used = 0;
+ self->in_block = NULL;
+ self->cipher = NULL;
+ return (nout >= 0);
+}
+
+static
+gboolean
+foil_output_cipher_mem_flush(
+ FoilOutput* out)
+{
+ return TRUE;
+}
+
+static
+gboolean
+foil_output_cipher_mem_reset(
+ FoilOutput* out)
+{
+ /* There's no generic way to reset the cipher state */
+ return FALSE;
+}
+
+static
+GBytes*
+foil_output_cipher_mem_to_bytes(
+ FoilOutput* out)
+{
+ FoilOutputCipherMem* self = G_CAST(out, FoilOutputCipherMem, parent);
+ GByteArray* buf = self->buf;
+
+ if (!foil_output_cipher_mem_finish(self)) {
+ g_byte_array_unref(buf);
+ self->buf = NULL;
+ return NULL;
+ } else {
+ /* Avoid copying the data */
+ GBytes* bytes = g_byte_array_free_to_bytes(buf);
+
+ self->buf = NULL;
+ if (self->offset) {
+ GBytes* our_bytes = g_bytes_new_from_bytes(bytes, self->offset,
+ g_bytes_get_size(bytes) - self->offset);
+
+ g_bytes_unref(bytes);
+ return our_bytes;
+ } else {
+ return bytes;
+ }
+ }
+}
+
+static
+void
+foil_output_cipher_mem_close(
+ FoilOutput* out)
+{
+ FoilOutputCipherMem* self = G_CAST(out, FoilOutputCipherMem, parent);
+
+ foil_output_cipher_mem_finish(self);
+ g_byte_array_unref(self->buf);
+ self->buf = NULL;
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/libfoil/src/foil_output_mem.c
^
|
@@ -1,26 +1,31 @@
/*
- * Copyright (C) 2016-2017 by Slava Monich
+ * Copyright (C) 2016-2022 by Slava Monich
*
* 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.
+ * 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 ``AS IS'' AND ANY EXPRESSED 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 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) ARISING
- * IN ANY WAY OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN
- * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 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.
*
* The views and conclusions contained in the software and documentation
* are those of the authors and should not be interpreted as representing
@@ -49,6 +54,7 @@
gsize size)
{
FoilOutputMem* self = G_CAST(out, FoilOutputMem, parent);
+
g_byte_array_append(self->buf, buf, size);
return size;
}
@@ -77,20 +83,26 @@
FoilOutput* out)
{
FoilOutputMem* self = G_CAST(out, FoilOutputMem, parent);
- GBytes* bytes = g_byte_array_free_to_bytes(self->buf);
- const gsize size = g_bytes_get_size(bytes);
+ GByteArray* buf = self->buf;
+ const guint size = buf->len;
+
self->buf = NULL;
GASSERT(size == self->offset + out->bytes_written);
if (size != self->offset + out->bytes_written) {
- g_bytes_unref(bytes);
- bytes = NULL;
- } else if (self->offset) {
- GBytes* our_bytes = g_bytes_new_from_bytes(bytes,
- self->offset, size - self->offset);
- g_bytes_unref(bytes);
- bytes = our_bytes;
+ g_byte_array_unref(buf);
+ return NULL;
+ } else {
+ /* Avoid copying the data */
+ GBytes* bytes = g_byte_array_free_to_bytes(buf);
+ if (self->offset) {
+ GBytes* our_bytes = g_bytes_new_from_bytes(bytes,
+ self->offset, size - self->offset);
+ g_bytes_unref(bytes);
+ return our_bytes;
+ } else {
+ return bytes;
+ }
}
- return bytes;
}
static
@@ -99,6 +111,7 @@
FoilOutput* out)
{
FoilOutputMem* self = G_CAST(out, FoilOutputMem, parent);
+
g_byte_array_unref(self->buf);
self->buf = NULL;
}
@@ -109,8 +122,9 @@
FoilOutput* out)
{
FoilOutputMem* self = G_CAST(out, FoilOutputMem, parent);
+
GASSERT(!self->buf);
- g_slice_free(FoilOutputMem, self);
+ gutil_slice_free(self);
}
FoilOutput*
@@ -126,6 +140,7 @@
foil_output_mem_free /* fn_free */
};
FoilOutputMem* mem = g_slice_new0(FoilOutputMem);
+
if (buf) {
mem->buf = g_byte_array_ref(buf);
mem->offset = buf->len;
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/libfoil/src/foil_output_p.h
^
|
@@ -1,26 +1,31 @@
/*
- * Copyright (C) 2016-2017 by Slava Monich
+ * Copyright (C) 2016-2022 by Slava Monich
*
* 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.
+ * 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 ``AS IS'' AND ANY EXPRESSED 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 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) ARISING
- * IN ANY WAY OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN
- * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 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.
*
* The views and conclusions contained in the software and documentation
* are those of the authors and should not be interpreted as representing
@@ -30,6 +35,7 @@
#ifndef FOIL_OUTPUT_P_H
#define FOIL_OUTPUT_P_H
+#include "foil_types_p.h"
#include "foil_output.h"
typedef struct foil_output_func {
@@ -51,7 +57,8 @@
FoilOutput*
foil_output_init(
FoilOutput* out,
- const FoilOutputFunc* fn);
+ const FoilOutputFunc* fn)
+ FOIL_INTERNAL;
#endif /* FOIL_OUTPUT_P_H */
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/libfoil/src/foil_pool.h
^
|
@@ -1,26 +1,31 @@
/*
- * Copyright (C) 2019 by Slava Monich
+ * Copyright (C) 2019-2022 by Slava Monich
*
* 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.
+ * 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 ``AS IS'' AND ANY EXPRESSED 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 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) ARISING
- * IN ANY WAY OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN
- * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 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.
*
* The views and conclusions contained in the software and documentation
* are those of the authors and should not be interpreted as representing
@@ -30,7 +35,7 @@
#ifndef FOIL_POOL_H
#define FOIL_POOL_H
-#include "foil_types.h"
+#include "foil_types_p.h"
typedef struct foil_pool_item FoilPoolItem;
@@ -41,27 +46,32 @@
void
foil_pool_init(
- FoilPool* pool);
+ FoilPool* pool)
+ FOIL_INTERNAL;
void
foil_pool_drain(
- FoilPool* pool);
+ FoilPool* pool)
+ FOIL_INTERNAL;
void
foil_pool_add(
FoilPool* pool,
gpointer pointer,
- GDestroyNotify destroy);
+ GDestroyNotify destroy)
+ FOIL_INTERNAL;
void
foil_pool_add_bytes(
FoilPool* pool,
- GBytes* bytes);
+ GBytes* bytes)
+ FOIL_INTERNAL;
void
foil_pool_add_bytes_ref(
FoilPool* pool,
- GBytes* bytes);
+ GBytes* bytes)
+ FOIL_INTERNAL;
#endif /* FOIL_POOL_H */
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/libfoil/src/foil_random_p.h
^
|
@@ -1,26 +1,31 @@
/*
- * Copyright (C) 2016 by Slava Monich
+ * Copyright (C) 2016-2022 by Slava Monich
*
* 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.
+ * 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 ``AS IS'' AND ANY EXPRESSED 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 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) ARISING
- * IN ANY WAY OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN
- * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 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.
*
* The views and conclusions contained in the software and documentation
* are those of the authors and should not be interpreted as representing
@@ -43,7 +48,7 @@
GObject object;
};
-GType foil_random_get_type(void);
+GType foil_random_get_type(void) FOIL_INTERNAL;
#define FOIL_TYPE_RANDOM (foil_random_get_type())
#define FOIL_RANDOM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), \
FOIL_TYPE_RANDOM, FoilRandomClass))
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/libfoil/src/foil_types_p.h
^
|
@@ -1,26 +1,31 @@
/*
- * Copyright (C) 2016-2019 by Slava Monich
+ * Copyright (C) 2016-2022 by Slava Monich
*
* 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.
+ * 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 ``AS IS'' AND ANY EXPRESSED 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 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) ARISING
- * IN ANY WAY OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN
- * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 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.
*
* The views and conclusions contained in the software and documentation
* are those of the authors and should not be interpreted as representing
@@ -38,6 +43,8 @@
typedef struct foil_key_rsa_public_data FoilKeyRsaPublicData;
+#define FOIL_INTERNAL G_GNUC_INTERNAL
+
#define FOIL_ALIGN(x) G_ALIGN4(x)
#define FOIL_BYTES_SET(bytes,data) \
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/libfoil/src/foil_util_p.h
^
|
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016-2021 by Slava Monich <slava@monich.com>
+ * Copyright (C) 2016-2022 by Slava Monich <slava@monich.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -35,70 +35,82 @@
#ifndef FOIL_UTIL_P_H
#define FOIL_UTIL_P_H
-#include "foil_util.h"
#include "foil_types_p.h"
+#include "foil_util.h"
guint8*
foil_bytes_copy(
FoilBytes* dest,
const FoilBytes* src,
- guint8* ptr);
+ guint8* ptr)
+ FOIL_INTERNAL;
void
foil_bytes_digest(
FoilBytes* bytes,
- FoilDigest* digest);
+ FoilDigest* digest)
+ FOIL_INTERNAL;
void*
foil_class_ref(
GType type,
- GType base);
+ GType base)
+ FOIL_INTERNAL;
void*
foil_abstract_class_ref(
GType type,
- GType base);
+ GType base)
+ FOIL_INTERNAL;
gsize
foil_parse_init_data(
GUtilRange* pos,
- const FoilBytes* data);
+ const FoilBytes* data)
+ FOIL_INTERNAL;
gsize
foil_parse_init_bytes(
GUtilRange* pos,
- GBytes* bytes);
+ GBytes* bytes)
+ FOIL_INTERNAL;
gsize
foil_parse_init_string(
GUtilRange* pos,
- const char* str);
+ const char* str)
+ FOIL_INTERNAL;
gboolean
foil_parse_skip_to_next_line(
GUtilRange* pos,
- gboolean continued);
+ gboolean continued)
+ FOIL_INTERNAL;
GHashTable*
foil_parse_headers(
GUtilRange* pos,
- GString* buf);
+ GString* buf)
+ FOIL_INTERNAL;
char*
foil_format_header(
const char* tag,
- const char* value);
+ const char* value)
+ FOIL_INTERNAL;
GHashTable*
foil_param_add(
GHashTable* params,
const char* key,
- const char* value);
+ const char* value)
+ FOIL_INTERNAL;
const void*
foil_memmem(
const FoilBytes* haystack,
- const FoilBytes* needle);
+ const FoilBytes* needle)
+ FOIL_INTERNAL;
#endif /* FOIL_UTIL_P_H */
|
[-]
[+]
|
Added |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/libfoil/src/foil_version.c
^
|
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2022 by Slava Monich <slava@monich.com>
+ *
+ * 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.
+ *
+ * The views and conclusions contained in the software and documentation
+ * are those of the authors and should not be interpreted as representing
+ * any official policies, either expressed or implied.
+ */
+
+#include "foil_version.h"
+
+/*
+ * Function for run-time version detection in case if you're linking
+ * against a dynamic library
+ */
+unsigned int
+foil_version() /* Since 1.0.24 */
+{
+ return FOIL_VERSION;
+}
+
+/*
+ * Local Variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/libfoil/src/openssl/foil_openssl_cipher_aes_decrypt.c
^
|
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016-2019 by Slava Monich
+ * Copyright (C) 2016-2022 by Slava Monich
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -51,6 +51,11 @@
typedef FoilOpensslCipherAesDecrypt FoilOpensslCipherAesCfbDecrypt;
typedef FoilOpensslCipherAesDecrypt FoilOpensslCipherAesEcbDecrypt;
+GType foil_openssl_cipher_aes_decrypt_get_type() FOIL_INTERNAL;
+GType foil_openssl_cipher_aes_cbc_decrypt_get_type() FOIL_INTERNAL;
+GType foil_openssl_cipher_aes_cfb_decrypt_get_type() FOIL_INTERNAL;
+GType foil_openssl_cipher_aes_ecb_decrypt_get_type() FOIL_INTERNAL;
+
G_DEFINE_ABSTRACT_TYPE(FoilOpensslCipherAesDecrypt,
foil_openssl_cipher_aes_decrypt, FOIL_TYPE_CIPHER_AES)
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/libfoil/src/openssl/foil_openssl_cipher_aes_encrypt.c
^
|
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016-2019 by Slava Monich
+ * Copyright (C) 2016-2022 by Slava Monich
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -47,6 +47,11 @@
typedef FoilOpensslCipherAesEncrypt FoilOpensslCipherAesCfbEncrypt;
typedef FoilOpensslCipherAesEncrypt FoilOpensslCipherAesEcbEncrypt;
+GType foil_openssl_cipher_aes_encrypt_get_type() FOIL_INTERNAL;
+GType foil_openssl_cipher_aes_cbc_encrypt_get_type() FOIL_INTERNAL;
+GType foil_openssl_cipher_aes_cfb_encrypt_get_type() FOIL_INTERNAL;
+GType foil_openssl_cipher_aes_ecb_encrypt_get_type() FOIL_INTERNAL;
+
G_DEFINE_ABSTRACT_TYPE(FoilOpensslCipherAesEncrypt,
foil_openssl_cipher_aes_encrypt, FOIL_TYPE_CIPHER_AES)
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/libfoil/src/openssl/foil_openssl_cipher_des_cbc.c
^
|
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2019 by Slava Monich
+ * Copyright (C) 2019-2022 by Slava Monich
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -55,6 +55,10 @@
typedef FoilOpensslCipherDesCbcClass FoilOpensslCipherDesCbcEncryptClass;
typedef FoilOpensslCipherDesCbcClass FoilOpensslCipherDesCbcDecryptClass;
+GType foil_openssl_cipher_des_cbc_get_type() FOIL_INTERNAL;
+GType foil_openssl_cipher_des_cbc_encrypt_get_type() FOIL_INTERNAL;
+GType foil_openssl_cipher_des_cbc_decrypt_get_type() FOIL_INTERNAL;
+
G_DEFINE_ABSTRACT_TYPE(FoilOpensslCipherDesCbc,
foil_openssl_cipher_des_cbc,
FOIL_TYPE_CIPHER_SYNC);
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/libfoil/src/openssl/foil_openssl_cipher_rsa_decrypt.c
^
|
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016-2019 by Slava Monich
+ * Copyright (C) 2016-2022 by Slava Monich
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -40,6 +40,8 @@
typedef FoilOpensslCipherRsaClass FoilOpensslCipherRsaDecryptClass;
typedef FoilOpensslCipherRsa FoilOpensslCipherRsaDecrypt;
+GType foil_openssl_cipher_rsa_decrypt_get_type() FOIL_INTERNAL;
+
G_DEFINE_TYPE(FoilOpensslCipherRsaDecrypt, foil_openssl_cipher_rsa_decrypt,
FOIL_OPENSSL_TYPE_CIPHER_RSA)
#define FOIL_OPENSSL_TYPE_CIPHER_RSA_DECRYPT \
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/libfoil/src/openssl/foil_openssl_cipher_rsa_encrypt.c
^
|
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016-2019 by Slava Monich
+ * Copyright (C) 2016-2022 by Slava Monich
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -40,6 +40,8 @@
typedef FoilOpensslCipherRsaClass FoilOpensslCipherRsaEncryptClass;
typedef FoilOpensslCipherRsa FoilOpensslCipherRsaEncrypt;
+GType foil_openssl_cipher_rsa_encrypt_get_type() FOIL_INTERNAL;
+
G_DEFINE_TYPE(FoilOpensslCipherRsaEncrypt, foil_openssl_cipher_rsa_encrypt,
FOIL_OPENSSL_TYPE_CIPHER_RSA)
#define FOIL_OPENSSL_TYPE_CIPHER_RSA_ENCRYPT \
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/libfoil/src/openssl/foil_openssl_des.h
^
|
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2019 by Slava Monich
+ * Copyright (C) 2019-2022 by Slava Monich
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -52,7 +52,7 @@
FoilOpensslKeyDesData* k3;
} FoilOpensslKeyDes;
-GType foil_openssl_key_des_get_type(void);
+GType foil_openssl_key_des_get_type(void) FOIL_INTERNAL;
#define FOIL_OPENSSL_TYPE_KEY_DES (foil_openssl_key_des_get_type())
#define FOIL_OPENSSL_KEY_DES(obj) (G_TYPE_CHECK_INSTANCE_CAST(obj, \
FOIL_OPENSSL_TYPE_KEY_DES, FoilOpensslKeyDes))
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/libfoil/src/openssl/foil_openssl_digest_md5.c
^
|
@@ -1,26 +1,31 @@
/*
- * Copyright (C) 2016-2018 by Slava Monich
+ * Copyright (C) 2016-2022 by Slava Monich
*
* 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.
+ * 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 ``AS IS'' AND ANY EXPRESSED 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 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) ARISING
- * IN ANY WAY OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN
- * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 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.
*
* The views and conclusions contained in the software and documentation
* are those of the authors and should not be interpreted as representing
@@ -41,15 +46,18 @@
MD5_CTX ctx;
} FoilOpensslDigestMD5;
+#define THIS_TYPE foil_openssl_digest_md5_get_type()
+#define THIS(obj) G_TYPE_CHECK_INSTANCE_CAST(obj, THIS_TYPE, \
+ FoilOpensslDigestMD5)
+
+GType THIS_TYPE FOIL_INTERNAL;
G_DEFINE_TYPE(FoilOpensslDigestMD5, foil_openssl_digest_md5, \
- FOIL_TYPE_DIGEST_MD5)
-#define FOIL_OPENSSL_DIGEST_MD5(obj) (G_TYPE_CHECK_INSTANCE_CAST(obj, \
- FOIL_DIGEST_MD5, FoilOpensslDigestMD5))
+ FOIL_TYPE_DIGEST_MD5)
GType
foil_impl_digest_md5_get_type()
{
- return foil_openssl_digest_md5_get_type();
+ return THIS_TYPE;
}
static
@@ -58,9 +66,15 @@
FoilDigest* digest,
FoilDigest* source)
{
- FoilOpensslDigestMD5* self = FOIL_OPENSSL_DIGEST_MD5(digest);
- FoilOpensslDigestMD5* other = FOIL_OPENSSL_DIGEST_MD5(source);
- self->ctx = other->ctx;
+ THIS(digest)->ctx = THIS(source)->ctx;
+}
+
+static
+void
+foil_openssl_digest_md5_reset(
+ FoilDigest* digest)
+{
+ MD5_Init(&(THIS(digest)->ctx));
}
static
@@ -70,8 +84,7 @@
const void* data,
size_t size)
{
- FoilOpensslDigestMD5* self = FOIL_OPENSSL_DIGEST_MD5(digest);
- MD5_Update(&self->ctx, data, size);
+ MD5_Update(&(THIS(digest)->ctx), data, size);
}
static
@@ -80,7 +93,8 @@
FoilDigest* digest,
void* md)
{
- FoilOpensslDigestMD5* self = FOIL_OPENSSL_DIGEST_MD5(digest);
+ FoilOpensslDigestMD5* self = THIS(digest);
+
if (md) {
MD5_Final(md, &self->ctx);
} else {
@@ -113,6 +127,7 @@
{
GASSERT(klass->size == MD5_DIGEST_LENGTH);
klass->fn_copy = foil_openssl_digest_md5_copy;
+ klass->fn_reset = foil_openssl_digest_md5_reset;
klass->fn_digest = foil_openssl_digest_md5_digest;
klass->fn_update = foil_openssl_digest_md5_update;
klass->fn_finish = foil_openssl_digest_md5_finish;
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/libfoil/src/openssl/foil_openssl_digest_sha1.c
^
|
@@ -1,26 +1,31 @@
/*
- * Copyright (C) 2016-2018 by Slava Monich
+ * Copyright (C) 2016-2022 by Slava Monich
*
* 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.
+ * 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 ``AS IS'' AND ANY EXPRESSED 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 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) ARISING
- * IN ANY WAY OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN
- * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 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.
*
* The views and conclusions contained in the software and documentation
* are those of the authors and should not be interpreted as representing
@@ -41,15 +46,18 @@
SHA_CTX ctx;
} FoilOpensslDigestSHA1;
+#define THIS_TYPE foil_openssl_digest_sha1_get_type()
+#define THIS(obj) G_TYPE_CHECK_INSTANCE_CAST(obj, THIS_TYPE, \
+ FoilOpensslDigestSHA1)
+
+GType THIS_TYPE FOIL_INTERNAL;
G_DEFINE_TYPE(FoilOpensslDigestSHA1, foil_openssl_digest_sha1, \
- FOIL_TYPE_DIGEST_SHA1)
-#define FOIL_OPENSSL_DIGEST_SHA1(obj) (G_TYPE_CHECK_INSTANCE_CAST(obj, \
- FOIL_DIGEST_SHA1, FoilOpensslDigestSHA1))
+ FOIL_TYPE_DIGEST_SHA1)
GType
foil_impl_digest_sha1_get_type()
{
- return foil_openssl_digest_sha1_get_type();
+ return THIS_TYPE;
}
static
@@ -58,9 +66,15 @@
FoilDigest* digest,
FoilDigest* source)
{
- FoilOpensslDigestSHA1* self = FOIL_OPENSSL_DIGEST_SHA1(digest);
- FoilOpensslDigestSHA1* other = FOIL_OPENSSL_DIGEST_SHA1(source);
- self->ctx = other->ctx;
+ THIS(digest)->ctx = THIS(source)->ctx;
+}
+
+static
+void
+foil_openssl_digest_sha1_reset(
+ FoilDigest* digest)
+{
+ SHA1_Init(&(THIS(digest)->ctx));
}
static
@@ -70,8 +84,7 @@
const void* data,
size_t size)
{
- FoilOpensslDigestSHA1* self = FOIL_OPENSSL_DIGEST_SHA1(digest);
- SHA1_Update(&self->ctx, data, size);
+ SHA1_Update(&(THIS(digest)->ctx), data, size);
}
static
@@ -80,7 +93,8 @@
FoilDigest* digest,
void* md)
{
- FoilOpensslDigestSHA1* self = FOIL_OPENSSL_DIGEST_SHA1(digest);
+ FoilOpensslDigestSHA1* self = THIS(digest);
+
if (G_LIKELY(md)) {
SHA1_Final(md, &self->ctx);
} else {
@@ -113,6 +127,7 @@
{
GASSERT(klass->size == SHA_DIGEST_LENGTH);
klass->fn_copy = foil_openssl_digest_sha1_copy;
+ klass->fn_reset = foil_openssl_digest_sha1_reset;
klass->fn_digest = foil_openssl_digest_sha1_digest;
klass->fn_update = foil_openssl_digest_sha1_update;
klass->fn_finish = foil_openssl_digest_sha1_finish;
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/libfoil/src/openssl/foil_openssl_digest_sha256.c
^
|
@@ -1,26 +1,31 @@
/*
- * Copyright (C) 2016-2018 by Slava Monich
+ * Copyright (C) 2016-2022 by Slava Monich
*
* 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.
+ * 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 ``AS IS'' AND ANY EXPRESSED 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 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) ARISING
- * IN ANY WAY OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN
- * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 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.
*
* The views and conclusions contained in the software and documentation
* are those of the authors and should not be interpreted as representing
@@ -41,15 +46,18 @@
SHA256_CTX ctx;
} FoilOpensslDigestSHA256;
+#define THIS_TYPE foil_openssl_digest_sha256_get_type()
+#define THIS(obj) G_TYPE_CHECK_INSTANCE_CAST(obj, THIS_TYPE, \
+ FoilOpensslDigestSHA256)
+
+GType THIS_TYPE FOIL_INTERNAL;
G_DEFINE_TYPE(FoilOpensslDigestSHA256, foil_openssl_digest_sha256, \
- FOIL_TYPE_DIGEST_SHA256)
-#define FOIL_OPENSSL_DIGEST_SHA256(obj) (G_TYPE_CHECK_INSTANCE_CAST(obj, \
- FOIL_DIGEST_SHA256, FoilOpensslDigestSHA256))
+ FOIL_TYPE_DIGEST_SHA256)
GType
foil_impl_digest_sha256_get_type()
{
- return foil_openssl_digest_sha256_get_type();
+ return THIS_TYPE;
}
static
@@ -58,9 +66,15 @@
FoilDigest* digest,
FoilDigest* source)
{
- FoilOpensslDigestSHA256* self = FOIL_OPENSSL_DIGEST_SHA256(digest);
- FoilOpensslDigestSHA256* other = FOIL_OPENSSL_DIGEST_SHA256(source);
- self->ctx = other->ctx;
+ THIS(digest)->ctx = THIS(source)->ctx;
+}
+
+static
+void
+foil_openssl_digest_sha256_reset(
+ FoilDigest* digest)
+{
+ SHA256_Init(&(THIS(digest)->ctx));
}
static
@@ -70,8 +84,7 @@
const void* data,
size_t size)
{
- FoilOpensslDigestSHA256* self = FOIL_OPENSSL_DIGEST_SHA256(digest);
- SHA256_Update(&self->ctx, data, size);
+ SHA256_Update(&(THIS(digest)->ctx), data, size);
}
static
@@ -80,7 +93,8 @@
FoilDigest* digest,
void* md)
{
- FoilOpensslDigestSHA256* self = FOIL_OPENSSL_DIGEST_SHA256(digest);
+ FoilOpensslDigestSHA256* self = THIS(digest);
+
if (G_LIKELY(md)) {
SHA256_Final(md, &self->ctx);
} else {
@@ -113,6 +127,7 @@
{
GASSERT(klass->size == SHA256_DIGEST_LENGTH);
klass->fn_copy = foil_openssl_digest_sha256_copy;
+ klass->fn_reset = foil_openssl_digest_sha256_reset;
klass->fn_digest = foil_openssl_digest_sha256_digest;
klass->fn_update = foil_openssl_digest_sha256_update;
klass->fn_finish = foil_openssl_digest_sha256_finish;
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/libfoil/src/openssl/foil_openssl_digest_sha512.c
^
|
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2021 by Slava Monich
+ * Copyright (C) 2021-2022 by Slava Monich
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -44,15 +44,18 @@
SHA512_CTX ctx;
} FoilOpensslDigestSHA512;
+#define THIS_TYPE foil_openssl_digest_sha512_get_type()
+#define THIS(obj) (G_TYPE_CHECK_INSTANCE_CAST(obj, THIS_TYPE, \
+ FoilOpensslDigestSHA512))
+
+GType THIS_TYPE FOIL_INTERNAL;
G_DEFINE_TYPE(FoilOpensslDigestSHA512, foil_openssl_digest_sha512, \
- FOIL_TYPE_DIGEST_SHA512)
-#define FOIL_OPENSSL_DIGEST_SHA512(obj) (G_TYPE_CHECK_INSTANCE_CAST(obj, \
- FOIL_DIGEST_SHA512, FoilOpensslDigestSHA512))
+ FOIL_TYPE_DIGEST_SHA512)
GType
foil_impl_digest_sha512_get_type()
{
- return foil_openssl_digest_sha512_get_type();
+ return THIS_TYPE;
}
static
@@ -61,9 +64,15 @@
FoilDigest* digest,
FoilDigest* source)
{
- FoilOpensslDigestSHA512* self = FOIL_OPENSSL_DIGEST_SHA512(digest);
- FoilOpensslDigestSHA512* other = FOIL_OPENSSL_DIGEST_SHA512(source);
- self->ctx = other->ctx;
+ THIS(digest)->ctx = THIS(source)->ctx;
+}
+
+static
+void
+foil_openssl_digest_sha512_reset(
+ FoilDigest* digest)
+{
+ SHA512_Init(&(THIS(digest)->ctx));
}
static
@@ -73,8 +82,7 @@
const void* data,
size_t size)
{
- FoilOpensslDigestSHA512* self = FOIL_OPENSSL_DIGEST_SHA512(digest);
- SHA512_Update(&self->ctx, data, size);
+ SHA512_Update(&(THIS(digest)->ctx), data, size);
}
static
@@ -83,7 +91,8 @@
FoilDigest* digest,
void* md)
{
- FoilOpensslDigestSHA512* self = FOIL_OPENSSL_DIGEST_SHA512(digest);
+ FoilOpensslDigestSHA512* self = THIS(digest);
+
if (G_LIKELY(md)) {
SHA512_Final(md, &self->ctx);
} else {
@@ -116,6 +125,7 @@
{
GASSERT(klass->size == SHA512_DIGEST_LENGTH);
klass->fn_copy = foil_openssl_digest_sha512_copy;
+ klass->fn_reset = foil_openssl_digest_sha512_reset;
klass->fn_digest = foil_openssl_digest_sha512_digest;
klass->fn_update = foil_openssl_digest_sha512_update;
klass->fn_finish = foil_openssl_digest_sha512_finish;
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/libfoil/src/openssl/foil_openssl_key_rsa_private.c
^
|
@@ -1,26 +1,31 @@
/*
- * Copyright (C) 2016-2019 by Slava Monich
+ * Copyright (C) 2016-2022 by Slava Monich
*
* 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.
+ * 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 ``AS IS'' AND ANY EXPRESSED 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 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) ARISING
- * IN ANY WAY OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN
- * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 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.
*
* The views and conclusions contained in the software and documentation
* are those of the authors and should not be interpreted as representing
@@ -34,6 +39,8 @@
#define GLOG_MODULE_NAME foil_log_key
#include "foil_log_p.h"
+#define FOIL_RSA_FIELD(rsa,x) foil_openssl_rsa_get_##x(rsa)
+
typedef FoilKeyRsaPrivateClass FoilOpensslKeyRsaPrivateClass;
G_DEFINE_TYPE(FoilOpensslKeyRsaPrivate, foil_openssl_key_rsa_private, \
FOIL_TYPE_KEY_RSA_PRIVATE);
@@ -49,14 +56,10 @@
FoilKeyRsaPrivate* key,
RSA* rsa)
{
- FOIL_RSA_KEY_SET_BN(rsa, n, key->data);
- FOIL_RSA_KEY_SET_BN(rsa, e, key->data);
- FOIL_RSA_KEY_SET_BN(rsa, d, key->data);
- FOIL_RSA_KEY_SET_BN(rsa, p, key->data);
- FOIL_RSA_KEY_SET_BN(rsa, q, key->data);
- FOIL_RSA_KEY_SET_BN(rsa, dmp1, key->data);
- FOIL_RSA_KEY_SET_BN(rsa, dmq1, key->data);
- FOIL_RSA_KEY_SET_BN(rsa, iqmp, key->data);
+ const FoilKeyRsaPrivateData* data = key->data;
+ foil_openssl_rsa_set_key(rsa, &data->n, &data->e, &data->d);
+ foil_openssl_rsa_set_factors(rsa, &data->p, &data->q);
+ foil_openssl_rsa_set_params(rsa, &data->dmp1, &data->dmq1, &data->iqmp);
}
static
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/libfoil/src/openssl/foil_openssl_key_rsa_public.c
^
|
@@ -1,26 +1,31 @@
/*
- * Copyright (C) 2016-2019 by Slava Monich
+ * Copyright (C) 2016-2022 by Slava Monich
*
* 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.
+ * 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 ``AS IS'' AND ANY EXPRESSED 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 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) ARISING
- * IN ANY WAY OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN
- * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 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.
*
* The views and conclusions contained in the software and documentation
* are those of the authors and should not be interpreted as representing
@@ -40,8 +45,8 @@
FoilKeyRsaPublic* key,
RSA* rsa)
{
- FOIL_RSA_KEY_SET_BN(rsa, n, key->data);
- FOIL_RSA_KEY_SET_BN(rsa, e, key->data);
+ const FoilKeyRsaPublicData* data = key->data;
+ foil_openssl_rsa_set_key(rsa, &data->n, &data->e, NULL);
}
/*
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/libfoil/src/openssl/foil_openssl_random.h
^
|
@@ -1,26 +1,31 @@
/*
- * Copyright (C) 2016-2018 by Slava Monich
+ * Copyright (C) 2016-2022 by Slava Monich
*
* 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.
+ * 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 ``AS IS'' AND ANY EXPRESSED 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 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) ARISING
- * IN ANY WAY OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN
- * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 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.
*
* The views and conclusions contained in the software and documentation
* are those of the authors and should not be interpreted as representing
@@ -30,13 +35,14 @@
#ifndef FOIL_OPENSSL_RANDOM_H
#define FOIL_OPENSSL_RANDOM_H
-#include "foil_types.h"
+#include "foil_types_p.h"
#include <glib-object.h>
GType
foil_openssl_random_get_type(
- void);
+ void)
+ FOIL_INTERNAL;
#endif /* FOIL_OPENSSL_RANDOM_H */
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/libfoil/src/openssl/foil_openssl_rsa.c
^
|
@@ -1,26 +1,31 @@
/*
- * Copyright (C) 2016-2019 by Slava Monich
+ * Copyright (C) 2016-2022 by Slava Monich
*
* 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.
+ * 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 ``AS IS'' AND ANY EXPRESSED 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 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) ARISING
- * IN ANY WAY OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN
- * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 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.
*
* The views and conclusions contained in the software and documentation
* are those of the authors and should not be interpreted as representing
@@ -30,16 +35,17 @@
#include "foil_openssl_rsa.h"
/*
- * Originally, struct rsa_st was public then it was made opaque then it
- * started to mutate. Binary compatibility - what's that? Never heard of it!
+ * In OpenSSL 1.0 struct rsa_st was public and there were no RSA_get0_xxx
+ * and RSA_set0_xxx accessors. We use the accessors when they are* available,
+ * and only if they are not there, access the fields directly (which hopefully
+ * means that we are linked against OpenSSL 1.0)
*/
-#if GLIB_SIZEOF_LONG != 4
-typedef struct rsa_st_v1 {
+typedef struct rsa_st_1_0 {
int pad;
long version;
- const RSA_METHOD* meth;
- ENGINE* engine;
+ void* meth;
+ void* engine;
BIGNUM* n;
BIGNUM* e;
BIGNUM* d;
@@ -48,266 +54,227 @@
BIGNUM* dmp1;
BIGNUM* dmq1;
BIGNUM* iqmp;
-} RSA_V1;
-# define CHECK_RSA_V1
-#else
-# undef CHECK_RSA_V1
-#endif
+} RSA_1_0;
-typedef struct rsa_st_v2 {
- int pad;
- guint32 version;
- const RSA_METHOD* meth;
- ENGINE* engine;
- BIGNUM* n;
- BIGNUM* e;
- BIGNUM* d;
- BIGNUM* p;
- BIGNUM* q;
- BIGNUM* dmp1;
- BIGNUM* dmq1;
- BIGNUM* iqmp;
-} RSA_V2;
-
-#ifdef CHECK_RSA_V1
-static
-RSA_V1*
-foil_openssl_rsa_v1(
- const RSA* rsa)
-{
- RSA_V1* v1 = (void*)rsa;
- return (!v1->version && v1->meth && !v1->engine) ? v1 : NULL;
-}
-#endif /* CHECK_RSA_V1 */
-
-static
-RSA_V2*
-foil_openssl_rsa_v2(
- const RSA* rsa)
-{
- RSA_V2* v2 = (void*)rsa;
- return (!v2->version && v2->meth && !v2->engine) ? v2 : NULL;
-}
-
-#ifdef CHECK_RSA_V1
-# define FOIL_RSA_GET_FIELD_PTR(rsa,x) \
- RSA_V1* v1 = foil_openssl_rsa_v1(rsa); \
- if (v1) { \
- return &v1->x; \
- } else { \
- RSA_V2* v2 = foil_openssl_rsa_v2(rsa); \
- if (v2) return &v2->x; \
- } \
- return NULL
-#else
-# define FOIL_RSA_GET_FIELD_PTR(rsa,x) \
- RSA_V2* v2 = foil_openssl_rsa_v2(rsa); \
- return v2 ? &v2->x : NULL
-#endif
-
-static
-BIGNUM**
-foil_openssl_rsa_get_n_ptr(
- const RSA* rsa)
-{
- FOIL_RSA_GET_FIELD_PTR(rsa,n);
-}
-
-static
-BIGNUM**
-foil_openssl_rsa_get_e_ptr(
- const RSA* rsa)
-{
- FOIL_RSA_GET_FIELD_PTR(rsa,e);
-}
-
-static
-BIGNUM**
-foil_openssl_rsa_get_d_ptr(
- const RSA* rsa)
-{
- FOIL_RSA_GET_FIELD_PTR(rsa,d);
-}
-
-static
-BIGNUM**
-foil_openssl_rsa_get_p_ptr(
- const RSA* rsa)
-{
- FOIL_RSA_GET_FIELD_PTR(rsa,p);
-}
-
-static
-BIGNUM**
-foil_openssl_rsa_get_q_ptr(
- const RSA* rsa)
-{
- FOIL_RSA_GET_FIELD_PTR(rsa,q);
-}
+#define FOIL_WEAK_FN __attribute__((weak))
-static
-BIGNUM**
-foil_openssl_rsa_get_dmp1_ptr(
- const RSA* rsa)
-{
- FOIL_RSA_GET_FIELD_PTR(rsa,dmp1);
-}
-
-static
-BIGNUM**
-foil_openssl_rsa_get_dmq1_ptr(
- const RSA* rsa)
-{
- FOIL_RSA_GET_FIELD_PTR(rsa,dmq1);
-}
-
-static
-BIGNUM**
-foil_openssl_rsa_get_iqmp_ptr(
- const RSA* rsa)
-{
- FOIL_RSA_GET_FIELD_PTR(rsa,iqmp);
-}
+void
+RSA_get0_key(
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/libfoil/src/openssl/foil_openssl_rsa.h
^
|
@@ -1,26 +1,31 @@
/*
- * Copyright (C) 2016-2019 by Slava Monich
+ * Copyright (C) 2016-2022 by Slava Monich
*
* 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.
+ * 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 ``AS IS'' AND ANY EXPRESSED 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 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) ARISING
- * IN ANY WAY OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN
- * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 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.
*
* The views and conclusions contained in the software and documentation
* are those of the authors and should not be interpreted as representing
@@ -34,116 +39,131 @@
#include "foil_key_rsa_public.h"
#include "foil_key_rsa_private.h"
+/*
+ * Accessors (if present at all) may have slightly different
+ * prototypes, with different const qualifiers.
+ */
+#define RSA_set0_key RSA_set0_key_
+#define RSA_set0_factors RSA_set0_factors_
+#define RSA_set0_crt_params RSA_set0_crt_params_
+#define RSA_get0_key RSA_get0_key_
+#define RSA_get0_factors RSA_get0_factors_
+#define RSA_get0_crt_params RSA_get0_crt_params_
+#define OPENSSL_SUPPRESS_DEPRECATED
+
#include <openssl/rsa.h>
#include <openssl/err.h>
+#undef RSA_set0_key
+#undef RSA_set0_factors
+#undef RSA_set0_crt_params
+#undef RSA_get0_key
+#undef RSA_get0_factors
+#undef RSA_get0_crt_params
+
+#if OPENSSL_API_LEVEL >= 30000
+# define RSA_CONST_PTR_3 const RSA*
+#else
+# define RSA_CONST_PTR_3 RSA*
+#endif
+
typedef FoilCipherClass FoilOpensslCipherRsaClass;
typedef struct foil_openssl_cipher_rsa {
FoilCipherSync sync;
int padding_size;
int padding;
RSA* rsa;
- RSA* (*dup)(RSA *rsa);
- int (*proc)(int flen, const unsigned char *from,
- unsigned char *to, RSA *rsa, int padding);
+ RSA* (*dup)(RSA_CONST_PTR_3 rsa);
+ int (*proc)(int flen, const unsigned char* from,
+ unsigned char* to, RSA* rsa, int padding);
} FoilOpensslCipherRsa;
-GType foil_openssl_cipher_rsa_get_type(void);
+GType foil_openssl_cipher_rsa_get_type(void) FOIL_INTERNAL;
#define FOIL_OPENSSL_TYPE_CIPHER_RSA foil_openssl_cipher_rsa_get_type()
typedef FoilKeyRsaPrivate FoilOpensslKeyRsaPrivate;
-GType foil_openssl_key_rsa_private_get_type(void);
+GType foil_openssl_key_rsa_private_get_type(void) FOIL_INTERNAL;
#define FOIL_OPENSSL_TYPE_KEY_RSA_PRIVATE \
foil_openssl_key_rsa_private_get_type()
void
foil_openssl_key_rsa_private_apply(
FoilKeyRsaPrivate* priv,
- RSA* rsa);
+ RSA* rsa)
+ FOIL_INTERNAL;
void
foil_openssl_key_rsa_public_apply(
FoilKeyRsaPublic* pub,
- RSA* rsa);
+ RSA* rsa)
+ FOIL_INTERNAL;
/* Getters for RSA fields */
const BIGNUM*
foil_openssl_rsa_get_n(
- const RSA* rsa);
+ const RSA* rsa)
+ FOIL_INTERNAL;
const BIGNUM*
foil_openssl_rsa_get_e(
- const RSA* rsa);
+ const RSA* rsa)
+ FOIL_INTERNAL;
const BIGNUM*
foil_openssl_rsa_get_d(
- const RSA* rsa);
+ const RSA* rsa)
+ FOIL_INTERNAL;
const BIGNUM*
foil_openssl_rsa_get_p(
- const RSA* rsa);
+ const RSA* rsa)
+ FOIL_INTERNAL;
const BIGNUM*
foil_openssl_rsa_get_q(
- const RSA* rsa);
+ const RSA* rsa)
+ FOIL_INTERNAL;
const BIGNUM*
foil_openssl_rsa_get_dmp1(
- const RSA* rsa);
+ const RSA* rsa)
+ FOIL_INTERNAL;
const BIGNUM*
foil_openssl_rsa_get_dmq1(
- const RSA* rsa);
+ const RSA* rsa)
+ FOIL_INTERNAL;
const BIGNUM*
foil_openssl_rsa_get_iqmp(
- const RSA* rsa);
+ const RSA* rsa)
+ FOIL_INTERNAL;
/* Setters for RSA fields */
-const BIGNUM*
-foil_openssl_rsa_set_n(
- RSA* rsa,
- const FoilBytes* bytes);
-
-const BIGNUM*
-foil_openssl_rsa_set_e(
- RSA* rsa,
- const FoilBytes* bytes);
-
-const BIGNUM*
-foil_openssl_rsa_set_d(
- RSA* rsa,
- const FoilBytes* bytes);
-
-const BIGNUM*
-foil_openssl_rsa_set_p(
- RSA* rsa,
- const FoilBytes* bytes);
-
-const BIGNUM*
-foil_openssl_rsa_set_q(
- RSA* rsa,
- const FoilBytes* bytes);
-
-const BIGNUM*
-foil_openssl_rsa_set_dmp1(
+void
+foil_openssl_rsa_set_key(
RSA* rsa,
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/rpm/foil.spec
^
|
@@ -1,5 +1,6 @@
Name: libfoil
-Version: 1.0.23
+
+Version: 1.0.27
Release: 0
Summary: Yet another glib-style crypto API
Group: Development/Libraries
@@ -46,8 +47,8 @@
%setup -q
%build
-make -C libfoil LIBDIR=%{_libdir} KEEP_SYMBOLS=1 release pkgconfig
-make -C tools LIBDIR=%{_libdir} KEEP_SYMBOLS=1 release
+make -C libfoil %{_smp_mflags} LIBDIR=%{_libdir} KEEP_SYMBOLS=1 release pkgconfig
+make -C tools %{_smp_mflags} LIBDIR=%{_libdir} KEEP_SYMBOLS=1 release
%install
rm -rf %{buildroot}
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/test/common/Makefile
^
|
@@ -15,6 +15,8 @@
SRC = $(EXE).c
endif
+COMMON_SRC ?= test_main.c
+
#
# Required packages
#
@@ -127,9 +129,21 @@
endif
endif
-$(DEBUG_OBJS): | $(DEBUG_BUILD_DIR)
-$(RELEASE_OBJS): | $(RELEASE_BUILD_DIR)
-$(COVERAGE_OBJS): | $(COVERAGE_BUILD_DIR)
+DEBUG_DEPS += $(DEBUG_LIB)
+RELEASE_DEPS += $(RELEASE_LIB)
+COVERAGE_DEPS += $(COVERAGE_LIB)
+
+DEBUG_ORDER_DEPS += libfoil-debug
+RELEASE_ORDER_DEPS += libfoil-release
+COVERAGE_ORDER_DEPS += libfoil-coverage
+
+$(DEBUG_LIB): | libfoil-debug
+$(RELEASE_LIB): | libfoil-release
+$(COVERAGE_LIB): | libfoil-coverage
+
+$(DEBUG_EXE) $(DEBUG_OBJS): | $(DEBUG_BUILD_DIR) $(DEBUG_ORDER_DEPS)
+$(RELEASE_EXE) $(RELEASE_OBJS): | $(RELEASE_BUILD_DIR) $(RELEASE_ORDER_DEPS)
+$(COVERAGE_EXE) $(COVERAGE_OBJS): | $(COVERAGE_BUILD_DIR) $(COVERAGE_ORDER_DEPS)
#
# Rules
@@ -139,15 +153,11 @@
RELEASE_EXE = $(RELEASE_BUILD_DIR)/$(EXE)
COVERAGE_EXE = $(COVERAGE_BUILD_DIR)/$(EXE)
-DEBUG_DEPS += libfoil-debug $(DEBUG_EXE)
-RELEASE_DEPS += libfoil-release $(RELEASE_EXE)
-COVERAGE_DEPS += libfoil-coverage $(COVERAGE_EXE)
-
-debug: $(DEBUG_DEPS)
+debug: $(DEBUG_EXE)
-release: $(RELEASE_DEPS)
+release: $(RELEASE_EXE)
-coverage: $(COVERAGE_DEPS)
+coverage: $(COVERAGE_EXE)
clean:
rm -f *~
@@ -165,6 +175,15 @@
valgrind: test_banner debug
@G_DEBUG=gc-friendly G_SLICE=always-malloc valgrind --tool=memcheck --leak-check=full --show-possibly-lost=no $(DEBUG_EXE)
+libfoil-debug:
+ @make $(SUBMAKE_OPTS) -C $(LIB_DIR) debug
+
+libfoil-release:
+ @make $(SUBMAKE_OPTS) -C $(LIB_DIR) release
+
+libfoil-coverage:
+ @make $(SUBMAKE_OPTS) -C $(LIB_DIR) coverage
+
$(DEBUG_BUILD_DIR):
mkdir -p $@
@@ -214,23 +233,14 @@
$(CC) -c $(COVERAGE_CFLAGS) -MT"$@" -MF"$(@:%.o=%.d)" $< -o $@
endif
-$(DEBUG_EXE): $(DEBUG_LIB) $(DEBUG_BUILD_DIR) $(DEBUG_OBJS)
+$(DEBUG_EXE): $(DEBUG_BUILD_DIR) $(DEBUG_OBJS) $(DEBUG_DEPS)
$(LD) $(DEBUG_LDFLAGS) $(DEBUG_OBJS) $(DEBUG_LIBS) -o $@
-$(RELEASE_EXE): $(RELEASE_LIB) $(RELEASE_BUILD_DIR) $(RELEASE_OBJS)
+$(RELEASE_EXE): $(RELEASE_BUILD_DIR) $(RELEASE_OBJS) $(RELEASE_DEPS)
$(LD) $(RELEASE_LDFLAGS) $(RELEASE_OBJS) $(RELEASE_LIBS) -o $@
ifeq ($(KEEP_SYMBOLS),0)
strip $@
endif
-$(COVERAGE_EXE): $(COVERAGE_LIB) $(COVERAGE_BUILD_DIR) $(COVERAGE_OBJS)
+$(COVERAGE_EXE): $(COVERAGE_BUILD_DIR) $(COVERAGE_OBJS) $(COVERAGE_DEPS)
$(LD) $(COVERAGE_LDFLAGS) $(COVERAGE_OBJS) $(COVERAGE_LIBS) -o $@
-
-libfoil-debug:
- @make $(SUBMAKE_OPTS) -C $(LIB_DIR) debug
-
-libfoil-release:
- @make $(SUBMAKE_OPTS) -C $(LIB_DIR) release
-
-libfoil-coverage:
- @make $(SUBMAKE_OPTS) -C $(LIB_DIR) coverage
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/test/common/Makefile.foilmsg
^
|
@@ -6,17 +6,27 @@
LIBFOILMSG_DIR ?= ../../../libfoilmsg
+INCLUDES += -I$(LIBFOILMSG_DIR)/include -I$(LIBFOILMSG_DIR)/src
+
+DEBUG_ORDER_DEPS += libfoilmsg-debug
+RELEASE_ORDER_DEPS += libfoilmsg-release
+COVERAGE_ORDER_DEPS += libfoilmsg-coverage
+
DEBUG_LIBFOILMSG_FILE := $(shell $(QUIET_MAKE) -C $(LIBFOILMSG_DIR) print_debug_lib)
RELEASE_LIBFOILMSG_FILE := $(shell $(QUIET_MAKE) -C $(LIBFOILMSG_DIR) print_release_lib)
COVERAGE_LIBFOILMSG_FILE := $(shell $(QUIET_MAKE) -C $(LIBFOILMSG_DIR) print_coverage_lib)
-INCLUDES += -I$(LIBFOILMSG_DIR)/include -I$(LIBFOILMSG_DIR)/src
-DEBUG_LIBS += $(LIBFOILMSG_DIR)/$(DEBUG_LIBFOILMSG_FILE)
-RELEASE_LIBS += $(LIBFOILMSG_DIR)/$(RELEASE_LIBFOILMSG_FILE)
-COVERAGE_LIBS += $(LIBFOILMSG_DIR)/$(COVERAGE_LIBFOILMSG_FILE)
-DEBUG_DEPS += libfoilmsg-debug
-RELEASE_DEPS += libfoilmsg-release
-COVERAGE_DEPS += libfoilmsg-coverage
+DEBUG_FOILMSG_LIB += $(LIBFOILMSG_DIR)/$(DEBUG_LIBFOILMSG_FILE)
+RELEASE_FOILMSG_LIB += $(LIBFOILMSG_DIR)/$(RELEASE_LIBFOILMSG_FILE)
+COVERAGE_FOILMSG_LIB += $(LIBFOILMSG_DIR)/$(COVERAGE_LIBFOILMSG_FILE)
+
+DEBUG_LIBS += $(DEBUG_FOILMSG_LIB)
+RELEASE_LIBS += $(RELEASE_FOILMSG_LIB)
+COVERAGE_LIBS += $(COVERAGE_FOILMSG_LIB)
+
+DEBUG_DEPS += $(DEBUG_FOILMSG_LIB)
+RELEASE_DEPS += $(RELEASE_FOILMSG_LIB)
+COVERAGE_DEPS += $(COVERAGE_FOILMSG_LIB)
include $(COMMON_DIR)/Makefile
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/test/common/test_common.h
^
|
@@ -1,26 +1,31 @@
/*
- * Copyright (C) 2016-2018 by Slava Monich
+ * Copyright (C) 2016-2022 by Slava Monich
*
* 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.
+ * 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 ``AS IS'' AND ANY EXPRESSED 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 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) ARISING
- * IN ANY WAY OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN
- * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 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.
*
* The views and conclusions contained in the software and documentation
* are those of the authors and should not be interpreted as representing
@@ -44,11 +49,6 @@
test_run(
void);
-GBytes*
-test_bytes_concat(
- GBytes* bytes1,
- GBytes* bytes2);
-
gboolean
test_bytes_equal(
GBytes* bytes,
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/test/common/test_main.c
^
|
@@ -1,26 +1,31 @@
/*
- * Copyright (C) 2016-2017 by Slava Monich
+ * Copyright (C) 2016-2022 by Slava Monich
*
* 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.
+ * 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 ``AS IS'' AND ANY EXPRESSED 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 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) ARISING
- * IN ANY WAY OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN
- * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 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.
*
* The views and conclusions contained in the software and documentation
* are those of the authors and should not be interpreted as representing
@@ -48,34 +53,6 @@
return test_bytes_equal(bytes, str, strlen(str));
}
-GBytes*
-test_bytes_concat(
- GBytes* bytes1,
- GBytes* bytes2)
-{
- guint8* data;
- guint8* ptr;
- gsize size = 0;
- if (bytes1) {
- size += g_bytes_get_size(bytes1);
- }
- if (bytes2) {
- size += g_bytes_get_size(bytes2);
- }
- ptr = data = g_malloc(size);
- if (bytes1) {
- const gsize nbytes = g_bytes_get_size(bytes1);
- memcpy(ptr, g_bytes_get_data(bytes1, NULL), nbytes);
- ptr += nbytes;
- }
- if (bytes2) {
- const gsize nbytes = g_bytes_get_size(bytes2);
- memcpy(ptr, g_bytes_get_data(bytes2, NULL), nbytes);
- ptr += nbytes;
- }
- return g_bytes_new_take(data, size);
-}
-
int
test_run(
void)
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/test/coverage/run
^
|
@@ -16,6 +16,7 @@
test_digest \
test_hmac \
test_input \
+test_kdf \
test_key_aes \
test_key_des \
test_key_rsa \
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/test/libfoil/Makefile
^
|
@@ -14,6 +14,7 @@
@$(MAKE) -C test_digest $*
@$(MAKE) -C test_hmac $*
@$(MAKE) -C test_input $*
+ @$(MAKE) -C test_kdf $*
@$(MAKE) -C test_key_aes $*
@$(MAKE) -C test_key_des $*
@$(MAKE) -C test_key_rsa $*
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/test/libfoil/test_cavp_aes/test_cavp_aes.c
^
|
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016-2021 by Slava Monich
+ * Copyright (C) 2016-2022 by Slava Monich
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -246,7 +246,7 @@
test_cavp_aes_key(
const Test* test)
{
- GBytes* key_bytes = test_bytes_concat(test->key, test->iv);
+ GBytes* key_bytes = gutil_bytes_concat(test->key, test->iv, NULL);
GType key_type;
FoilKey* key;
switch (g_bytes_get_size(test->key)*8) {
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/test/libfoil/test_cavp_cmac/test_cavp_cmac.c
^
|
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2019 by Slava Monich
+ * Copyright (C) 2019-2022 by Slava Monich <slava@monich.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -265,7 +265,7 @@
test.Key3 = test_bytes_truncate(test.Key3, FOIL_DES_KEY_SIZE);
test.Msg = test_bytes_truncate(test.Msg, test.Mlen);
test.Mac = test_bytes_truncate(test.Mac, test.Tlen);
- tests = g_slist_append(tests, g_memdup(&test, sizeof(test)));
+ tests = g_slist_append(tests, gutil_memdup(&test, sizeof(test)));
memset(&test, 0, sizeof(test));
flags = 0;
}
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/test/libfoil/test_cipher/Makefile
^
|
@@ -1,6 +1,5 @@
# -*- Mode: makefile-gmake -*-
EXE = test_cipher
-COMMON_SRC = test_main.c
include ../../common/Makefile
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/test/libfoil/test_cmac/Makefile
^
|
@@ -1,6 +1,5 @@
# -*- Mode: makefile-gmake -*-
EXE = test_cmac
-COMMON_SRC = test_main.c
include ../../common/Makefile
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/test/libfoil/test_digest/Makefile
^
|
@@ -1,6 +1,5 @@
# -*- Mode: makefile-gmake -*-
EXE = test_digest
-COMMON_SRC = test_main.c
include ../../common/Makefile
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/test/libfoil/test_digest/test_digest.c
^
|
@@ -1,29 +1,31 @@
/*
- * Copyright (C) 2016-2021 by Slava Monich
+ * Copyright (C) 2016-2022 by Slava Monich <slava@monich.com>
*
* 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.
+ * 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 ``AS IS'' AND ANY EXPRESSED 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 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) ARISING
- * IN ANY WAY OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN
- * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 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.
*
* The views and conclusions contained in the software and documentation
* are those of the authors and should not be interpreted as representing
@@ -34,6 +36,8 @@
#include "foil_digest_p.h"
+#include <gutil_misc.h>
+
typedef struct test_digest {
const char* name;
GTestDataFunc fn;
@@ -44,6 +48,30 @@
guint output_size;
} TestDigest;
+/* Empty digests */
+#define empty_md5_data test_md5_data1
+static const guint8 empty_sha1_data[] = {
+ 0xda,0x39,0xa3,0xee,0x5e,0x6b,0x4b,0x0d,
+ 0x32,0x55,0xbf,0xef,0x95,0x60,0x18,0x90,
+ 0xaf,0xd8,0x07,0x09
+};
+static const guint8 empty_sha256_data[] = {
+ 0xe3,0xb0,0xc4,0x42,0x98,0xfc,0x1c,0x14,
+ 0x9a,0xfb,0xf4,0xc8,0x99,0x6f,0xb9,0x24,
+ 0x27,0xae,0x41,0xe4,0x64,0x9b,0x93,0x4c,
+ 0xa4,0x95,0x99,0x1b,0x78,0x52,0xb8,0x55
+};
+static const guint8 empty_sha512_data[] = {
+ 0xcf,0x83,0xe1,0x35,0x7e,0xef,0xb8,0xbd,
+ 0xf1,0x54,0x28,0x50,0xd6,0x6d,0x80,0x07,
+ 0xd6,0x20,0xe4,0x05,0x0b,0x57,0x15,0xdc,
+ 0x83,0xf4,0xa9,0x21,0xd3,0x6c,0xe9,0xce,
+ 0x47,0xd0,0xd1,0x3c,0x5d,0x85,0xf2,0xb0,
+ 0xff,0x83,0x18,0xd2,0x87,0x7e,0xec,0x2f,
+ 0x63,0xb9,0x31,0xbd,0x47,0x41,0x7a,0x81,
+ 0xa5,0x38,0x32,0x7a,0xf9,0x27,0xda,0x3e
+};
+
/* MD5 examples from http://www.ietf.org/rfc/rfc1321 */
#define MD5_TEST1 ""
@@ -220,11 +248,14 @@
static const guchar data[1] = { 1 };
GBytes* bytes = g_bytes_new_static(data, sizeof(data));
FoilDigest* md5 = foil_digest_new_md5();
+ int tmp;
+
g_assert(!foil_digest_type_size(0));
g_assert(!foil_digest_type_block_size(0));
g_assert(!foil_digest_type_name(0));
g_assert(!foil_digest_new(0));
g_assert(!foil_digest_clone(NULL));
+ g_assert(!foil_digest_reset(NULL));
g_assert(!foil_digest_ref(NULL));
g_assert(!foil_digest_size(NULL));
g_assert(!foil_digest_block_size(NULL));
@@ -236,6 +267,9 @@
g_assert(!foil_digest_data(0, NULL, sizeof(data)));
g_assert(!foil_digest_data(0, data, sizeof(data)));
g_assert(!foil_digest_data(0, data, 0));
+ g_assert(!foil_digest_data_buf(G_TYPE_OBJECT, NULL, 0, NULL));
+ g_assert(!foil_digest_data_buf(G_TYPE_OBJECT, NULL, 0, &tmp));
+ g_assert(!foil_digest_data_buf(FOIL_DIGEST_MD5, NULL, 0, NULL));
g_assert(!foil_digest_bytes(0, NULL));
g_assert(!foil_digest_bytes(0, bytes));
g_assert(!foil_digest_type_block_size(FOIL_TYPE_DIGEST));
@@ -250,6 +284,7 @@
foil_digest_update_bytes(NULL, bytes);
foil_digest_unref(NULL);
g_bytes_unref(bytes);
+ foil_digest_reset(md5);
foil_digest_unref(md5);
}
@@ -260,15 +295,19 @@
{
FoilDigest* d1 = foil_digest_new_md5();
FoilDigest* d2;
+ GBytes* md5_in = g_bytes_new_static(MD5_TEST2, strlen(MD5_TEST2));
GBytes* b1;
GBytes* b2;
/* Clone unfinished digest */
- foil_digest_update(d1, MD5_TEST2, strlen(MD5_TEST2));
+ g_assert(foil_digest_update_bytes(d1, md5_in));
d2 = foil_digest_clone(d1);
b1 = foil_digest_finish(d1);
b2 = foil_digest_finish(d2);
+ /* Finished digest is not updated */
+ g_assert(!foil_digest_update_bytes(d1, md5_in));
+
g_assert(g_bytes_equal(b1, b2));
g_assert(g_bytes_get_size(b1) == sizeof(test_md5_data2));
g_assert(!memcmp(g_bytes_get_data(b1, NULL), test_md5_data2,
@@ -279,9 +318,12 @@
/* Clone finished digest */
d1 = foil_digest_new_sha1();
- foil_digest_update(d1, SHA1_TEST1, strlen(SHA1_TEST1));
+ g_assert(foil_digest_update(d1, SHA1_TEST1, strlen(SHA1_TEST1)));
b1 = foil_digest_finish(d1);
+ /* Finished digest is not updated */
+ g_assert(!foil_digest_update(d1, SHA1_TEST1, strlen(SHA1_TEST1)));
+
d2 = foil_digest_clone(d1);
b2 = foil_digest_finish(d2);
@@ -292,6 +334,7 @@
foil_digest_unref(d1);
foil_digest_unref(d2);
+ g_bytes_unref(md5_in);
}
static
@@ -372,6 +415,39 @@
static
void
+test_reset(
+ gconstpointer param)
+{
+ const TestDigest* test = param;
+ const size_t input_len = strlen(test->input);
+ GType type = test->digest_type();
+ FoilDigest* digest = foil_digest_new(type);
+ GBytes* b1;
+ GBytes* b2;
+ int i;
+
+ for (i = 0; i < test->repeat_count; i++) {
+ foil_digest_update(digest, test->input, input_len);
+ }
+ b1 = g_bytes_ref(foil_digest_finish(digest));
+
+ g_assert(foil_digest_reset(digest));
+
+ for (i = 0; i < test->repeat_count; i++) {
+ foil_digest_update(digest, test->input, input_len);
+ }
+ b2 = foil_digest_finish(digest);
+
+ /* Results must be different but identical */
+ g_assert(b1 != b2);
+ g_assert(g_bytes_equal(b1, b2));
+
+ g_bytes_unref(b1);
+ foil_digest_unref(digest);
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/test/libfoil/test_hmac/Makefile
^
|
@@ -1,6 +1,5 @@
# -*- Mode: makefile-gmake -*-
EXE = test_hmac
-COMMON_SRC = test_main.c
include ../../common/Makefile
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/test/libfoil/test_hmac/test_hmac.c
^
|
@@ -1,26 +1,31 @@
/*
- * Copyright (C) 2018 by Slava Monich
+ * Copyright (C) 2018-2022 by Slava Monich <slava@monich.com>
*
* 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.
+ * 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 ``AS IS'' AND ANY EXPRESSED 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 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) ARISING
- * IN ANY WAY OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN
- * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 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.
*
* The views and conclusions contained in the software and documentation
* are those of the authors and should not be interpreted as representing
@@ -40,22 +45,57 @@
FoilBytes output;
} TestHmac;
+/* Empty HMACs */
+
+static const guint8 empty_md5_output[] = {
+ 0x74,0xe6,0xf7,0x29,0x8a,0x9c,0x2d,0x16,
+ 0x89,0x35,0xf5,0x8c,0x00,0x1b,0xad,0x88
+};
+
+static const guint8 empty_sha1_output[] = {
+ 0xfb,0xdb,0x1d,0x1b,0x18,0xaa,0x6c,0x08,
+ 0x32,0x4b,0x7d,0x64,0xb7,0x1f,0xb7,0x63,
+ 0x70,0x69,0x0e,0x1d
+};
+
+static const guint8 empty_sha256_output[] = {
+ 0xb6,0x13,0x67,0x9a,0x08,0x14,0xd9,0xec,
+ 0x77,0x2f,0x95,0xd7,0x78,0xc3,0x5f,0xc5,
+ 0xff,0x16,0x97,0xc4,0x93,0x71,0x56,0x53,
+ 0xc6,0xc7,0x12,0x14,0x42,0x92,0xc5,0xad
+};
+
+static const guint8 empty_sha512_output[] = {
+ 0xb9,0x36,0xce,0xe8,0x6c,0x9f,0x87,0xaa,
+ 0x5d,0x3c,0x6f,0x2e,0x84,0xcb,0x5a,0x42,
+ 0x39,0xa5,0xfe,0x50,0x48,0x0a,0x6e,0xc6,
+ 0x6b,0x70,0xab,0x5b,0x1f,0x4a,0xc6,0x73,
+ 0x0c,0x6c,0x51,0x54,0x21,0xb3,0x27,0xec,
+ 0x1d,0x69,0x40,0x2e,0x53,0xdf,0xb4,0x9a,
+ 0xd7,0x38,0x1e,0xb0,0x67,0xb3,0x38,0xfd,
+ 0x7b,0x0c,0xb2,0x22,0x47,0x22,0x5d,0x47,
+};
+
/*
* Test vectors from:
*
* https://tools.ietf.org/rfc/rfc2202.txt (MD-5, SHA-1)
* https://tools.ietf.org/rfc/rfc2202.txt (SHA-256)
+ * https://tools.ietf.org/rfc/rfc4231.txt (SHA512)
*/
-#define test1_sha256_key test1_sha1_key
+#define test1_sha1_key test1_sha_key
+#define test1_sha256_key test1_sha_key
+#define test1_sha512_key test1_sha_key
#define test1_md5_data test1_data
#define test1_sha1_data test1_data
#define test1_sha256_data test1_data
+#define test1_sha512_data test1_data
static const guint8 test1_md5_key[] = {
0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,
0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,0x0b
};
-static const guint8 test1_sha1_key[] = {
+static const guint8 test1_sha_key[] = {
0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,
0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,
0x0b,0x0b,0x0b,0x0b
@@ -78,13 +118,25 @@
0x88,0x1d,0xc2,0x00,0xc9,0x83,0x3d,0xa7,
0x26,0xe9,0x37,0x6c,0x2e,0x32,0xcf,0xf7
};
+static const guint8 test1_sha512_output[] = {
+ 0x87,0xaa,0x7c,0xde,0xa5,0xef,0x61,0x9d,
+ 0x4f,0xf0,0xb4,0x24,0x1a,0x1d,0x6c,0xb0,
+ 0x23,0x79,0xf4,0xe2,0xce,0x4e,0xc2,0x78,
+ 0x7a,0xd0,0xb3,0x05,0x45,0xe1,0x7c,0xde,
+ 0xda,0xa8,0x33,0xb7,0xd6,0xb8,0xa7,0x02,
+ 0x03,0x8b,0x27,0x4e,0xae,0xa3,0xf4,0xe4,
+ 0xbe,0x9d,0x91,0x4e,0xeb,0x61,0xf1,0x70,
+ 0x2e,0x69,0x6c,0x20,0x3a,0x12,0x68,0x54
+};
#define test2_md5_key test2_key
#define test2_sha1_key test2_key
#define test2_sha256_key test2_key
+#define test2_sha512_key test2_key
#define test2_md5_data test2_data
#define test2_sha1_data test2_data
#define test2_sha256_data test2_data
+#define test2_sha512_data test2_data
static const guint8 test2_key[] = {
'J', 'e', 'f', 'e'
};
@@ -109,16 +161,29 @@
0x5a,0x00,0x3f,0x08,0x9d,0x27,0x39,0x83,
0x9d,0xec,0x58,0xb9,0x64,0xec,0x38,0x43
};
+static const guint8 test2_sha512_output[] = {
+ 0x16,0x4b,0x7a,0x7b,0xfc,0xf8,0x19,0xe2,
+ 0xe3,0x95,0xfb,0xe7,0x3b,0x56,0xe0,0xa3,
+ 0x87,0xbd,0x64,0x22,0x2e,0x83,0x1f,0xd6,
+ 0x10,0x27,0x0c,0xd7,0xea,0x25,0x05,0x54,
+ 0x97,0x58,0xbf,0x75,0xc0,0x5a,0x99,0x4a,
+ 0x6d,0x03,0x4f,0x65,0xf8,0xf0,0xe6,0xfd,
+ 0xca,0xea,0xb1,0xa3,0x4d,0x4a,0x6b,0x4b,
+ 0x63,0x6e,0x07,0x0a,0x38,0xbc,0xe7,0x37
+};
-#define test3_sha256_key test3_sha1_key
+#define test3_sha1_key test3_sha_key
+#define test3_sha256_key test3_sha_key
+#define test3_sha512_key test3_sha_key
#define test3_md5_data test3_data
#define test3_sha1_data test3_data
#define test3_sha256_data test3_data
+#define test3_sha512_data test3_data
static const guint8 test3_md5_key[] = {
0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,
0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa
};
-static const guint8 test3_sha1_key[] = {
+static const guint8 test3_sha_key[] = {
0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,
0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,
0xaa,0xaa,0xaa,0xaa
@@ -147,13 +212,25 @@
0x29,0x59,0x09,0x8b,0x3e,0xf8,0xc1,0x22,
0xd9,0x63,0x55,0x14,0xce,0xd5,0x65,0xfe
};
+static const guint8 test3_sha512_output[] = {
+ 0xfa,0x73,0xb0,0x08,0x9d,0x56,0xa2,0x84,
+ 0xef,0xb0,0xf0,0x75,0x6c,0x89,0x0b,0xe9,
+ 0xb1,0xb5,0xdb,0xdd,0x8e,0xe8,0x1a,0x36,
+ 0x55,0xf8,0x3e,0x33,0xb2,0x27,0x9d,0x39,
+ 0xbf,0x3e,0x84,0x82,0x79,0xa7,0x22,0xc8,
+ 0x06,0xb4,0x85,0xa4,0x7e,0x67,0xc8,0x07,
+ 0xb9,0x46,0xa3,0x37,0xbe,0xe8,0x94,0x26,
+ 0x74,0x27,0x88,0x59,0xe1,0x32,0x92,0xfb
+};
#define test4_md5_key test4_key
#define test4_sha1_key test4_key
#define test4_sha256_key test4_key
+#define test4_sha512_key test4_key
#define test4_md5_data test4_data
#define test4_sha1_data test4_data
#define test4_sha256_data test4_data
+#define test4_sha512_data test4_data
static const guint8 test4_key[] = {
0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x10,
@@ -184,16 +261,29 @@
0x85,0xf0,0xfa,0xa3,0xe5,0x78,0xf8,0x07,
0x7a,0x2e,0x3f,0xf4,0x67,0x29,0x66,0x5b
};
+static const guint8 test4_sha512_output[] = {
+ 0xb0,0xba,0x46,0x56,0x37,0x45,0x8c,0x69,
+ 0x90,0xe5,0xa8,0xc5,0xf6,0x1d,0x4a,0xf7,
+ 0xe5,0x76,0xd9,0x7f,0xf9,0x4b,0x87,0x2d,
|
[-]
[+]
|
Added |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/test/libfoil/test_kdf/Makefile
^
|
@@ -0,0 +1,5 @@
+# -*- Mode: makefile-gmake -*-
+
+EXE = test_kdf
+
+include ../../common/Makefile
|
[-]
[+]
|
Added |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/test/libfoil/test_kdf/test_kdf.c
^
|
@@ -0,0 +1,235 @@
+/*
+ * Copyright (C) 2022 by Slava Monich
+ *
+ * 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.
+ *
+ * The views and conclusions contained in the software and documentation
+ * are those of the authors and should not be interpreted as representing
+ * any official policies, either expressed or implied.
+ */
+
+#include "test_common.h"
+
+#include "foil_kdf.h"
+#include "foil_digest.h"
+#include "foil_random.h"
+
+typedef struct test_kdf {
+ const char* name;
+ GType (*digest_type)(void);
+ const char* pw;
+ gssize pwlen;
+ FoilBytes salt;
+ guint iter;
+ guint dlen;
+ FoilBytes output;
+} TestKdf;
+
+static
+void
+test_null(
+ void)
+{
+ FoilBytes salt;
+
+ salt.val = (void*)&salt;
+ salt.len = sizeof(salt);
+ g_assert(!foil_kdf_pbkdf2((GType)0, NULL, 0, NULL, 0, 0));
+ /* Not a digest type: */
+ g_assert(!foil_kdf_pbkdf2(FOIL_RANDOM_DEFAULT, NULL, 0, &salt, 1, 0));
+ /* No iterations */
+ g_assert(!foil_kdf_pbkdf2(FOIL_DIGEST_SHA1, NULL, 0, &salt, 0, 0));
+ /* NULL password */
+ g_assert(!foil_kdf_pbkdf2(FOIL_DIGEST_SHA1, NULL, -1, &salt, 1, 0));
+}
+
+static
+void
+test_kdf(
+ gconstpointer param)
+{
+ const TestKdf* test = param;
+ GBytes* result = foil_kdf_pbkdf2(test->digest_type(), test->pw,
+ test->pwlen, &test->salt, test->iter, test->dlen);
+ gsize size = 0;
+ gconstpointer data;
+
+ g_assert(result);
+ data = g_bytes_get_data(result, &size);
+
+ g_assert_cmpuint(size, == ,test->output.len);
+ g_assert(!memcmp(data, test->output.val, size));
+ g_bytes_unref(result);
+}
+
+/* Test descriptors */
+
+#define TEST_(name) "/kdf/" name
+
+/*
+ * RFC 6070
+ * PKCS #5: Password-Based Key Derivation Function 2 (PBKDF2) Test Vectors
+ */
+
+static guint8 rfc6070_001_output[] = {
+ 0x0c, 0x60, 0xc8, 0x0f, 0x96, 0x1f, 0x0e, 0x71,
+ 0xf3, 0xa9, 0xb5, 0x24, 0xaf, 0x60, 0x12, 0x06,
+ 0x2f, 0xe0, 0x37, 0xa6
+};
+
+static guint8 rfc6070_002_output[] = {
+ 0xea, 0x6c, 0x01, 0x4d, 0xc7, 0x2d, 0x6f, 0x8c,
+ 0xcd, 0x1e, 0xd9, 0x2a, 0xce, 0x1d, 0x41, 0xf0,
+ 0xd8, 0xde, 0x89, 0x57
+};
+
+static guint8 rfc6070_003_output[] = {
+ 0x4b, 0x00, 0x79, 0x01, 0xb7, 0x65, 0x48, 0x9a,
+ 0xbe, 0xad, 0x49, 0xd9, 0x26, 0xf7, 0x21, 0xd0,
+ 0x65, 0xa4, 0x29, 0xc1
+};
+
+#ifdef TEST_16777216
+/* This one takes too long to run it on every build (although it succeeds) */
+static guint8 rfc6070_004_output[] = {
+ 0xee, 0xfe, 0x3d, 0x61, 0xcd, 0x4d, 0xa4, 0xe4,
+ 0xe9, 0x94, 0x5b, 0x3d, 0x6b, 0xa2, 0x15, 0x8c,
+ 0x26, 0x34, 0xe9, 0x84
+};
+#endif
+
+static guint8 rfc6070_005_output[] = {
+ 0x3d, 0x2e, 0xec, 0x4f, 0xe4, 0x1c, 0x84, 0x9b,
+ 0x80, 0xc8, 0xd8, 0x36, 0x62, 0xc0, 0xe4, 0x4a,
+ 0x8b, 0x29, 0x1a, 0x96, 0x4c, 0xf2, 0xf0, 0x70,
+ 0x38
+};
+
+static guint8 rfc6070_006_output[] = {
+ 0x56, 0xfa, 0x6a, 0xa7, 0x55, 0x48, 0x09, 0x9d,
+ 0xcc, 0x37, 0xd7, 0xf0, 0x34, 0x25, 0xe0, 0xc3
+};
+
+static guint8 collision_salt[] = {
+ 0xa0, 0x09, 0xc1, 0xa4, 0x85, 0x91, 0x2c, 0x6a,
+ 0xe6, 0x30, 0xd3, 0xe7, 0x44, 0x24, 0x0b, 0x04
+};
+
+static guint8 collision_output[] = {
+ 0x17, 0xeb, 0x40, 0x14, 0xc8, 0xc4, 0x61, 0xc3,
+ 0x00, 0xe9, 0xb6, 0x15, 0x18, 0xb9, 0xa1, 0x8b
+};
+
+static const TestKdf tests[] = {
+ {
+ TEST_("RFC6070/001"),
+ foil_impl_digest_sha1_get_type,
+ "password", 8,
+ { (const guint8*) "salt", 4 },
+ 1,
+ 20,
+ { TEST_ARRAY_AND_SIZE(rfc6070_001_output) }
+ },{
+ TEST_("RFC6070/002"),
+ foil_impl_digest_sha1_get_type,
+ "password", -1, /* Do strlen() on the password */
+ { (const guint8*) "salt", 4 },
+ 2,
+ 0, /* Use the default (digest size) */
+ { TEST_ARRAY_AND_SIZE(rfc6070_002_output) }
+ },{
+ TEST_("RFC6070/003"),
+ foil_impl_digest_sha1_get_type,
+ "password", 8,
+ { (const guint8*) "salt", 4 },
+ 4096,
+ 20,
+ { TEST_ARRAY_AND_SIZE(rfc6070_003_output) }
+#ifdef TEST_16777216
+ },{ /* This one takes too long to run it on every build */
+ TEST_("RFC6070/004"),
+ foil_impl_digest_sha1_get_type,
+ "password", 8,
+ { (const guint8*) "salt", 4 },
+ 16777216,
+ 20,
+ { TEST_ARRAY_AND_SIZE(rfc6070_004_output) }
+#endif
+ },{
+ TEST_("RFC6070/005"),
+ foil_impl_digest_sha1_get_type,
+ "passwordPASSWORDpassword", 24,
+ { (const guint8*) "saltSALTsaltSALTsaltSALTsaltSALTsalt", 36 },
+ 4096,
+ 25,
+ { TEST_ARRAY_AND_SIZE(rfc6070_005_output) }
+ },{
+ TEST_("RFC6070/006"),
+ foil_impl_digest_sha1_get_type,
+ "pass\0word", 9,
+ { (const guint8*) "sa\0lt", 5 },
+ 4096,
+ 16,
+ { TEST_ARRAY_AND_SIZE(rfc6070_006_output) }
+ },{ /* Collision example from Wikipedia */
+ TEST_("collision/1"),
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/test/libfoil/test_key_aes/Makefile
^
|
@@ -1,6 +1,5 @@
# -*- Mode: makefile-gmake -*-
EXE = test_key_aes
-COMMON_SRC = test_main.c
include ../../common/Makefile
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/test/libfoil/test_key_aes/test_key_aes.c
^
|
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016-2019 by Slava Monich
+ * Copyright (C) 2016-2022 by Slava Monich <slava@monich.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -168,6 +168,12 @@
FoilKey* key2 = foil_key_generate_new(type, FOIL_KEY_BITS_DEFAULT);
GBytes* bytes = foil_key_to_bytes(key2);
FoilKey* key3;
+
+ /* Only default format is valid for AES keys */
+ g_assert(!foil_key_to_binary_format(key1, FOIL_KEY_EXPORT_FORMAT_RSA_PKCS1));
+ g_assert(!foil_key_to_binary_format(key1, FOIL_KEY_BINARY_FORMAT_RSA_SSH));
+ g_assert(!foil_key_to_binary_format(key1, (FoilKeyBinaryFormat)-1));
+
g_assert(key1 && key2);
key3 = foil_key_new_from_bytes(G_TYPE_FROM_INSTANCE(key2), bytes);
g_assert(key3);
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/test/libfoil/test_key_des/Makefile
^
|
@@ -1,6 +1,5 @@
# -*- Mode: makefile-gmake -*-
EXE = test_key_des
-COMMON_SRC = test_main.c
include ../../common/Makefile
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/test/libfoil/test_key_des/test_key_des.c
^
|
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2019 by Slava Monich
+ * Copyright (C) 2019-2022 by Slava Monich <slava@monich.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -130,6 +130,11 @@
FoilKey* deserialized = foil_key_new_from_bytes(FOIL_KEY_DES, serialized);
GError* error = NULL;
+ /* Only default format is valid for DES keys */
+ g_assert(!foil_key_to_binary_format(key, FOIL_KEY_EXPORT_FORMAT_RSA_PKCS1));
+ g_assert(!foil_key_to_binary_format(key, FOIL_KEY_BINARY_FORMAT_RSA_SSH));
+ g_assert(!foil_key_to_binary_format(key, (FoilKeyBinaryFormat)-1));
+
/* If IV is already zero, foil_key_set_iv works like foil_key_ref */
g_assert(foil_key_set_iv(key3, NULL, FOIL_DES_IV_SIZE) == key3);
foil_key_unref(key3);
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/test/libfoil/test_key_rsa/test_key_rsa.c
^
|
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016-2019 by Slava Monich
+ * Copyright (C) 2016-2022 by Slava Monich <slava@monich.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -418,12 +418,39 @@
TestKeyRsaKeys keys;
GBytes* pub_data;
GBytes* priv_data;
+ GBytes* bytes;
FoilKey* pub2;
+ FoilKey* priv_key;
FoilPrivateKey* priv2;
test_key_rsa_keys_init(&keys, test);
+ priv_key = FOIL_KEY(keys.priv);
+
+ /* Invalid binary format produces NULL */
+ g_assert(!foil_key_to_binary_format(keys.pub, (FoilKeyBinaryFormat)-1));
+ g_assert(!foil_key_to_binary_format(priv_key, (FoilKeyBinaryFormat)-1));
+
+ /* No ssh-rsa format for RSA private key */
+ g_assert(!foil_key_to_binary_format(priv_key,
+ FOIL_KEY_BINARY_FORMAT_RSA_SSH));
+
+ /* Data in default format */
pub_data = foil_key_to_bytes(keys.pub);
- priv_data = foil_key_to_bytes(FOIL_KEY(keys.priv));
+ priv_data = foil_key_to_bytes(priv_key);
+
+ /* ssh-rsa format is the default public key format */
+ bytes = foil_key_to_binary_format(keys.pub,
+ FOIL_KEY_BINARY_FORMAT_RSA_SSH);
+ g_assert(g_bytes_equal(bytes, pub_data));
+ g_bytes_unref(bytes);
+
+ /* PKCS1 is the default RSA private key format */
+ bytes = foil_key_to_binary_format(priv_key,
+ FOIL_KEY_EXPORT_FORMAT_RSA_PKCS1);
+ g_assert(g_bytes_equal(bytes, priv_data));
+ g_bytes_unref(bytes);
+
+ /* Reconstruct the keys from the data in default format */
pub2 = foil_key_new_from_bytes(FOIL_KEY_RSA_PUBLIC, pub_data);
priv2 = foil_private_key_new_from_bytes(FOIL_KEY_RSA_PRIVATE, priv_data);
g_assert(pub2);
@@ -433,6 +460,17 @@
foil_key_unref(pub2);
foil_private_key_unref(priv2);
+
+ /* Test non-default PKCS #1 RSA public key format */
+ g_bytes_unref(pub_data);
+ pub_data = foil_key_to_binary_format(keys.pub,
+ FOIL_KEY_EXPORT_FORMAT_RSA_PKCS1);
+
+ pub2 = foil_key_new_from_bytes(FOIL_KEY_RSA_PUBLIC, pub_data);
+ g_assert(pub2);
+ g_assert(foil_key_equal(pub2, keys.pub));
+ foil_key_unref(pub2);
+
g_bytes_unref(pub_data);
g_bytes_unref(priv_data);
test_key_rsa_keys_deinit(&keys);
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/test/libfoil/test_output/Makefile
^
|
@@ -1,6 +1,6 @@
# -*- Mode: makefile-gmake -*-
EXE = test_output
-COMMON_SRC = test_main.c
+COMMON_SRC = test_main.c test_hexdump.c
include ../../common/Makefile
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/test/libfoil/test_output/test_output.c
^
|
@@ -1,26 +1,31 @@
/*
- * Copyright (C) 2016-2017 by Slava Monich
+ * Copyright (C) 2016-2022 by Slava Monich <slava@monich.com>
*
* 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.
+ * 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 ``AS IS'' AND ANY EXPRESSED 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 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) ARISING
- * IN ANY WAY OUT OF THE USE OR INABILITY TO USE THIS SOFTWARE, EVEN
- * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 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.
*
* The views and conclusions contained in the software and documentation
* are those of the authors and should not be interpreted as representing
@@ -30,16 +35,37 @@
#include "test_common.h"
#include "foil_output.h"
+#include "foil_cipher.h"
#include "foil_digest.h"
+#include "foil_hmac.h"
+#include "foil_key.h"
+#include "foil_private_key.h"
+
+#include <gutil_misc.h>
#include <glib/gstdio.h>
+#define TEST_(name) "/output/" name
+
+typedef struct test_output_cipher_data {
+ const char* name;
+ GUtilData key;
+ GType (*key_type)(void);
+ FoilKey* (*dec_key)(FoilKey*);
+ GType (*enc_type)(void);
+ GType (*dec_type)(void);
+ const void* input;
+ gsize input_size;
+} TestOutputCipher;
+
static
void
test_output_null(
void)
{
guint8 buf[1];
+ FoilKey* key = foil_key_generate_new(FOIL_TYPE_KEY_AES, 128);
+ FoilCipher* cipher = foil_cipher_new(FOIL_CIPHER_AES_CBC_ENCRYPT, key);
FoilOutput* out = foil_output_mem_new(NULL);
GBytes* empty = g_bytes_new_static(buf, 0);
@@ -48,6 +74,12 @@
foil_output_close(NULL);
foil_output_unref(NULL);
g_assert(!foil_output_ref(NULL));
+ g_assert(!foil_output_cipher_mem_new(NULL, NULL, NULL));
+ g_assert(!foil_output_cipher_mem_new2(NULL, NULL, NULL));
+ g_assert(!foil_output_cipher_new(NULL, cipher, NULL));
+ g_assert(!foil_output_cipher_new(NULL, NULL, NULL));
+ g_assert(!foil_output_cipher_new2(NULL, cipher, NULL));
+ g_assert(!foil_output_cipher_new2(NULL, NULL, NULL));
g_assert(!foil_output_digest_new(NULL, NULL));
g_assert(!foil_output_file_new_open(NULL));
g_assert(!foil_output_free_to_bytes(NULL));
@@ -58,6 +90,8 @@
g_assert(!foil_output_write(out, NULL, 0));
g_assert(!foil_output_write(out, buf, 0));
g_assert(!foil_output_write(out, NULL, 1));
+ g_assert(!foil_output_write_eol(NULL));
+ g_assert(!foil_output_write_byte(NULL, 1));
g_assert(foil_output_write_bytes(NULL, NULL) < 0);
g_assert(!foil_output_write_bytes(out, NULL));
g_assert(foil_output_write_bytes(out, empty) == 0);
@@ -65,6 +99,8 @@
g_assert(foil_output_write_bytes_all(out, NULL));
g_assert(foil_output_write_bytes_all(out, empty));
foil_output_unref(out);
+ foil_cipher_unref(cipher);
+ foil_key_unref(key);
g_bytes_unref(empty);
}
@@ -107,13 +143,259 @@
out = foil_output_mem_new(buf);
g_assert(foil_output_write_all(out, test123, sizeof(test123)));
g_byte_array_append(buf, test123, sizeof(test123));
- g_assert(!foil_output_free_to_bytes(out));
+ g_assert(!foil_output_free_to_bytes(out));
+
+ /* Writing a single byte */
+ g_byte_array_set_size(buf, 0);
+ out = foil_output_mem_new(buf);
+ g_assert(foil_output_write_byte(out, 42));
+ g_assert_cmpuint(buf->len, == ,1);
+ g_assert_cmpuint(buf->data[0], == ,42);
+ foil_output_unref(out);
g_byte_array_unref(buf);
}
static
void
+test_output_cipher_basic(
+ void)
+{
+ static const char prefix[] = "This is a prefix";
+ static const char test_data[] = "This is a secret";
+ GByteArray* buf1 = g_byte_array_new();
+ GByteArray* buf2 = g_byte_array_new();
+ FoilKey* key = foil_key_generate_new(FOIL_TYPE_KEY_AES, 128);
+ FoilCipher* cipher1 = foil_cipher_new(FOIL_CIPHER_AES_CBC_ENCRYPT, key);
+ FoilCipher* cipher2 = foil_cipher_new(FOIL_CIPHER_AES_CBC_ENCRYPT, key);
+ FoilOutput* buf = foil_output_mem_new(buf1);
+ FoilOutput* out = foil_output_cipher_new(buf, cipher1, NULL);
+ FoilOutput* out_mem;
+
+ /* Add some data in front of the ciphered data */
+ g_byte_array_append(buf2, (const void*)prefix, sizeof(prefix));
+ out_mem = foil_output_cipher_mem_new(buf2, cipher2, NULL);
+
+ foil_cipher_unref(cipher1);
+ foil_cipher_unref(cipher2);
+ g_assert(!foil_output_reset(out));
+ g_assert(!foil_output_reset(out_mem));
+ g_assert(foil_output_flush(out));
+ g_assert(foil_output_write_all(out, test_data, sizeof(test_data)));
+ g_assert(foil_output_write_all(out_mem, test_data, sizeof(test_data)));
+ TEST_DEBUG_HEXDUMP(buf1->data, buf1->len);
+ g_assert_cmpuint(buf1->len, > ,0);
+ g_assert_cmpuint(buf1->len, == ,buf2->len - sizeof(prefix));
+ g_assert(!memcmp(buf1->data, buf2->data + sizeof(prefix), buf1->len));
+ foil_output_unref(out_mem);
+
+ /* Fail to write to a closed stream */
+ foil_output_close(buf);
+ foil_output_unref(buf);
+ g_assert(!foil_output_write_all(out, test_data, sizeof(test_data)));
+ foil_output_unref(out);
+
+ /* Another kind of failure due to a closed underlying stream */
+ cipher1 = foil_cipher_new(FOIL_CIPHER_AES_CBC_ENCRYPT, key);
+ buf = foil_output_mem_new(NULL);
+ out = foil_output_cipher_new(buf, cipher1, NULL);
+ foil_cipher_unref(cipher1);
+
+ g_assert(foil_output_write_all(out, test_data, sizeof(test_data)));
+ foil_output_close(buf);
+ foil_output_unref(buf);
+ g_assert(!foil_output_free_to_bytes(out));
+
+ g_byte_array_unref(buf1);
+ g_byte_array_unref(buf2);
+ foil_key_unref(key);
+}
+
+static
+void
+test_output_cipher_digest(
+ gconstpointer param)
+{
+ static const char prefix[] = "This is a prefix";
+ const TestOutputCipher* test = param;
+ const guint8* in = test->input;
+ GType digest_type = FOIL_DIGEST_SHA1;
+ GByteArray* mem2 = g_byte_array_new_take(gutil_memdup(prefix,
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/tools/foilmsg/Makefile
^
|
@@ -35,23 +35,12 @@
RELEASE_BUILD_DIR = $(BUILD_DIR)/release
#
-# Application version
-#
-
-VERSION_FILE = ../../VERSION
-VERSION_MAJOR = $(shell head -1 $(VERSION_FILE) | cut -f1 -d.)
-VERSION_MINOR = $(shell head -1 $(VERSION_FILE) | cut -f2 -d.)
-VERSION_RELEASE = $(shell head -1 $(VERSION_FILE) | cut -f3 -d.)
-VERSION = $(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_RELEASE)
-
-#
# Tools and flags
#
CC = $(CROSS_COMPILE)gcc
LD = $(CC)
WARNINGS = -Wall
-DEFINES += -DVERSION=$(VERSION)
INCLUDES = -I$(LIBFOIL_DIR)/include -I$(LIBFOILMSG_DIR)/include
BASE_FLAGS = -fPIC
BASE_LDFLAGS = $(BASE_FLAGS) $(LDFLAGS)
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/tools/foilmsg/foilmsg.c
^
|
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2016-2021 by Slava Monich
+ * Copyright (C) 2016-2022 by Slava Monich
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -386,7 +386,7 @@
gboolean show_info = FALSE;
gboolean for_self = FALSE;
gboolean binary = FALSE;
-#ifdef VERSION
+#ifdef FOIL_VERSION_STRING
gboolean print_version = FALSE;
#endif
GError* error = NULL;
@@ -418,7 +418,7 @@
"Write output to FILE", "FILE" },
{ "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
"Enable verbose output", NULL },
-#ifdef VERSION
+#ifdef FOIL_VERSION_STRING
{ "version", 0, 0, G_OPTION_ARG_NONE, &print_version,
"Print version and exit", NULL },
#endif
@@ -500,9 +500,9 @@
decrypt = TRUE;
}
-#ifdef VERSION
+#ifdef FOIL_VERSION_STRING
if (ok && print_version) {
- printf("%s %s\n", gutil_log_default.name, G_STRINGIFY(VERSION));
+ printf("%s %s\n", gutil_log_default.name, FOIL_VERSION_STRING);
ret = RET_OK;
} else
#endif
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/tools/foilpng/Makefile
^
|
@@ -35,23 +35,12 @@
RELEASE_BUILD_DIR = $(BUILD_DIR)/release
#
-# Application version
-#
-
-VERSION_FILE = ../../VERSION
-VERSION_MAJOR = $(shell head -1 $(VERSION_FILE) | cut -f1 -d.)
-VERSION_MINOR = $(shell head -1 $(VERSION_FILE) | cut -f2 -d.)
-VERSION_RELEASE = $(shell head -1 $(VERSION_FILE) | cut -f3 -d.)
-VERSION = $(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_RELEASE)
-
-#
# Tools and flags
#
CC = $(CROSS_COMPILE)gcc
LD = $(CC)
WARNINGS = -Wall
-DEFINES += -DVERSION=$(VERSION)
INCLUDES = -I$(LIBFOIL_DIR)/include -I$(LIBFOILMSG_DIR)/include
BASE_FLAGS = -fPIC
BASE_LDFLAGS = $(BASE_FLAGS) $(LDFLAGS)
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/foil/tools/foilpng/foilpng.c
^
|
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2017-2021 by Slava Monich
+ * Copyright (C) 2017-2022 by Slava Monich
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -399,7 +399,7 @@
gboolean verbose = FALSE;
gboolean decrypt = FALSE;
gboolean for_self = FALSE;
-#ifdef VERSION
+#ifdef FOIL_VERSION_STRING
gboolean print_version = FALSE;
#endif
GError* error = NULL;
@@ -422,7 +422,7 @@
"Public key of the other party", "FILE" },
{ "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
"Enable verbose output", NULL },
-#ifdef VERSION
+#ifdef FOIL_VERSION_STRING
{ "version", 0, 0, G_OPTION_ARG_NONE, &print_version,
"Print version and exit", NULL },
#endif
@@ -488,9 +488,9 @@
ok = FALSE;
}
-#ifdef VERSION
+#ifdef FOIL_VERSION_STRING
if (ok && print_version) {
- printf("%s %s\n", gutil_log_default.name, G_STRINGIFY(VERSION));
+ printf("%s %s\n", gutil_log_default.name, FOIL_VERSION_STRING);
ret = RET_OK;
} else
#endif
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/harbour-lib/LICENSE
^
|
@@ -1,5 +1,5 @@
Copyright (C) 2015-2021 Jolla Ltd.
-Copyright (C) 2015-2021 Slava Monich <slava@monich.com>
+Copyright (C) 2015-2023 Slava Monich <slava@monich.com>
You may use this file under the terms of BSD license as follows:
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/harbour-lib/harbour-lib.pro
^
|
@@ -25,6 +25,7 @@
SOURCES += \
src/HarbourBase32.cpp \
src/HarbourBase45.cpp \
+ src/HarbourBattery.cpp \
src/HarbourClipboard.cpp \
src/HarbourColorEditorModel.cpp \
src/HarbourDisplayBlanking.cpp \
@@ -36,6 +37,7 @@
src/HarbourOrganizeListModel.cpp \
src/HarbourPolicyPlugin.cpp \
src/HarbourProcessState.cpp \
+ src/HarbourProtoBuf.cpp \
src/HarbourSelectionListModel.cpp \
src/HarbourSigChildHandler.cpp \
src/HarbourSingleImageProvider.cpp \
@@ -46,7 +48,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 += \
@@ -59,6 +62,7 @@
PUBLIC_HEADERS += \
include/HarbourBase32.h \
include/HarbourBase45.h \
+ include/HarbourBattery.h \
include/HarbourClipboard.h \
include/HarbourColorEditorModel.h \
include/HarbourDebug.h \
@@ -70,6 +74,7 @@
include/HarbourOrganizeListModel.h \
include/HarbourPolicyPlugin.h \
include/HarbourProcessState.h \
+ include/HarbourProtoBuf.h \
include/HarbourSelectionListModel.h \
include/HarbourSigChildHandler.h \
include/HarbourSingleImageProvider.h \
@@ -80,7 +85,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-foilnotes-1.1.1.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-foilnotes-1.1.1.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-foilnotes-1.1.1.tar.gz/harbour-lib/include/HarbourBattery.h
^
|
@@ -0,0 +1,89 @@
+/*
+ * 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_BATTERY_H
+#define HARBOUR_BATTERY_H
+
+#include <QObject>
+
+class QQmlEngine;
+class QJSEngine;
+
+// D-Bus calls used by this object require mce 1.86.0 (Sailfish OS 2.1)
+class HarbourBattery: public QObject
+{
+ Q_OBJECT
+ Q_PROPERTY(BatteryStatus batteryStatus READ batteryStatus NOTIFY batteryStatusChanged)
+ Q_PROPERTY(BatteryState batteryState READ batteryState NOTIFY batteryStateChanged)
+ Q_PROPERTY(int batteryLevel READ batteryLevel NOTIFY batteryLevelChanged)
+ Q_ENUMS(BatteryStatus)
+ Q_ENUMS(BatteryState)
+
+public:
+ enum BatteryStatus {
+ BatteryStatusUnknown,
+ BatteryStatusEmpty,
+ BatteryStatusLow,
+ BatteryStatusOk,
+ BatteryStatusFull
+ };
+
+ enum BatteryState {
+ BatteryStateUnknown,
+ BatteryStateCharging,
+ BatteryStateDischarging,
+ BatteryStateNotCharging,
+ BatteryStateFull
+ };
+
+ explicit HarbourBattery(QObject* aParent = Q_NULLPTR);
+ ~HarbourBattery();
+
+ // Callback for qmlRegisterSingletonType<HarbourBattery>
+ static QObject* createSingleton(QQmlEngine*, QJSEngine*);
+
+ BatteryStatus batteryStatus() const;
+ BatteryState batteryState() const;
+ int batteryLevel() const;
+
+Q_SIGNALS:
+ void batteryStatusChanged();
+ void batteryStateChanged();
+ void batteryLevelChanged();
+
+private:
+ class Private;
+ Private* iPrivate;
+};
+
+#endif // HARBOUR_BATTERY_H
|
[-]
[+]
|
Added |
_service:tar_git:harbour-foilnotes-1.1.1.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-foilnotes-1.1.1.tar.gz/harbour-lib/include/HarbourSelectionListModel.h
^
|
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2019 Jolla Ltd.
- * Copyright (C) 2019 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2019-2023 Slava Monich <slava@jolla.com>
*
* You may use this file under the terms of the BSD license as follows:
*
@@ -37,33 +37,44 @@
#include <QtQml>
#include <QIdentityProxyModel>
-class HarbourSelectionListModel : public QIdentityProxyModel {
+class HarbourSelectionListModel : public QIdentityProxyModel
+{
Q_OBJECT
Q_PROPERTY(QObject* sourceModel READ sourceModel WRITE setSourceModelObject NOTIFY sourceModelObjectChanged)
+ Q_PROPERTY(QList<int> nonSelectableRows READ nonSelectableRows WRITE setNonSelectableRows NOTIFY nonSelectableRowsChanged)
Q_PROPERTY(QList<int> selectedRows READ selectedRows NOTIFY selectedRowsChanged)
- Q_PROPERTY(int selectionCount READ selectionCount NOTIFY selectedRowsChanged)
+ Q_PROPERTY(int selectableCount READ selectableCount NOTIFY selectableCountChanged)
+ Q_PROPERTY(int selectionCount READ selectionCount NOTIFY selectionCountChanged)
Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
public:
HarbourSelectionListModel(QObject* aParent = Q_NULLPTR);
- void setSourceModelObject(QObject* aModel);
+ void setSourceModelObject(QObject*);
+
+ QList<int> nonSelectableRows() const;
+ void setNonSelectableRows(const QList<int>);
QList<int> selectedRows() const;
+ int selectableCount() const;
int selectionCount() const;
Q_INVOKABLE void selectAll();
Q_INVOKABLE void clearSelection();
+ Q_INVOKABLE void toggleRows(const QList<int>);
// 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;
- QVariant data(const QModelIndex& aIndex, int aRole) const Q_DECL_OVERRIDE;
- bool setData(const QModelIndex& aIndex, const QVariant& aValue, int aRole) 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 sourceModelObjectChanged();
+ void nonSelectableRowsChanged();
void selectedRowsChanged();
+ void selectableCountChanged();
+ void selectionCountChanged();
void countChanged();
private:
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.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-foilnotes-1.1.1.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-foilnotes-1.1.1.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)
|
[-]
[+]
|
Added |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/harbour-lib/qml/HarbourInvertEffect.qml
^
|
@@ -0,0 +1,13 @@
+import QtQuick 2.0
+
+ShaderEffect {
+ property variant source
+ fragmentShader: "
+ uniform sampler2D source;
+ uniform lowp float qt_Opacity;
+ varying highp vec2 qt_TexCoord0;
+ void main(void) {
+ highp vec4 pixelColor = texture2D(source, qt_TexCoord0);
+ gl_FragColor = vec4(vec3(1,1,1) - pixelColor.rgb, pixelColor.a) * qt_Opacity;
+ }"
+}
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.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-foilnotes-1.1.1.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-foilnotes-1.1.1.tar.gz/harbour-lib/src/HarbourBattery.cpp
^
|
@@ -0,0 +1,266 @@
+/*
+ * 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 "HarbourBattery.h"
+#include "HarbourDebug.h"
+#include "HarbourMce.h"
+
+#include <QDBusPendingCallWatcher>
+#include <QDBusPendingReply>
+
+// ==========================================================================
+// HarbourBattery::Private
+// ==========================================================================
+
+class HarbourBattery::Private : public HarbourMce
+{
+ Q_OBJECT
+
+public:
+ static const QString MCE_BATTERY_STATUS_UNKNOWN;
+ static const QString MCE_BATTERY_STATUS_FULL;
+ static const QString MCE_BATTERY_STATUS_OK;
+ static const QString MCE_BATTERY_STATUS_LOW;
+ static const QString MCE_BATTERY_STATUS_EMPTY;
+
+ static const QString MCE_BATTERY_STATE_UNKNOWN;
+ static const QString MCE_BATTERY_STATE_DISCHARGING;
+ static const QString MCE_BATTERY_STATE_CHARGING;
+ static const QString MCE_BATTERY_STATE_NOT_CHARGING;
+ static const QString MCE_BATTERY_STATE_FULL;
+
+ Private(HarbourBattery*);
+
+ HarbourBattery* parentObject() const;
+
+public Q_SLOTS:
+ void updateBatteryStatus(const QString);
+ void updateBatteryState(const QString);
+ void updateBatteryLevel(int);
+ void onBatteryStatusQueryDone(QDBusPendingCallWatcher*);
+ void onBatteryStateQueryDone(QDBusPendingCallWatcher*);
+ void onBatteryLevelQueryDone(QDBusPendingCallWatcher*);
+
+public:
+ BatteryStatus iBatteryStatus;
+ BatteryState iBatteryState;
+ int iBatteryLevel;
+};
+
+const QString HarbourBattery::Private::MCE_BATTERY_STATUS_UNKNOWN("unknown");
+const QString HarbourBattery::Private::MCE_BATTERY_STATUS_FULL("full");
+const QString HarbourBattery::Private::MCE_BATTERY_STATUS_OK("ok");
+const QString HarbourBattery::Private::MCE_BATTERY_STATUS_LOW("low");
+const QString HarbourBattery::Private::MCE_BATTERY_STATUS_EMPTY("empty");
+
+const QString HarbourBattery::Private::MCE_BATTERY_STATE_UNKNOWN("unknown");
+const QString HarbourBattery::Private::MCE_BATTERY_STATE_DISCHARGING("discharging");
+const QString HarbourBattery::Private::MCE_BATTERY_STATE_CHARGING("charging");
+const QString HarbourBattery::Private::MCE_BATTERY_STATE_NOT_CHARGING("not_charging");
+const QString HarbourBattery::Private::MCE_BATTERY_STATE_FULL("full");
+
+HarbourBattery::Private::Private(
+ HarbourBattery* aParent) :
+ HarbourMce(aParent),
+ iBatteryStatus(BatteryStatusUnknown),
+ iBatteryState(BatteryStateUnknown),
+ iBatteryLevel(0)
+{
+ setupProperty("get_battery_status", "battery_status_ind",
+ SLOT(onBatteryStatusQueryDone(QDBusPendingCallWatcher*)),
+ SLOT(updateBatteryStatus(QString)));
+ setupProperty("get_battery_state", "battery_state_ind",
+ SLOT(onBatteryStateQueryDone(QDBusPendingCallWatcher*)),
+ SLOT(updateBatteryState(QString)));
+ setupProperty("get_battery_level", "battery_level_ind",
+ SLOT(onBatteryLevelQueryDone(QDBusPendingCallWatcher*)),
+ SLOT(updateBatteryLevel(int)));
+}
+
+inline
+HarbourBattery*
+HarbourBattery::Private::parentObject() const
+{
+ return qobject_cast<HarbourBattery*>(parent());
+}
+
+void
+HarbourBattery::Private::updateBatteryStatus(
+ const QString aStatus)
+{
+ BatteryStatus status = BatteryStatusUnknown;
+
+ if (aStatus == MCE_BATTERY_STATUS_OK) {
+ status = BatteryStatusOk;
+ } else if (aStatus == MCE_BATTERY_STATUS_FULL) {
+ status = BatteryStatusFull;
+ } else if (aStatus == MCE_BATTERY_STATUS_LOW) {
+ status = BatteryStatusLow;
+ } else if (aStatus == MCE_BATTERY_STATUS_EMPTY) {
+ status = BatteryStatusEmpty;
+ } else if (aStatus != MCE_BATTERY_STATUS_UNKNOWN) {
+ HWARN("Unexpected battery status" << aStatus);
+ return;
+ }
+
+ if (iBatteryStatus != status) {
+ iBatteryStatus = status;
+ HDEBUG(aStatus);
+ Q_EMIT parentObject()->batteryStatusChanged();
+ }
+}
+
+void
+HarbourBattery::Private::updateBatteryState(
+ const QString aState)
+{
+ BatteryState state = BatteryStateUnknown;
+
+ if (aState == MCE_BATTERY_STATE_CHARGING) {
+ state = BatteryStateCharging;
+ } else if (aState == MCE_BATTERY_STATE_DISCHARGING) {
+ state = BatteryStateDischarging;
+ } else if (aState == MCE_BATTERY_STATE_NOT_CHARGING) {
+ state = BatteryStateNotCharging;
+ } else if (aState == MCE_BATTERY_STATE_FULL) {
+ state = BatteryStateFull;
+ } else if (aState != MCE_BATTERY_STATE_UNKNOWN) {
+ HWARN("Unexpected battery state" << aState);
+ return;
+ }
+
+ if (iBatteryState != state) {
+ iBatteryState = state;
+ HDEBUG(aState);
+ Q_EMIT parentObject()->batteryStateChanged();
+ }
+}
+
+void
+HarbourBattery::Private::updateBatteryLevel(
+ int aLevel)
+{
+ if (iBatteryLevel != aLevel) {
+ iBatteryLevel = aLevel;
+ HDEBUG(aLevel);
+ Q_EMIT parentObject()->batteryLevelChanged();
+ }
+}
+
+void
+HarbourBattery::Private::onBatteryStatusQueryDone(
+ QDBusPendingCallWatcher* aWatcher)
+{
+ QDBusPendingReply<QString> reply(*aWatcher);
+
+ if (reply.isError()) {
+ HWARN(reply.error().message());
+ } else {
+ updateBatteryStatus(reply.value());
+ }
+ aWatcher->deleteLater();
+}
+
+void
+HarbourBattery::Private::onBatteryStateQueryDone(
+ QDBusPendingCallWatcher* aWatcher)
+{
+ QDBusPendingReply<QString> reply(*aWatcher);
+
|
[-]
[+]
|
Added |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/harbour-lib/src/HarbourProtoBuf.cpp
^
|
@@ -0,0 +1,144 @@
+/*
+ * 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)
+{
+ if (aOutput) {
+ 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)
+{
+ if (aOutput) {
+ 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)
+{
+ if (aPos) {
+ 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;
+ if (aResult) {
+ *aResult = value;
+ }
+ return true;
+ }
+ }
+
+ // Premature end of stream or too many bytes
+ if (aResult) {
+ *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)
+{
+ if (aPos) {
+ GUtilRange pos = *aPos;
+ quint64 size;
+
+ if (parseVarInt(&pos, &size) && (pos.ptr + size) <= pos.end) {
+ if (aPayload) {
+ aPayload->bytes = pos.ptr;
+ aPayload->size = size;
+ }
+ aPos->ptr = pos.ptr + size;
+ return true;
+ }
+ }
+ return false;
+}
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/harbour-lib/src/HarbourSelectionListModel.cpp
^
|
@@ -1,6 +1,6 @@
-/*
+/*
* Copyright (C) 2019 Jolla Ltd.
- * Copyright (C) 2019 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2019-2023 Slava Monich <slava@jolla.com>
*
* You may use this file under the terms of the BSD license as follows:
*
@@ -41,20 +41,47 @@
// HarbourSelectionListModel::Private
// ==========================================================================
-class HarbourSelectionListModel::Private : public QObject {
+// s(SignalName,signalName)
+#define QUEUED_SIGNALS(s) \
+ s(NonSelectableRows,nonSelectableRows) \
+ s(SelectedRows,selectedRows) \
+ s(SelectableCount,selectableCount) \
+ s(SelectionCount,selectionCount) \
+ s(Count,count)
+
+class HarbourSelectionListModel::Private : public QObject
+{
Q_OBJECT
public:
- Private(HarbourSelectionListModel* aParent);
+ typedef void (HarbourSelectionListModel::*SignalEmitter)();
+ typedef uint SignalMask;
+
+ enum Signal {
+#define SIGNAL_ENUM_(Name,name) Signal##Name##Changed,
+ QUEUED_SIGNALS(SIGNAL_ENUM_)
+#undef SIGNAL_ENUM_
+ SignalCount
+ };
+
+ Private(HarbourSelectionListModel*);
+
+ static int binaryFind(const QList<int>, int);
HarbourSelectionListModel* parentModel();
- static int binaryFind(const QList<int> aList, int aValue);
- bool isSelectionRole(int aRole) const;
- bool isSelectedRow(int aRow) const;
- int findSelectedRow(int aRow) const;
- void selectRow(int aRow);
- void unselectRow(int aRow);
- void selectionChangedAt(int aRow);
+ void queueSignal(Signal aSignal);
+ void emitQueuedSignals();
+ bool isSelectionRole(int) const;
+ bool isSelectedRow(int) const;
+ bool isSelectableRow(int) const;
+ int findSelectedRow(int) const;
+ void updateCounts();
+ void selectRow(int);
+ void unselectRow(int);
+ void toggleRows(const QList<int>);
+ void setNonSelectableRows(const QList<int>);
+ void selectedRowChanged(int);
+ void selectionChangedAt(int);
void clearSelection();
void selectAll();
void reset();
@@ -63,13 +90,20 @@
void onCountChanged();
public:
+ SignalMask iQueuedSignals;
+ Signal iFirstQueuedSignal;
QList<int> iSelectedRows;
- QVector<int> iSelectedRole;
+ QList<int> iNonSelectableRows;
+ QList<int> iNormalizedNonSelectableRows;
+ QVector<int> iSelectedRole; // Passed to dataChanged as an argument
+ int iLastKnownSelectableCount;
int iLastKnownCount;
};
-HarbourSelectionListModel::Private::Private(HarbourSelectionListModel* aParent) :
+HarbourSelectionListModel::Private::Private(
+ HarbourSelectionListModel* aParent) :
QObject(aParent),
+ iLastKnownSelectableCount(0),
iLastKnownCount(0)
{
connect(aParent, SIGNAL(modelReset()), SLOT(onCountChanged()));
@@ -77,22 +111,10 @@
connect(aParent, SIGNAL(rowsRemoved(QModelIndex,int,int)), SLOT(onCountChanged()));
}
-inline HarbourSelectionListModel* HarbourSelectionListModel::Private::parentModel()
-{
- return qobject_cast<HarbourSelectionListModel*>(parent());
-}
-
-inline bool HarbourSelectionListModel::Private::isSelectionRole(int aRole) const
-{
- return !iSelectedRole.isEmpty() && iSelectedRole.first() == aRole;
-}
-
-inline bool HarbourSelectionListModel::Private::isSelectedRow(int aRow) const
-{
- return findSelectedRow(aRow) >= 0;
-}
-
-int HarbourSelectionListModel::Private::binaryFind(const QList<int> aList, int aValue)
+int
+HarbourSelectionListModel::Private::binaryFind(
+ const QList<int> aList,
+ int aValue)
{
// It turned out to be significantly easier to copy/paste this code
// than to fight with qBinaryFind and iterators which behave strangely
@@ -117,34 +139,131 @@
return -(low + 1);
}
-int HarbourSelectionListModel::Private::findSelectedRow(int aRow) const
+inline
+HarbourSelectionListModel*
+HarbourSelectionListModel::Private::parentModel()
+{
+ return qobject_cast<HarbourSelectionListModel*>(parent());
+}
+
+void
+HarbourSelectionListModel::Private::queueSignal(
+ Signal aSignal)
+{
+ if (aSignal >= 0 && aSignal < SignalCount) {
+ const SignalMask signalBit = (SignalMask(1) << aSignal);
+ if (iQueuedSignals) {
+ iQueuedSignals |= signalBit;
+ if (iFirstQueuedSignal > aSignal) {
+ iFirstQueuedSignal = aSignal;
+ }
+ } else {
+ iQueuedSignals = signalBit;
+ iFirstQueuedSignal = aSignal;
+ }
+ }
+}
+
+void
+HarbourSelectionListModel::Private::emitQueuedSignals()
+{
+ static const SignalEmitter emitSignal [] = {
+#define SIGNAL_EMITTER_(Name,name) &HarbourSelectionListModel::name##Changed,
+ QUEUED_SIGNALS(SIGNAL_EMITTER_)
+#undef SIGNAL_EMITTER_
+ };
+ if (iQueuedSignals) {
+ HarbourSelectionListModel* model = parentModel();
+ // Reset first queued signal before emitting the signals.
+ // Signal handlers may emit new signals.
+ uint i = iFirstQueuedSignal;
+ iFirstQueuedSignal = SignalCount;
+ for (; i < SignalCount && iQueuedSignals; i++) {
+ const SignalMask signalBit = (SignalMask(1) << i);
+ if (iQueuedSignals & signalBit) {
+ iQueuedSignals &= ~signalBit;
+ Q_EMIT (model->*(emitSignal[i]))();
+ }
+ }
+ }
+}
+
+inline
+bool
+HarbourSelectionListModel::Private::isSelectionRole(
+ int aRole) const
+{
+ return !iSelectedRole.isEmpty() && iSelectedRole.first() == aRole;
+}
+
+inline
+bool
+HarbourSelectionListModel::Private::isSelectedRow(
+ int aRow) const
+{
+ return findSelectedRow(aRow) >= 0;
+}
+
+inline
+bool
+HarbourSelectionListModel::Private::isSelectableRow(
+ int aRow) const
+{
+ return binaryFind(iNonSelectableRows, aRow) < 0;
+}
+
+int
+HarbourSelectionListModel::Private::findSelectedRow(
+ int aRow) const
{
return binaryFind(iSelectedRows, aRow);
}
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.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-foilnotes-1.1.1.tar.gz/harbour-lib/src/HarbourUtil.cpp
^
|
@@ -0,0 +1,116 @@
+/*
+ * 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)
+{
+ return aSize ?
+ QByteArray::fromRawData((const char*) aData, (int) aSize).toHex() :
+ QByteArray();
+}
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/harbour-lib/src/libcrypto.c
^
|
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2021 Jolla Ltd.
- * Copyright (C) 2021 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2021-2023 Slava Monich <slava@monich.com>
*
* You may use this file under the terms of the BSD license as follows:
*
@@ -112,14 +112,22 @@
(const unsigned char* in, unsigned char* out, const AES_KEY* key, \
const int enc), \
(in, out, key, enc)) \
+ f(BN_clear_free, (BIGNUM *a), (a)) \
f(BN_free, (BIGNUM *a), (a)) \
f(DES_ede3_cbc_encrypt, \
(const unsigned char* input, unsigned char* output, long length, \
DES_key_schedule* ks1, DES_key_schedule* ks2, DES_key_schedule* ks3, \
DES_cblock* ivec, int enc), \
(input, output, length, ks1, ks2, ks3, ivec, enc)) \
- f(ERR_load_crypto_strings, (void), ()) \
- f(RSA_free, (RSA* r), (r))
+ f(/* libcrypto.so.10 */ ERR_load_crypto_strings, (void), ()) \
+ f(RSA_free, (RSA* r), (r)) \
+ f(/* libcrypto.so.1.1 */ RSA_get0_key, (const RSA* r, const BIGNUM** n, \
+ const BIGNUM** e, const BIGNUM** d), (r, n, e, d)) \
+ f(/* libcrypto.so.1.1 */ RSA_get0_factors, (const RSA* r, \
+ const BIGNUM** p, const BIGNUM** q), (r, p, q)) \
+ f(/* libcrypto.so.1.1 */ RSA_get0_crt_params, (const RSA* r, \
+ const BIGNUM** dmp1, const BIGNUM** dmq1, const BIGNUM** iqmp), \
+ (r, dmp1, dmq1, iqmp))
/* f(ret,name,params,args,def) */
#define LIBCRYPTO_FUNCTIONS2(f) \
@@ -149,7 +157,7 @@
f(int, MD5_Init, (MD5_CTX* c), (c), 0) \
f(int, MD5_Update, (MD5_CTX* c, const void* data, size_t len), \
(c, data, len), 0) \
- f(int, OPENSSL_init_crypto, \
+ f(int, /* libcrypto.so.1.1 */ OPENSSL_init_crypto, \
(uint64_t opts, const OPENSSL_INIT_SETTINGS* settings), \
(opts, settings), 0) \
f(int, RAND_bytes, (unsigned char* buf, int num), (buf, num), 0) \
@@ -173,6 +181,12 @@
(int flen, const unsigned char* from, unsigned char* to, RSA* rsa, \
int padding), (flen, from, to, rsa, padding), 0) \
f(int, RSA_size, (const RSA* rsa), (rsa), 0) \
+ f(int, /* libcrypto.so.1.1 */ RSA_set0_key, (RSA* r, BIGNUM* n, \
+ BIGNUM* e, BIGNUM* d), (r, n, e, d), 0) \
+ f(int, /* libcrypto.so.1.1 */ RSA_set0_factors, (RSA* r, BIGNUM* p, \
+ BIGNUM* q), (r, p, q), 0) \
+ f(int, /* libcrypto.so.1.1 */ RSA_set0_crt_params, (RSA* r, \
+ BIGNUM* dmp1, BIGNUM* dmq1, BIGNUM* iqmp), (r, dmp1, dmq1, iqmp), 0) \
f(unsigned char*, SHA1, (const unsigned char* d, size_t n, \
unsigned char* md), (d, n, md), NULL) \
f(int, SHA1_Final, (unsigned char* md, SHA_CTX* c), (md, c), 0) \
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/harbour-lib/test/Makefile
^
|
@@ -4,3 +4,5 @@
%:
@$(MAKE) -C TestHarbourBase32 $*
@$(MAKE) -C TestHarbourBase45 $*
+ @$(MAKE) -C TestHarbourProtoBuf $*
+ @$(MAKE) -C TestHarbourUtil $*
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.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-foilnotes-1.1.1.tar.gz/harbour-lib/test/TestHarbourProtoBuf/Makefile
^
|
@@ -0,0 +1,7 @@
+# -*- Mode: makefile-gmake -*-
+
+PKGS = libglibutil
+EXE = TestHarbourProtoBuf
+HARBOUR_SRC = HarbourProtoBuf.cpp
+
+include ../Makefile.common
|
[-]
[+]
|
Added |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/harbour-lib/test/TestHarbourProtoBuf/TestHarbourProtoBuf.cpp
^
|
@@ -0,0 +1,168 @@
+/*
+ * 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 "HarbourProtoBuf.h"
+
+#include <glib.h>
+
+/*==========================================================================*
+ * null
+ *==========================================================================*/
+
+static
+void
+test_null(
+ void)
+{
+ g_assert(!HarbourProtoBuf::appendVarInt(NULL, 0));
+ g_assert(!HarbourProtoBuf::appendVarIntKeyValue(NULL, 0, 0));
+ g_assert(!HarbourProtoBuf::appendDelimitedValue(NULL, QByteArray()));
+ g_assert(!HarbourProtoBuf::appendDelimitedKeyValue(NULL,
+ HarbourProtoBuf::TYPE_DELIMITED, QByteArray()));
+ g_assert(!HarbourProtoBuf::parseVarInt(NULL, NULL));
+ g_assert(!HarbourProtoBuf::parseDelimitedValue(NULL, NULL));
+}
+
+/*==========================================================================*
+ * int
+ *==========================================================================*/
+
+static
+void
+test_int(
+ void)
+{
+ QByteArray buf;
+ GUtilRange range;
+ quint64 res;
+
+ static const guint8 enc0[] = { 0 };
+
+ g_assert(HarbourProtoBuf::appendVarInt(&buf, 0) == &buf);
+ g_assert(buf == QByteArray::fromRawData((char*)enc0, sizeof(enc0)));
+
+ range.end = (range.ptr = enc0);
+ g_assert(!HarbourProtoBuf::parseVarInt(&range, NULL));
+ range.end = (range.ptr = enc0);
+
+ res = 42;
+ g_assert(!HarbourProtoBuf::parseVarInt(&range, &res));
+ g_assert_cmpuint(res, == ,0);
+
+ range.end = (range.ptr = enc0) + sizeof(enc0);
+ g_assert(HarbourProtoBuf::parseVarInt(&range, NULL));
+ g_assert(range.ptr == range.end);
+
+ res = 42;
+ range.end = (range.ptr = enc0) + sizeof(enc0);
+ g_assert(HarbourProtoBuf::parseVarInt(&range, &res));
+ g_assert_cmpuint(res, == ,0);
+
+ static const guint8 enc257[] = { 0x82, 0x01 };
+
+ buf.clear();
+ g_assert(HarbourProtoBuf::appendVarInt(&buf, 257) == &buf);
+ g_assert(buf == QByteArray::fromRawData((char*)enc257, sizeof(enc257)));
+
+ res = 42;
+ range.end = (range.ptr = enc257) + 1;
+ g_assert(!HarbourProtoBuf::parseVarInt(&range, &res));
+ g_assert_cmpuint(res, == ,0);
+
+ res = 42;
+ range.end = (range.ptr = enc257) + sizeof(enc257);
+ g_assert(HarbourProtoBuf::parseVarInt(&range, &res));
+ g_assert(range.ptr == range.end);
+ g_assert_cmpuint(res, == ,257);
+}
+
+/*==========================================================================*
+ * delimited
+ *==========================================================================*/
+
+static
+void
+test_delimited(
+ void)
+{
+ QByteArray buf;
+ GUtilRange range;
+ GUtilData payload;
+ static const guint8 value[] = { 0x01, 0x02 };
+ static const guint8 encodedValue[] = { 0x02, 0x01, 0x02 };
+
+ g_assert(HarbourProtoBuf::appendDelimitedValue(&buf,
+ QByteArray::fromRawData((char*)value, sizeof(value))) == &buf);
+ g_assert(buf == QByteArray::fromRawData((char*)encodedValue,
+ sizeof(encodedValue)));
+
+ range.end = (range.ptr = encodedValue);
+ g_assert(!HarbourProtoBuf::parseDelimitedValue(&range, NULL));
+ g_assert(range.ptr == encodedValue);
+
+ range.end = (range.ptr = encodedValue) + sizeof(encodedValue) - 1;
+ g_assert(!HarbourProtoBuf::parseDelimitedValue(&range, NULL));
+ g_assert(range.ptr == encodedValue);
+
+ range.end = (range.ptr = encodedValue) + sizeof(encodedValue);
+ g_assert(HarbourProtoBuf::parseDelimitedValue(&range, NULL));
+
+ memset(&payload, 0, sizeof(payload));
+ range.end = (range.ptr = encodedValue) + sizeof(encodedValue);
+ g_assert(HarbourProtoBuf::parseDelimitedValue(&range, &payload));
+ g_assert_cmpuint(payload.size, == ,sizeof(value));
+ g_assert(!memcmp(payload.bytes, value, sizeof(value)));
+}
+
+/*==========================================================================*
+ * Common
+ *==========================================================================*/
+
+#define TEST_(name) "/HarbourProtoBuf/" name
+
+int main(int argc, char* argv[])
+{
+ g_test_init(&argc, &argv, NULL);
+ g_test_add_func(TEST_("null"), test_null);
+ g_test_add_func(TEST_("int"), test_int);
+ g_test_add_func(TEST_("delimited"), test_delimited);
+ return g_test_run();
+}
+
+/*
+ * Local Variables:
+ * mode: C++
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
|
[-]
[+]
|
Added |
_service:tar_git:harbour-foilnotes-1.1.1.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-foilnotes-1.1.1.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
+ };
+
+ // Lower case is assumed
+ const QByteArray hex("0102030405060708090a0b0c0d0e0f1011121314");
+
+ 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));
+ const QByteArray out(HarbourUtil::toHexBytes(data, sizeof(data)));
+ g_assert_cmpstr(out.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-foilnotes-1.1.1.tar.gz/harbour-lib/test/coverage/run
^
|
@@ -5,7 +5,9 @@
TESTS="\
TestHarbourBase32 \
-TestHarbourBase45"
+TestHarbourBase45 \
+TestHarbourProtoBuf \
+TestHarbourUtil"
function err() {
echo "*** ERROR!" $1
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/libglibutil/LICENSE
^
|
@@ -1,4 +1,5 @@
-Copyright (C) 2014-2021 Jolla Ltd.
+Copyright (C) 2014-2022 Jolla Ltd.
+Copyright (C) 2023 Slava Monich <slava@monich.com>
You may use this file under the terms of BSD license as follows:
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/libglibutil/Makefile
^
|
@@ -20,7 +20,7 @@
VERSION_MAJOR = 1
VERSION_MINOR = 0
-VERSION_RELEASE = 55
+VERSION_RELEASE = 68
# Version for pkg-config
PCVERSION = $(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_RELEASE)
@@ -53,7 +53,8 @@
gutil_misc.c \
gutil_ring.c \
gutil_strv.c \
- gutil_timenotify.c
+ gutil_timenotify.c \
+ gutil_weakref.c
#
# Directories
@@ -93,7 +94,7 @@
RELEASE_LDFLAGS = $(FULL_LDFLAGS) $(RELEASE_FLAGS)
DEBUG_CFLAGS = $(FULL_CFLAGS) $(DEBUG_FLAGS) -DDEBUG
RELEASE_CFLAGS = $(FULL_CFLAGS) $(RELEASE_FLAGS) -O2
-COVERAGE_CFLAGS = $(FULL_CFLAGS) $(COVERAGE_FLAGS) --coverage
+COVERAGE_CFLAGS = $(FULL_CFLAGS) $(COVERAGE_FLAGS) -O0 --coverage
#
# Files
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/libglibutil/debian/changelog
^
|
@@ -1,3 +1,81 @@
+libglibutil (1.0.68) unstable; urgency=low
+
+ * Added gutil_weakref module
+ * Fixed a few compilation warnings
+ * Packaging tweaks
+
+ -- Slava Monich <slava.monich@jolla.com> Sat, 04 Feb 2023 04:26:45 +0200
+
+libglibutil (1.0.67) unstable; urgency=low
+
+ * Added gutil_log_dump_bytes()
+
+ -- Slava Monich <slava.monich@jolla.com> Fri, 15 Jul 2022 03:02:33 +0300
+
+libglibutil (1.0.66) unstable; urgency=low
+
+ * Bumped debhelper compat level to 7
+
+ -- Slava Monich <slava.monich@jolla.com> Fri, 15 Jul 2022 03:02:33 +0300
+
+libglibutil (1.0.65) unstable; urgency=low
+
+ * Fixed a Musl compatibility issue
+
+ -- Slava Monich <slava.monich@jolla.com> Thu, 16 Jun 2022 02:12:22 +0300
+
+libglibutil (1.0.64) unstable; urgency=low
+
+ * Resolved a mysterious parallel build issue
+
+ -- Slava Monich <slava.monich@jolla.com> Tue, 17 May 2022 03:56:50 +0300
+
+libglibutil (1.0.63) unstable; urgency=low
+
+ * Added gutil_bytes_has_prefix()
+ * Added gutil_bytes_has_suffix()
+
+ -- Slava Monich <slava.monich@jolla.com> Sat, 23 Apr 2022 21:24:25 +0300
+
+libglibutil (1.0.62) unstable; urgency=low
+
+ * Added gutil_strlen0()
+ * Added gutil_strv_find_last()
+ * Added gutil_strv_remove_dups()
+
+ -- Slava Monich <slava.monich@jolla.com> Sun, 13 Mar 2022 21:59:26 +0200
+
+libglibutil (1.0.61) unstable; urgency=low
+
+ * Added gutil_strv_remove()
+
+ -- Slava Monich <slava.monich@jolla.com> Thu, 25 Nov 2021 18:31:18 +0200
+
+libglibutil (1.0.60) unstable; urgency=low
+
+ * Housekeeping release
+
+ -- Slava Monich <slava.monich@jolla.com> Mon, 22 Nov 2021 23:37:14 +0200
+
+libglibutil (1.0.58) unstable; urgency=low
+
+ * Don't check upper bound when setting log level from the envvironment
+
+ -- Slava Monich <slava.monich@jolla.com> Wed, 17 Nov 2021 13:17:45 +0200
+
+libglibutil (1.0.57) unstable; urgency=low
+
+ * Fixed unit tests for older 32-bit systems
+
+ -- Slava Monich <slava.monich@jolla.com> Mon, 08 Nov 2021 02:28:37 +0200
+
+libglibutil (1.0.56) unstable; urgency=low
+
+ * Added gutil_parse_int64()
+ * Added gutil_parse_uint64()
+
+ -- Slava Monich <slava.monich@jolla.com> Sun, 03 Oct 2021 20:18:15 +0300
+
libglibutil (1.0.55) unstable; urgency=low
* Added gutil_log_dump()
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/libglibutil/debian/compat
^
|
@@ -1 +1 @@
-5
+7
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/libglibutil/debian/copyright
^
|
@@ -1,4 +1,5 @@
-Copyright (C) 2014-2021 Jolla Ltd.
+Copyright (C) 2014-2022 Jolla Ltd.
+Copyright (C) 2023 Slava Monich <slava@monich.com>
You may use this file under the terms of BSD license as follows:
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/libglibutil/include/gutil_log.h
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2014-2021 Jolla Ltd.
- * Copyright (C) 2014-2021 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2014-2022 Jolla Ltd.
+ * Copyright (C) 2014-2022 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -147,6 +147,13 @@
const void* data,
gsize size); /* Since 1.0.55 */
+void
+gutil_log_dump_bytes(
+ const GLogModule* module,
+ int level,
+ const char* prefix,
+ GBytes* bytes); /* Since 1.0.67 */
+
/* Check if logging is enabled for the specified log level */
gboolean
gutil_log_enabled(
@@ -328,10 +335,13 @@
GLOG_LEVEL_DEBUG, "%s() " f, __FUNCTION__, ##args)
# define GDEBUG_DUMP(buf,n) gutil_log_dump(GLOG_MODULE_CURRENT, \
GLOG_LEVEL_DEBUG, NULL, buf, n) /* Since 1.0.55 */
+# define GDEBUG_DUMP_BYTES(b) gutil_log_dump_bytes(GLOG_MODULE_CURRENT, \
+ GLOG_LEVEL_DEBUG, NULL, b) /* Since 1.0.67 */
# else
# define GDEBUG(f,args...) GLOG_NOTHING
# define GDEBUG_(f,args...) GLOG_NOTHING
# define GDEBUG_DUMP(buf,n) GLOG_NOTHING /* Since 1.0.55 */
+# define GDEBUG_DUMP_BYTES(b) GLOG_NOTHING /* Since 1.0.67 */
# endif /* GUTIL_LOG_DEBUG */
#else
# define GDEBUG_ GDEBUG
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/libglibutil/include/gutil_misc.h
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2016-2021 Jolla Ltd.
- * Copyright (C) 2016-2021 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2016-2022 Jolla Ltd.
+ * Copyright (C) 2016-2022 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -76,6 +76,18 @@
unsigned int* value); /* Since 1.0.53 */
gboolean
+gutil_parse_int64(
+ const char* str,
+ int base,
+ gint64* value); /* Since 1.0.56 */
+
+gboolean
+gutil_parse_uint64(
+ const char* str,
+ int base,
+ guint64* value); /* Since 1.0.56 */
+
+gboolean
gutil_data_equal(
const GUtilData* data1,
const GUtilData* data2); /* Since 1.0.31 */
@@ -123,6 +135,18 @@
GBytes* bytes,
const GUtilData* data); /* Since 1.0.41 */
+gboolean
+gutil_bytes_has_prefix(
+ GBytes* bytes,
+ const void* data,
+ gsize size); /* Since 1.0.63 */
+
+gboolean
+gutil_bytes_has_suffix(
+ GBytes* bytes,
+ const void* data,
+ gsize size); /* Since 1.0.63 */
+
gsize
gutil_ptrv_length(
const void* ptrv); /* Since 1.0.50 */
@@ -137,6 +161,10 @@
gsize size); /* Since 1.0.52 */
gsize
+gutil_strlen0(
+ const char* str); /* Since 1.0.62 */
+
+gsize
gutil_range_init_with_bytes(
GUtilRange* range,
GBytes* bytes); /* Since 1.0.55 */
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/libglibutil/include/gutil_strv.h
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2014-2020 Jolla Ltd.
- * Copyright (C) 2014-2020 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2014-2022 Jolla Ltd.
+ * Copyright (C) 2014-2022 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -69,6 +69,15 @@
const char* s);
/**
+ * Returns index of the last occurrence of specified string in the string
+ * array, or -1 if the string is not found.
+ */
+int
+gutil_strv_find_last(
+ const GStrV* sv,
+ const char* s); /* Since 1.0.62 */
+
+/**
* Checks if string array contains the specified string.
*/
gboolean
@@ -107,6 +116,19 @@
G_GNUC_WARN_UNUSED_RESULT;
/**
+ * Removes one or all matching strings from the array and frees them.
+ */
+GStrV*
+gutil_strv_remove(
+ GStrV* sv,
+ const char* s,
+ gboolean remove_all) /* Since 1.0.61 */
+ G_GNUC_WARN_UNUSED_RESULT;
+
+#define gutil_strv_remove_one(sv, s) gutil_strv_remove(sv, s, FALSE)
+#define gutil_strv_remove_all(sv, s) gutil_strv_remove(sv, s, TRUE)
+
+/**
* Checks two string arrays for equality.
*/
gboolean
@@ -115,6 +137,13 @@
const GStrV* sv2);
/**
+ * Removes all duplicates from the string array.
+ */
+GStrV*
+gutil_strv_remove_dups(
+ GStrV* sv); /* Since 1.0.62 */
+
+/**
* Sorts the string array
*/
GStrV*
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/libglibutil/include/gutil_types.h
^
|
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2014-2021 Jolla Ltd.
- * Copyright (C) 2014-2021 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2023 Slava Monich <slava@monich.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -48,6 +48,7 @@
typedef struct gutil_inotify_watch GUtilInotifyWatch;
typedef struct gutil_ring GUtilRing;
typedef struct gutil_time_notify GUtilTimeNotify;
+typedef struct gutil_weakref GUtilWeakRef; /* Since 1.0.68 */
typedef struct gutil_data {
const guint8* bytes;
|
[-]
[+]
|
Added |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/libglibutil/include/gutil_weakref.h
^
|
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2023 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 HOLDERS 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 GUTIL_WEAKREF_H
+#define GUTIL_WEAKREF_H
+
+#include "gutil_types.h"
+
+/*
+ * Ref-countable weak reference can be used to avoid calling g_weak_ref_set()
+ * too often because it grabs global weak_locations_lock for exclusive access.
+ * Note that g_weak_ref_set() is also invoked internally by g_weak_ref_init()
+ * and g_weak_ref_clear().
+ *
+ * g_weak_ref_get() on the other hand only acquires weak_locations_lock
+ * for read-only access which is less of a bottleneck in a multi-threaded
+ * environment. And it's generally significantly simpler and faster than
+ * g_weak_ref_set().
+ *
+ * Since 1.0.68
+ */
+
+G_BEGIN_DECLS
+
+GUtilWeakRef*
+gutil_weakref_new(
+ gpointer obj);
+
+GUtilWeakRef*
+gutil_weakref_ref(
+ GUtilWeakRef* ref);
+
+void
+gutil_weakref_unref(
+ GUtilWeakRef* ref);
+
+gpointer
+gutil_weakref_get(
+ GUtilWeakRef* ref);
+
+void
+gutil_weakref_set(
+ GUtilWeakRef* ref,
+ gpointer obj);
+
+G_END_DECLS
+
+#endif /* GUTIL_WEAKREF_H */
+
+/*
+ * Local Variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/libglibutil/rpm/libglibutil.spec
^
|
@@ -1,13 +1,19 @@
Name: libglibutil
-Version: 1.0.55
+Version: 1.0.68
Release: 0
Summary: Library of glib utilities
License: BSD
-URL: https://git.sailfishos.org/mer-core/libglibutil
+URL: https://github.com/sailfishos/libglibutil
Source: %{name}-%{version}.tar.bz2
+BuildRequires: pkgconfig
BuildRequires: pkgconfig(glib-2.0)
+
+# license macro requires rpm >= 4.11
+BuildRequires: pkgconfig(rpm)
+%define license_support %(pkg-config --exists 'rpm >= 4.11'; echo $?)
+
Requires(post): /sbin/ldconfig
Requires(postun): /sbin/ldconfig
@@ -17,7 +23,6 @@
%package devel
Summary: Development library for %{name}
Requires: %{name} = %{version}
-Requires: pkgconfig
%description devel
This package contains the development library for %{name}.
@@ -29,7 +34,6 @@
make %{_smp_mflags} LIBDIR=%{_libdir} KEEP_SYMBOLS=1 release pkgconfig
%install
-rm -rf %{buildroot}
make LIBDIR=%{_libdir} DESTDIR=%{buildroot} install-dev
%check
@@ -42,9 +46,13 @@
%files
%defattr(-,root,root,-)
%{_libdir}/%{name}.so.*
+%if %{license_support} == 0
+%license LICENSE
+%endif
%files devel
%defattr(-,root,root,-)
+%dir %{_includedir}/gutil
%{_libdir}/pkgconfig/*.pc
%{_libdir}/%{name}.so
%{_includedir}/gutil/*.h
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/libglibutil/src/gutil_log.c
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2014-2021 Jolla Ltd.
- * Copyright (C) 2014-2021 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2014-2022 Jolla Ltd.
+ * Copyright (C) 2014-2022 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -14,8 +14,8 @@
* 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.
+ * 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
@@ -490,6 +490,29 @@
return FALSE;
}
+static
+void
+gutil_log_dump2(
+ const GLogModule* module,
+ int level,
+ const char* prefix,
+ const void* data,
+ gsize size)
+{
+ const guint8* ptr = data;
+ guint off = 0;
+
+ if (!prefix) prefix = "";
+ while (size > 0) {
+ char buf[GUTIL_HEXDUMP_BUFSIZE];
+ const guint consumed = gutil_hexdump(buf, ptr + off, size);
+
+ gutil_log(module, level, "%s%04X: %s", prefix, off, buf);
+ size -= consumed;
+ off += consumed;
+ }
+}
+
void
gutil_log_dump(
const GLogModule* module,
@@ -499,18 +522,21 @@
gsize size) /* Since 1.0.55 */
{
if (gutil_log_enabled(module, level)) {
- const guint8* ptr = data;
- guint off = 0;
+ gutil_log_dump2(module, level, prefix, data, size);
+ }
+}
- if (!prefix) prefix = "";
- while (size > 0) {
- char buf[GUTIL_HEXDUMP_BUFSIZE];
- const guint consumed = gutil_hexdump(buf, ptr + off, size);
-
- gutil_log(module, level, "%s%04X: %s", prefix, off, buf);
- size -= consumed;
- off += consumed;
- }
+void
+gutil_log_dump_bytes(
+ const GLogModule* module,
+ int level,
+ const char* prefix,
+ GBytes* bytes) /* Since 1.0.67 */
+{
+ if (G_LIKELY(bytes) && gutil_log_enabled(module, level)) {
+ gsize size = 0;
+ const guint8* data = g_bytes_get_data(bytes, &size);
+ gutil_log_dump2(module, level, prefix, data, size);
}
}
@@ -676,7 +702,7 @@
int val = 0;
if (gutil_parse_int(getenv("GUTIL_LOG_DEFAULT_LEVEL"), 0, &val) &&
- val >= GLOG_LEVEL_INHERIT && val <= GLOG_LEVEL_VERBOSE) {
+ val >= GLOG_LEVEL_INHERIT) {
gutil_log_default.level = val;
GDEBUG("Default log level %d", val);
}
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/libglibutil/src/gutil_misc.c
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2016-2021 Jolla Ltd.
- * Copyright (C) 2016-2021 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2016-2022 Jolla Ltd.
+ * Copyright (C) 2016-2022 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -35,6 +35,7 @@
#include <glib-object.h>
#include <ctype.h>
+#include <errno.h>
#include <limits.h>
void
@@ -181,17 +182,57 @@
int base,
int* value) /* Since 1.0.30 */
{
+ gint64 ll;
+
+ if (gutil_parse_int64(str, base, &ll) && ll >= INT_MIN && ll <= INT_MAX) {
+ if (value) {
+ *value = (int)ll;
+ }
+ return TRUE;
+ }
+ return FALSE;
+}
+
+gboolean
+gutil_parse_uint(
+ const char* str,
+ int base,
+ unsigned int* value) /* Since 1.0.53 */
+{
+ guint64 ull;
+
+ if (gutil_parse_uint64(str, base, &ull) && ull <= UINT_MAX) {
+ if (value) {
+ *value = (unsigned int)ull;
+ }
+ return TRUE;
+ }
+ return FALSE;
+}
+
+gboolean
+gutil_parse_int64(
+ const char* str,
+ int base,
+ gint64* value) /* Since 1.0.56 */
+{
gboolean ok = FALSE;
- if (str && str[0]) {
+ if (str && *str) {
char* tmp = NULL;
char* end = NULL;
const char* stripped = gutil_strstrip(str, &tmp);
- const gint64 ll = g_ascii_strtoll(stripped, &end, base);
+ gint64 ll;
- ok = !*end && ll >= INT_MIN && ll <= INT_MAX;
- if (ok && value) {
- *value = (int)ll;
+ errno = 0;
+ ll = g_ascii_strtoll(stripped, &end, base);
+ if (end && !*end &&
+ !((ll == G_MAXINT64 || ll == G_MININT64) && errno == ERANGE) &&
+ !(ll == 0 && errno == EINVAL)) {
+ if (value) {
+ *value = ll;
+ }
+ ok = TRUE;
}
g_free(tmp);
}
@@ -199,22 +240,35 @@
}
gboolean
-gutil_parse_uint(
+gutil_parse_uint64(
const char* str,
int base,
- unsigned int* value) /* Since 1.0.53 */
+ guint64* value) /* Since 1.0.56 */
{
gboolean ok = FALSE;
- if (str && str[0]) {
+ /*
+ * Sorry, we don't accept minus as a part of an unsigned number
+ * (unlike strtoul)
+ */
+ if (str && *str && *str != '-') {
char* tmp = NULL;
- char* end = NULL;
const char* stripped = gutil_strstrip(str, &tmp);
- const guint64 ull = g_ascii_strtoull(stripped, &end, base);
- ok = !*end && ull <= UINT_MAX;
- if (ok && value) {
- *value = (unsigned int)ull;
+ if (*stripped != '-') {
+ char* end = NULL;
+ guint64 ull;
+
+ errno = 0;
+ ull = g_ascii_strtoull(stripped, &end, base);
+ if (end && !*end &&
+ !(ull == G_MAXUINT64 && errno == ERANGE) &&
+ !(ull == 0 && errno == EINVAL)) {
+ if (value) {
+ *value = ull;
+ }
+ ok = TRUE;
+ }
}
g_free(tmp);
}
@@ -457,6 +511,52 @@
}
}
+gboolean
+gutil_bytes_has_prefix(
+ GBytes* bytes,
+ const void* data,
+ gsize size) /* Since 1.0.63 */
+{
+ if (!bytes) {
+ /* NULL GBytes has neither prefix nor suffix, even an empty one */
+ return FALSE;
+ } else if (!size) {
+ /*
+ * That's largely a philosophical question - can anything have
+ * an empty prefix? Let's assume that the answer is yes. And
+ * then if anything can have such a prefix, everything has it.
+ * Right? Except for NULL GBytes which doesn't have anything
+ * as said earlier.
+ */
+ return TRUE;
+ } else {
+ gsize bytes_size;
+ const guint8* contents = g_bytes_get_data(bytes, &bytes_size);
+
+ return (bytes_size >= size) && !memcmp(contents, data, size);
+ }
+}
+
+gboolean
+gutil_bytes_has_suffix(
+ GBytes* bytes,
+ const void* data,
+ gsize size) /* Since 1.0.63 */
+{
+ /* Treat an empty suffix the same way as an empty prefix */
+ if (!bytes) {
+ return FALSE;
+ } else if (!size) {
+ return TRUE;
+ } else {
+ gsize bytes_size;
+ const guint8* contents = g_bytes_get_data(bytes, &bytes_size);
+
+ return (bytes_size >= size) &&
+ !memcmp(contents + (bytes_size - size), data, size);
+ }
+}
+
/* Calculates the length of NULL-terminated array of pointers */
gsize
gutil_ptrv_length(
@@ -502,6 +602,14 @@
}
}
+/* NULL-tolerant version of strlen */
+gsize
+gutil_strlen0(
+ const char* str) /* Since 1.0.62 */
+{
+ return str ? strlen(str) : 0;
+}
+
gsize
gutil_range_init_with_bytes(
GUtilRange* range,
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/libglibutil/src/gutil_strv.c
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2014-2020 Jolla Ltd.
- * Copyright (C) 2014-2020 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2014-2022 Jolla Ltd.
+ * Copyright (C) 2014-2022 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -88,9 +88,10 @@
const GStrV* sv,
const char* s)
{
- if (sv && s) {
+ if (G_LIKELY(sv) && G_LIKELY(s)) {
int i = 0;
const GStrV* ptr;
+
for (ptr = sv; *ptr; ptr++, i++) {
if (!strcmp(*ptr, s)) {
return i;
@@ -100,6 +101,36 @@
return -1;
}
+/* Helper for gutil_strv_find_last and friends */
+static
+int
+gutil_strv_find_last_impl(
+ const GStrV* sv,
+ const char* s,
+ int i /* exclisive */)
+{
+ while (i > 0) {
+ if (!strcmp(sv[--i], s)) {
+ return i;
+ }
+ }
+ return -1;
+}
+
+/**
+ * Returns index of the last occurrence of specified string in the string
+ * array, or -1 if the string is not found.
+ */
+int
+gutil_strv_find_last(
+ const GStrV* sv,
+ const char* s) /* Since 1.0.62 */
+{
+ /* NULL sv is handled by gutil_strv_length() */
+ return G_LIKELY(s) ? gutil_strv_find_last_impl(sv, s,
+ gutil_strv_length(sv)) : -1;
+}
+
/**
* Checks if string array contains the specified string.
*/
@@ -158,6 +189,22 @@
return sv;
}
+/* Internal helper for removal functions */
+static
+GStrV*
+gutil_strv_remove_impl(
+ GStrV* sv,
+ guint pos,
+ guint len,
+ gboolean free_string)
+{
+ if (free_string) {
+ g_free(sv[pos]);
+ }
+ memmove(sv + pos, sv + pos + 1, sizeof(char*)*(len - pos));
+ return g_realloc(sv, sizeof(char*)*len);
+}
+
/**
* Removes the string from the specified position in the array.
*/
@@ -169,15 +216,66 @@
{
if (G_LIKELY(sv) && G_LIKELY(pos >= 0)) {
const int len = gutil_strv_length(sv);
+
if (pos < len) {
- if (free_string) {
- g_free(sv[pos]);
+ sv = gutil_strv_remove_impl(sv, pos, len, free_string);
+ }
+ }
+ return sv;
+}
+
+/**
+ * Removes one or all matching strings from the array and frees them.
+ */
+GStrV*
+gutil_strv_remove(
+ GStrV* sv,
+ const char* s,
+ gboolean remove_all)
+{
+ if (G_LIKELY(sv) && G_LIKELY(s)) {
+ const int pos = gutil_strv_find(sv, s);
+
+ if (pos >= 0) {
+ guint len = gutil_strv_length(sv);
+
+ sv = gutil_strv_remove_impl(sv, pos, len, TRUE);
+ if (remove_all) {
+ int i, l;
+
+ len--;
+ l = len - pos;
+ while ((i = gutil_strv_find_last_impl(sv + pos, s, l)) >= 0) {
+ sv = gutil_strv_remove_impl(sv, pos + i, len--, TRUE);
+ l = i;
+ }
}
- if (pos < len-1) {
- memmove(sv + pos, sv + pos + 1, sizeof(char*)*(len-pos-1));
+ }
+ }
+ return sv;
+}
+
+/**
+ * Removes all duplicates from the string array.
+ */
+GStrV*
+gutil_strv_remove_dups(
+ GStrV* sv) /* Since 1.0.62 */
+{
+ if (G_LIKELY(sv)) {
+ guint len = gutil_strv_length(sv), pos = 0, l = len;
+
+ while (pos < len) {
+ int i = gutil_strv_find_last_impl(sv + pos + 1, sv[pos], l - 1);
+
+ if (i < 0) {
+ /* Done with this string, switch to the next one */
+ pos++;
+ l = len - pos;
+ } else {
+ sv = gutil_strv_remove_impl(sv, pos + 1 + i, len--, TRUE);
+ l = i + 1;
}
- sv[len-1] = NULL;
- sv = g_realloc(sv, sizeof(char*)*len);
}
}
return sv;
|
[-]
[+]
|
Added |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/libglibutil/src/gutil_weakref.c
^
|
@@ -0,0 +1,115 @@
+/*
+ * Copyright (C) 2023 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 HOLDERS 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 "gutil_weakref.h"
+#include "gutil_log.h"
+#include "gutil_macros.h"
+
+#include <glib-object.h>
+
+/*
+ * Ref-countable weak reference can be used to avoid calling g_weak_ref_set()
+ * too often because it grabs global weak_locations_lock for exclusive access.
+ * Note that g_weak_ref_set() is also invoked internally by g_weak_ref_init()
+ * and g_weak_ref_clear().
+ *
+ * g_weak_ref_get() on the other hand only acquires weak_locations_lock
+ * for read-only access which is less of a bottleneck in a multi-threaded
+ * environment. And it's generally significantly simpler and faster than
+ * g_weak_ref_set().
+ *
+ * Since 1.0.68
+ */
+
+struct gutil_weakref {
+ gint ref_count;
+ GWeakRef weak_ref;
+};
+
+GUtilWeakRef*
+gutil_weakref_new(
+ gpointer obj)
+{
+ GUtilWeakRef* self = g_slice_new(GUtilWeakRef);
+
+ g_atomic_int_set(&self->ref_count, 1);
+ g_weak_ref_init(&self->weak_ref, obj);
+ return self;
+}
+
+GUtilWeakRef*
+gutil_weakref_ref(
+ GUtilWeakRef* self)
+{
+ if (G_LIKELY(self)) {
+ GASSERT(self->ref_count > 0);
+ g_atomic_int_inc(&self->ref_count);
+ }
+ return self;
+}
+
+void
+gutil_weakref_unref(
+ GUtilWeakRef* self)
+{
+ if (G_LIKELY(self)) {
+ GASSERT(self->ref_count > 0);
+ if (g_atomic_int_dec_and_test(&self->ref_count)) {
+ g_weak_ref_clear(&self->weak_ref);
+ gutil_slice_free(self);
+ }
+ }
+}
+
+gpointer
+gutil_weakref_get(
+ GUtilWeakRef* self)
+{
+ return G_LIKELY(self) ? g_weak_ref_get(&self->weak_ref) : NULL;
+}
+
+void
+gutil_weakref_set(
+ GUtilWeakRef* self,
+ gpointer obj)
+{
+ if (G_LIKELY(self)) {
+ g_weak_ref_set(&self->weak_ref, obj);
+ }
+}
+
+/*
+ * Local Variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/libglibutil/test/Makefile
^
|
@@ -12,3 +12,4 @@
@$(MAKE) -C test_misc $*
@$(MAKE) -C test_ring $*
@$(MAKE) -C test_strv $*
+ @$(MAKE) -C test_weakref $*
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/libglibutil/test/common/Makefile
^
|
@@ -52,7 +52,7 @@
$(shell pkg-config --cflags $(PKGS))
FULL_LDFLAGS = $(BASE_LDFLAGS)
LIBS = $(shell pkg-config --libs $(PKGS))
-QUIET_MAKE = make --no-print-directory
+QUIET_MAKE = $(MAKE) --no-print-directory
DEBUG_FLAGS = -g
RELEASE_FLAGS =
COVERAGE_FLAGS = -g
@@ -134,7 +134,7 @@
rm -fr $(BUILD_DIR)
cleaner: clean
- @make -C $(LIB_DIR) clean
+ @$(MAKE) -C $(LIB_DIR) clean
test_banner:
@echo "===========" $(EXE) "=========== "
@@ -185,10 +185,10 @@
$(LD) $(COVERAGE_LDFLAGS) $(COVERAGE_OBJS) $< $(LIBS) -o $@
debug_lib:
- @make $(SUBMAKE_OPTS) -C $(LIB_DIR) debug
+ @$(MAKE) $(SUBMAKE_OPTS) -C $(LIB_DIR) debug
release_lib:
- @make $(SUBMAKE_OPTS) -C $(LIB_DIR) release
+ @$(MAKE) $(SUBMAKE_OPTS) -C $(LIB_DIR) release
coverage_lib:
- @make $(SUBMAKE_OPTS) -C $(LIB_DIR) coverage
+ @$(MAKE) $(SUBMAKE_OPTS) -C $(LIB_DIR) coverage
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/libglibutil/test/common/test_common.h
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2016-2018 Jolla Ltd.
- * Copyright (C) 2016-2018 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2016-2022 Jolla Ltd.
+ * Copyright (C) 2016-2022 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -14,8 +14,8 @@
* 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.
+ * 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
@@ -58,6 +58,7 @@
/* Macros */
#define TEST_INIT_DATA(a,b) ((a).bytes = (void*)(b), (a).size = sizeof(b))
+#define TEST_ARRAY_AND_SIZE(a) (a), sizeof(a)
#endif /* TEST_COMMON_H */
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/libglibutil/test/coverage/run
^
|
@@ -13,7 +13,8 @@
test_log \
test_misc \
test_ring \
-test_strv"
+test_strv \
+test_weakref"
FLAVOR="coverage"
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/libglibutil/test/test_ints/test_ints.c
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2017 Jolla Ltd.
- * Contact: Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2017-2022 Jolla Ltd.
+ * Copyright (C) 2017-2022 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -13,9 +13,9 @@
* 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 name of Jolla Ltd nor the names of its contributors may
- * be used to endorse or promote products derived from this software
- * without specific prior written permission.
+ * 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
@@ -33,6 +33,7 @@
#include "test_common.h"
#include "gutil_ints.h"
+#include "gutil_misc.h"
static TestOpt test_opt;
@@ -141,7 +142,7 @@
g_free(data);
/* And this one duplicates the data because we use test_custom_free: */
- data = g_memdup(a1, sizeof(a1));
+ data = gutil_memdup(a1, sizeof(a1));
i1 = gutil_ints_new_with_free_func(data, G_N_ELEMENTS(a1),
test_custom_free, data);
data = gutil_ints_unref_to_data(i1, &count);
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/libglibutil/test/test_log/Makefile
^
|
@@ -1,6 +1,6 @@
# -*- Mode: makefile-gmake -*-
-CFLAGS += -DGLOG_LEVEL_MAX=GLOG_LEVEL_VERBOSE
+CFLAGS += -DGLOG_LEVEL_MAX=GLOG_LEVEL_VERBOSE -DGLOG_LEVEL_ASSERT=GLOG_LEVEL_ALWAYS
EXE = test_log
include ../common/Makefile
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/libglibutil/test/test_log/test_log.c
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2017-2021 Jolla Ltd.
- * Copyright (C) 2017-2021 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2017-2022 Jolla Ltd.
+ * Copyright (C) 2017-2022 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -30,16 +30,18 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifdef linux
-# define _GNU_SOURCE /* for fopencookie */
-# define HAVE_TEST_LOG_FILE
-#endif
+#define _GNU_SOURCE /* for fopencookie */
#include "test_common.h"
#include "gutil_strv.h"
#include "gutil_log.h"
+#ifdef __GLIBC__
+/* glibc has writeable stdout */
+# define HAVE_TEST_LOG_FILE
+#endif
+
static TestOpt test_opt;
static GString* test_log_buf;
@@ -304,33 +306,50 @@
void)
{
static const guint8 short_data[] = { 0x01, 0x02, 0x03, 0x04 };
+ static const char short_data_dump[] =
+ " 0000: 01 02 03 04 ....\n";
static const guint8 long_data[] = {
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
0x00
};
+ static const char long_data_dump[] =
+ "0000: 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f "
+ "01234567 89:;<=>?\n"
+ "0010: 00 "
+ ".\n";
const GLogProc fn = gutil_log_func;
+ const GLogModule* log = &gutil_log_default;
+ GBytes* bytes;
+
test_log_buf = g_string_new(NULL);
gutil_log_func = test_log_fn;
- gutil_log_dump(&gutil_log_default, GLOG_LEVEL_NONE, NULL,
- short_data, sizeof(short_data));
+ gutil_log_dump_bytes(log, GLOG_LEVEL_NONE, " ", NULL);
+ gutil_log_dump(log,GLOG_LEVEL_NONE," ",TEST_ARRAY_AND_SIZE(short_data));
g_assert_cmpuint(test_log_buf->len, == ,0);
- gutil_log_dump(&gutil_log_default, GLOG_LEVEL_ALWAYS, " ",
- short_data, sizeof(short_data));
- g_assert_cmpstr(test_log_buf->str, == ,
- " 0000: 01 02 03 04 ....\n");
+ gutil_log_dump(log,GLOG_LEVEL_ALWAYS," ",TEST_ARRAY_AND_SIZE(short_data));
+ g_assert_cmpstr(test_log_buf->str, == ,short_data_dump);
g_string_set_size(test_log_buf, 0);
- gutil_log_dump(&gutil_log_default, GLOG_LEVEL_ALWAYS, NULL,
- long_data, sizeof(long_data));
- g_assert_cmpstr(test_log_buf->str, == ,
- "0000: 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f "
- "01234567 89:;<=>?\n"
- "0010: 00 "
- ".\n");
+ bytes = g_bytes_new_static(TEST_ARRAY_AND_SIZE(short_data));
+ gutil_log_dump_bytes(log, GLOG_LEVEL_NONE, " ", bytes);
+ g_assert_cmpuint(test_log_buf->len, == ,0);
+ gutil_log_dump_bytes(log, GLOG_LEVEL_ALWAYS, " ", bytes);
+ g_assert_cmpstr(test_log_buf->str, == ,short_data_dump);
+ g_bytes_unref(bytes);
+
+ g_string_set_size(test_log_buf, 0);
+ gutil_log_dump(log,GLOG_LEVEL_ALWAYS,NULL,TEST_ARRAY_AND_SIZE(long_data));
+ g_assert_cmpstr(test_log_buf->str, == ,long_data_dump);
+
+ g_string_set_size(test_log_buf, 0);
+ bytes = g_bytes_new_static(TEST_ARRAY_AND_SIZE(long_data));
+ gutil_log_dump_bytes(log, GLOG_LEVEL_ALWAYS, NULL, bytes);
+ g_assert_cmpstr(test_log_buf->str, == ,long_data_dump);
+ g_bytes_unref(bytes);
g_string_free(test_log_buf, TRUE);
test_log_buf = NULL;
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/libglibutil/test/test_misc/test_misc.c
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2016-2021 Jolla Ltd.
- * Copyright (C) 2016-2021 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2016-2022 Jolla Ltd.
+ * Copyright (C) 2016-2022 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -173,6 +173,8 @@
g_assert(!gutil_parse_int("", 0, NULL));
g_assert(!gutil_parse_int("garbage", 0, NULL));
g_assert(!gutil_parse_int("0 trailing garbage", 0, NULL));
+ g_assert(!gutil_parse_int("0", -1, NULL));
+ g_assert(!gutil_parse_int("0", 1, NULL));
g_assert(gutil_parse_int("0", 0, NULL));
g_assert(gutil_parse_int("0", 0, &value));
g_assert_cmpint(value, == ,0);
@@ -207,16 +209,22 @@
g_assert(!gutil_parse_uint("", 0, NULL));
g_assert(!gutil_parse_uint("garbage", 0, NULL));
g_assert(!gutil_parse_uint("0 trailing garbage", 0, NULL));
+ g_assert(!gutil_parse_uint("0", -1, NULL));
+ g_assert(!gutil_parse_uint("0", 1, NULL));
g_assert(gutil_parse_uint("0", 0, NULL));
g_assert(gutil_parse_uint("0", 0, &value));
g_assert_cmpuint(value, == ,0);
g_assert(gutil_parse_uint("42", 0, &value));
g_assert_cmpuint(value, == ,42);
g_assert(!gutil_parse_uint("0x10000000000000000", 0, &value));
+#if defined __SIZEOF_INT__ && __SIZEOF_INT__ == 4
+ g_assert(!gutil_parse_uint("0x100000000", 0, &value));
+#endif
g_assert(!gutil_parse_uint("-2147483649", 0, &value));
g_assert(!gutil_parse_uint("-1", 0, &value));
+ g_assert(!gutil_parse_uint(" -1 ", 0, &value));
g_assert(gutil_parse_uint("4294967295", 0, &value));
- g_assert_cmpuint(value, == ,4294967295);
+ g_assert_cmpuint(value, == ,4294967295U);
g_assert(gutil_parse_uint(" 0x7fffffff ", 0, &value));
g_assert_cmpuint(value, == ,0x7fffffff);
g_assert(gutil_parse_uint(" 7fffffff ", 16, &value));
@@ -228,6 +236,95 @@
}
/*==========================================================================*
+ * parse_int64
+ *==========================================================================*/
+
+static
+void
+test_parse_int64(
+ void)
+{
+ gint64 value;
+
+ g_assert(!gutil_parse_int64(NULL, 0, NULL));
+ g_assert(!gutil_parse_int64("", 0, NULL));
+ g_assert(!gutil_parse_int64("garbage", 0, NULL));
+ g_assert(!gutil_parse_int64("0 trailing garbage", 0, NULL));
+ g_assert(!gutil_parse_int64("0", -1, NULL));
+ g_assert(!gutil_parse_int64("0", 1, NULL));
+ g_assert(gutil_parse_int64("0", 0, NULL));
+ g_assert(gutil_parse_int64("0", 0, &value));
+ g_assert_cmpint(value, == ,0);
+ g_assert(gutil_parse_int64("-1", 0, &value));
+ g_assert_cmpint(value, == ,-1);
+ g_assert(gutil_parse_int64("42", 0, &value));
+ g_assert_cmpint(value, == ,42);
+ g_assert(gutil_parse_int64("-2147483649", 0, &value));
+ g_assert_cmpint(value, == ,G_GINT64_CONSTANT(-2147483649));
+ g_assert(gutil_parse_int64("4294967295", 0, &value));
+ g_assert_cmpint(value, == ,G_GINT64_CONSTANT(4294967295));
+ g_assert(gutil_parse_int64(" 0x7fffffff ", 0, &value));
+ g_assert_cmpint(value, == ,0x7fffffff);
+ g_assert(gutil_parse_int64(" 7fffffff ", 16, &value));
+ g_assert_cmpint(value, == ,0x7fffffff);
+ g_assert(gutil_parse_int64("7ffffffe ", 16, &value));
+ g_assert_cmpint(value, == ,0x7ffffffe);
+ g_assert(gutil_parse_int64("0xffffffff", 0, &value));
+ g_assert_cmpint(value, == ,0xffffffff);
+ g_assert(gutil_parse_int64("-9223372036854775808", 0, &value));
+ g_assert_cmpint(value, == ,0x8000000000000000);
+ g_assert(gutil_parse_int64("9223372036854775807", 0, &value));
+ g_assert_cmpint(value, == ,0x7fffffffffffffff);
+#ifndef _WIN32
+ g_assert(!gutil_parse_int64("0x10000000000000000", 0, &value));
+ g_assert(!gutil_parse_int64("-9223372036854775809", 0, &value));
+ g_assert(!gutil_parse_int64("9223372036854775808", 0, &value));
+#endif
+}
+
+/*==========================================================================*
+ * parse_uint64
+ *==========================================================================*/
+
+static
+void
+test_parse_uint64(
+ void)
+{
+ guint64 value;
+
+ g_assert(!gutil_parse_uint64(NULL, 0, NULL));
+ g_assert(!gutil_parse_uint64("", 0, NULL));
+ g_assert(!gutil_parse_uint64("garbage", 0, NULL));
+ g_assert(!gutil_parse_uint64("0 trailing garbage", 0, NULL));
+ g_assert(!gutil_parse_uint64("0", -1, NULL));
+ g_assert(!gutil_parse_uint64("0", 1, NULL));
+ g_assert(gutil_parse_uint64("0", 0, NULL));
+ g_assert(gutil_parse_uint64("0", 0, &value));
+ g_assert_cmpuint(value, == ,0);
+ g_assert(gutil_parse_uint64("42", 0, &value));
+ g_assert_cmpuint(value, == ,42);
+ g_assert(!gutil_parse_uint64("-2147483649", 0, &value));
+ g_assert(!gutil_parse_uint64("-1", 0, &value));
+ g_assert(!gutil_parse_uint64(" -1 ", 0, &value));
+ g_assert(gutil_parse_uint64("4294967295", 0, &value));
+ g_assert_cmpuint(value, == ,4294967295U);
+ g_assert(!gutil_parse_uint64(" 0x7fffffff ffffffff ", 0, &value));
+ g_assert(gutil_parse_uint64(" 0x7fffffffffffffff ", 0, &value));
+ g_assert_cmpuint(value, == ,0x7fffffffffffffff);
+ g_assert(!gutil_parse_uint64(" 7fffffff ffffffff", 16, &value));
+ g_assert(gutil_parse_uint64(" 7fffffffffffffff ", 16, &value));
+ g_assert_cmpuint(value, == ,0x7fffffffffffffff);
+ g_assert(gutil_parse_uint64("0x100000000", 0, &value));
+ g_assert_cmpuint(value, == ,0x100000000);
+ g_assert(gutil_parse_uint64("0xffffffffffffffff", 0, &value));
+ g_assert_cmpuint(value, == ,0xffffffffffffffff);
+#ifndef _WIN32
+ g_assert(!gutil_parse_uint64("0x10000000000000000", 0, &value));
+#endif
+}
+
+/*==========================================================================*
* data_equal
*==========================================================================*/
@@ -582,6 +679,20 @@
}
/*==========================================================================*
+ * strlen
+ *==========================================================================*/
+
+static
+void
+test_strlen(
+ void)
+{
+ g_assert(!gutil_strlen0(NULL));
+ g_assert_cmpuint(gutil_strlen0(""), == ,0);
+ g_assert_cmpuint(gutil_strlen0("1"), == ,1);
+}
+
+/*==========================================================================*
* range_init
*==========================================================================*/
@@ -658,6 +769,70 @@
}
/*==========================================================================*
+ * bytes_prefix
+ *==========================================================================*/
+
+static
+void
+test_bytes_prefix(
+ void)
+{
+ static const guint8 data[] = { 0x01, 0x02, 0x03, 0x04 };
+ static const guint8 prefix[] = { 0x01, 0x02 };
+ static const guint8 not_prefix[] = { 0x03, 0x04 };
+ static const guint8 too_long[] = { 0x01, 0x02, 0x03, 0x04, 0x05 };
+ GBytes* empty = g_bytes_new_static(NULL, 0);
+ GBytes* bytes = g_bytes_new_static(TEST_ARRAY_AND_SIZE(data));
+
+ /* NULL GBytes doesn't have any prefix, even an empty one */
+ g_assert(!gutil_bytes_has_prefix(NULL, NULL, 0));
+
+ /* Anything has an empty prefix */
+ g_assert(gutil_bytes_has_prefix(empty, NULL, 0));
+ g_assert(gutil_bytes_has_prefix(bytes, prefix, 0));
+
+ /* Test the matching */
+ g_assert(gutil_bytes_has_prefix(bytes, TEST_ARRAY_AND_SIZE(prefix)));
+ g_assert(!gutil_bytes_has_prefix(bytes, TEST_ARRAY_AND_SIZE(not_prefix)));
+ g_assert(!gutil_bytes_has_prefix(bytes, TEST_ARRAY_AND_SIZE(too_long)));
+
+ g_bytes_unref(empty);
+ g_bytes_unref(bytes);
+}
+
+/*==========================================================================*
+ * bytes_suffix
+ *==========================================================================*/
+
+static
+void
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/libglibutil/test/test_strv/test_strv.c
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2015-2020 Jolla Ltd.
- * Copyright (C) 2015-2020 Slava Monich <slava.monich@jolla.com>
+ * Copyright (C) 2015-2022 Jolla Ltd.
+ * Copyright (C) 2015-2022 Slava Monich <slava.monich@jolla.com>
*
* You may use this file under the terms of BSD license as follows:
*
@@ -163,7 +163,12 @@
g_assert(gutil_strv_contains(sv, "b"));
g_assert(gutil_strv_contains(sv, "c"));
g_assert(!gutil_strv_contains(sv, "d"));
- g_assert(gutil_strv_find(sv, "b") == 1);
+ g_assert_cmpint(gutil_strv_find(sv, "b"), == ,1);
+ g_assert_cmpint(gutil_strv_find_last(sv, "a"), == ,0);
+ g_assert_cmpint(gutil_strv_find_last(sv, "b"), == ,2);
+ g_assert_cmpint(gutil_strv_find_last(sv, "c"), == ,3);
+ g_assert_cmpint(gutil_strv_find_last(sv, "d"), == ,-1);
+ g_assert_cmpint(gutil_strv_find_last(NULL, NULL), == ,-1);
g_assert(!gutil_strv_contains(sv, NULL));
g_assert(!gutil_strv_contains(NULL, "a"));
g_assert(!gutil_strv_contains(NULL, NULL));
@@ -179,6 +184,37 @@
test_remove(
void)
{
+ guint orig_len = 8;
+ char** sv = g_strsplit("a,b,c,b,c,c,d,b", ",", 0); /* 8 elements */
+ char** sv1 = g_strsplit("a,b,b,c,c,d,b", ",", 0); /* Minus one c */
+ char** sv2 = g_strsplit("a,c,c,d", ",", 0); /* Minus all b's */
+ char** sv3 = g_strsplit("a,c,c", ",", 0); /* Minus all (actually one) d */
+
+ g_assert(!gutil_strv_remove_all(NULL, NULL));
+ g_assert(gutil_strv_remove_all(sv, NULL) == sv);
+ g_assert_cmpuint(gutil_strv_length(sv), == ,orig_len);
+
+ g_assert(sv == gutil_strv_remove_all(sv, "e")); /* "e" is not there */
+ g_assert_cmpuint(gutil_strv_length(sv), == ,orig_len);
+ g_assert(gutil_strv_equal(sv = gutil_strv_remove_one(sv, "c"), sv1));
+ g_assert(gutil_strv_equal(sv = gutil_strv_remove_all(sv, "b"), sv2));
+ g_assert(gutil_strv_equal(sv = gutil_strv_remove_all(sv, "d"), sv3));
+
+ g_strfreev(sv);
+ g_strfreev(sv1);
+ g_strfreev(sv2);
+ g_strfreev(sv3);
+}
+
+/*==========================================================================*
+ * RemoveAt
+ *==========================================================================*/
+
+static
+void
+test_remove_at(
+ void)
+{
char** sv = g_strsplit("a,b,c", ",", 0);
char* c = sv[2];
@@ -198,6 +234,27 @@
}
/*==========================================================================*
+ * RemoveDups
+ *==========================================================================*/
+
+static
+void
+test_remove_dups(
+ void)
+{
+ char** sv = g_strsplit("a,b,c,b,c,c,d,b", ",", 0); /* 8 elements */
+ char** sv1 = g_strsplit("a,b,c,d", ",", 0); /* No dups */
+
+ g_assert(!gutil_strv_remove_dups(NULL));
+ g_assert(gutil_strv_equal(sv = gutil_strv_remove_dups(sv), sv1));
+ g_assert(sv == gutil_strv_remove_dups(sv)); /* Nothing to realloc */
+ g_assert(gutil_strv_equal(sv, sv1)); /* Still equal */
+
+ g_strfreev(sv);
+ g_strfreev(sv1);
+}
+
+/*==========================================================================*
* Sort
*==========================================================================*/
@@ -280,6 +337,8 @@
g_test_add_func(TEST_PREFIX "equal", test_equal);
g_test_add_func(TEST_PREFIX "find", test_find);
g_test_add_func(TEST_PREFIX "remove", test_remove);
+ g_test_add_func(TEST_PREFIX "remove_at", test_remove_at);
+ g_test_add_func(TEST_PREFIX "remove_dups", test_remove_dups);
g_test_add_func(TEST_PREFIX "sort", test_sort);
g_test_add_func(TEST_PREFIX "bsearch", test_bsearch);
g_test_add_func(TEST_PREFIX "strip", test_strip);
|
[-]
[+]
|
Added |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/libglibutil/test/test_weakref/Makefile
^
|
@@ -0,0 +1,5 @@
+# -*- Mode: makefile-gmake -*-
+
+EXE = test_weakref
+
+include ../common/Makefile
|
[-]
[+]
|
Added |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/libglibutil/test/test_weakref/test_weakref.c
^
|
@@ -0,0 +1,105 @@
+/*
+ * Copyright (C) 2023 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 HOLDERS 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 "test_common.h"
+
+#include "gutil_weakref.h"
+
+#include <glib-object.h>
+
+static TestOpt test_opt;
+
+/*==========================================================================*
+ * null
+ *==========================================================================*/
+
+static
+void
+test_null()
+{
+ gutil_weakref_unref(NULL);
+ gutil_weakref_set(NULL, NULL);
+ g_assert(!gutil_weakref_ref(NULL));
+ g_assert(!gutil_weakref_get(NULL));
+}
+
+/*==========================================================================*
+ * basic
+ *==========================================================================*/
+
+static
+void
+test_basic()
+{
+ GObject* obj = g_object_new(TEST_OBJECT_TYPE, NULL);
+ GUtilWeakRef* ref = gutil_weakref_new(obj);
+
+ g_assert(gutil_weakref_ref(ref) == ref);
+ gutil_weakref_unref(ref);
+ g_assert(gutil_weakref_get(ref) == obj);
+ g_object_unref(obj);
+ gutil_weakref_unref(ref);
+
+ ref = gutil_weakref_new(NULL);
+ g_assert(!gutil_weakref_get(ref));
+ gutil_weakref_set(ref, obj);
+ g_assert(gutil_weakref_get(ref) == obj);
+ g_object_unref(obj);
+ g_object_unref(obj); /* This actually deallocates the object */
+ g_assert(!gutil_weakref_get(ref));
+ gutil_weakref_unref(ref);
+}
+
+/*==========================================================================*
+ * Common
+ *==========================================================================*/
+
+#define TEST_(name) "/weakref/" name
+
+int main(int argc, char* argv[])
+{
+ G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
+ g_type_init();
+ G_GNUC_END_IGNORE_DEPRECATIONS;
+ g_test_init(&argc, &argv, NULL);
+ test_init(&test_opt, argc, argv);
+ g_test_add_func(TEST_("null"), test_null);
+ g_test_add_func(TEST_("basic"), test_basic);
+ return g_test_run();
+}
+
+/*
+ * Local Variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/libgnfcdc/LICENSE
^
|
@@ -1,5 +1,5 @@
-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 the BSD license as follows:
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/libgnfcdc/Makefile
^
|
@@ -23,7 +23,7 @@
VERSION_MAJOR = 1
VERSION_MINOR = 0
-VERSION_RELEASE = 7
+VERSION_RELEASE = 10
# Version for pkg-config
PCVERSION = $(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_RELEASE)
@@ -55,7 +55,8 @@
nfcdc_log.c \
nfcdc_peer.c \
nfcdc_peer_service.c \
- nfcdc_tag.c
+ nfcdc_tag.c \
+ nfcdc_util.c
GEN_SRC = \
org.sailfishos.nfc.Adapter.c \
@@ -90,10 +91,11 @@
BASE_FLAGS = -fPIC
FULL_CFLAGS = $(BASE_FLAGS) $(CFLAGS) $(DEFINES) $(WARNINGS) $(INCLUDES) \
-MMD -MP $(shell pkg-config --cflags $(PKGS))
-FULL_LDFLAGS = $(BASE_FLAGS) $(LDFLAGS) -shared -Wl,-soname=$(LIB_SONAME)
+FULL_LDFLAGS = $(BASE_FLAGS) $(LDFLAGS) -shared -Wl,-soname=$(LIB_SONAME) \
+ -Wl,--version-script=libgnfcdc.map
LIBS = $(shell pkg-config --libs $(PKGS))
DEBUG_FLAGS = -g
-RELEASE_FLAGS =
+RELEASE_FLAGS = -flto
COVERAGE_FLAGS = -g
KEEP_SYMBOLS ?= 0
@@ -104,7 +106,7 @@
DEBUG_LDFLAGS = $(FULL_LDFLAGS) $(DEBUG_FLAGS)
RELEASE_LDFLAGS = $(FULL_LDFLAGS) $(RELEASE_FLAGS)
DEBUG_CFLAGS = $(FULL_CFLAGS) $(DEBUG_FLAGS) -DDEBUG
-RELEASE_CFLAGS = $(FULL_CFLAGS) $(RELEASE_FLAGS) -O2
+RELEASE_CFLAGS = $(FULL_CFLAGS) $(RELEASE_FLAGS) -O2 -ffat-lto-objects
COVERAGE_CFLAGS = $(FULL_CFLAGS) $(COVERAGE_FLAGS) --coverage
#
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/libgnfcdc/include/nfcdc_isodep.h
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2019 Jolla Ltd.
- * Copyright (C) 2019 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 the BSD license as follows:
*
@@ -42,6 +42,8 @@
#include <gio/gio.h>
+#define NFC_ISODEP_SW1(sw) (((sw) >> 8) & 0xff)
+#define NFC_ISODEP_SW2(sw) ((sw) & 0xff)
#define NFC_ISODEP_SW(sw1,sw2) ((((sw1) << 8) & 0xff00) | ((sw2) & 0xff))
#define NFC_ISODEP_SW_OK NFC_ISODEP_SW(0x90,00) /* Normal completion */
@@ -54,20 +56,34 @@
NFC_ISODEP_PROPERTY_COUNT
} NFC_ISODEP_PROPERTY;
+typedef enum nfc_isodep_act_param {
+ /* NFC-A */
+ NFC_ISODEP_ACT_PARAM_T0, /* Format Byte T0 */
+ NFC_ISODEP_ACT_PARAM_TA, /* Interface Bytes TA (optional) */
+ NFC_ISODEP_ACT_PARAM_TB, /* Interface Bytes TB (optional) */
+ NFC_ISODEP_ACT_PARAM_TC, /* Interface Bytes TC (optional) */
+ NFC_ISODEP_ACT_PARAM_HB, /* Historical Bytes */
+ /* NFC-B */
+ NFC_ISODEP_ACT_PARAM_MBLI, /* Maximum Buffer Length Index */
+ NFC_ISODEP_ACT_PARAM_DID, /* Device ID */
+ NFC_ISODEP_ACT_PARAM_HLR, /* Higher Layer Response (optional) */
+ NFC_ISODEP_ACT_PARAM_COUNT
+} NFC_ISODEP_ACT_PARAM;
+
struct nfc_isodep_client {
const char* path;
gboolean valid;
gboolean present;
};
-typedef struct nfc_isodep_apdu {
+struct nfc_isodep_apdu {
guint8 cla; /* Class byte */
guint8 ins; /* Instruction byte */
guint8 p1; /* Parameter byte 1 */
guint8 p2; /* Parameter byte 2 */
GUtilData data; /* Command data */
guint le; /* Expected length, zero if none */
-} NfcIsoDepApdu;
+};
typedef
void
@@ -97,6 +113,15 @@
nfc_isodep_client_unref(
NfcIsoDepClient* isodep);
+NfcTagClient*
+nfc_isodep_client_tag(
+ NfcIsoDepClient* isodep); /* Since 1.0.10 */
+
+const GUtilData*
+nfc_isodep_client_act_param(
+ NfcIsoDepClient* isodep,
+ NFC_ISODEP_ACT_PARAM param); /* Since 1.0.8 */
+
gboolean
nfc_isodep_client_transmit(
NfcIsoDepClient* isodep,
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/libgnfcdc/include/nfcdc_tag.h
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2019 Jolla Ltd.
- * Copyright (C) 2019 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 the BSD license as follows:
*
@@ -56,6 +56,17 @@
NFC_TAG_PROPERTY_COUNT
} NFC_TAG_PROPERTY;
+typedef enum nfc_tag_poll_param {
+ /* NFC-A */
+ NFC_TAG_POLL_PARAM_SELRES, /* SEL_RES Response */
+ NFC_TAG_POLL_PARAM_NFCID1, /* NFCID1 */
+ /* NFC-B */
+ NFC_TAG_POLL_PARAM_NFCID0, /* NFCID0 (optional) */
+ NFC_TAG_POLL_PARAM_APPDATA, /* SENSB_RES */
+ NFC_TAG_POLL_PARAM_PROTINFO, /* SENSB_RES/PROTINFO (optional) */
+ NFC_TAG_POLL_PARAM_COUNT
+} NFC_TAG_POLL_PARAM; /* Since 1.0.10 */
+
struct nfc_tag_client {
const char* path;
gboolean valid;
@@ -68,6 +79,13 @@
typedef
void
+(*NfcTagClientCallFunc)(
+ NfcTagClient* tag,
+ const GError* error,
+ void* user_data); /* Since 1.0.9 */
+
+typedef
+void
(*NfcTagPropertyFunc)(
NfcTagClient* tag,
NFC_TAG_PROPERTY property,
@@ -93,6 +111,10 @@
nfc_tag_client_unref(
NfcTagClient* tag);
+NfcTagClientLock*
+nfc_tag_client_get_lock(
+ NfcTagClient* tag); /* Since 1.0.10 */
+
gboolean
nfc_tag_client_acquire_lock(
NfcTagClient* tag,
@@ -102,6 +124,19 @@
void* user_data,
GDestroyNotify destroy);
+const GUtilData*
+nfc_tag_client_poll_param(
+ NfcTagClient* tag,
+ NFC_TAG_POLL_PARAM param); /* Since 1.0.10 */
+
+gboolean
+nfc_tag_client_deactivate(
+ NfcTagClient* tag,
+ GCancellable* cancel,
+ NfcTagClientCallFunc callback,
+ void* user_data,
+ GDestroyNotify destroy); /* Since 1.0.9 */
+
gulong
nfc_tag_client_add_property_handler(
NfcTagClient* tag,
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/libgnfcdc/include/nfcdc_types.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 the BSD license as follows:
*
@@ -47,6 +47,7 @@
typedef struct nfc_adapter_client NfcAdapterClient;
typedef struct nfc_daemon_client NfcDaemonClient;
typedef struct nfc_default_adapter NfcDefaultAdapter;
+typedef struct nfc_isodep_apdu NfcIsoDepApdu;
typedef struct nfc_isodep_client NfcIsoDepClient;
typedef struct nfc_mode_request NfcModeRequest; /* Since 1.0.6 */
typedef struct nfc_service_connection NfcServiceConnection; /* Since 1.0.6 */
|
[-]
[+]
|
Added |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/libgnfcdc/libgnfcdc.map
^
|
@@ -0,0 +1,7 @@
+{
+ global:
+ nfc_*;
+ nfcdc_*;
+ local:
+ *;
+};
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/libgnfcdc/rpm/libgnfcdc.spec
^
|
@@ -1,6 +1,6 @@
Name: libgnfcdc
-Version: 1.0.7
+Version: 1.0.10
Release: 0
Summary: Glib based NFC Daemon Client
Group: Development/Libraries
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/libgnfcdc/spec/org.sailfishos.nfc.IsoDep.xml
^
|
@@ -3,6 +3,20 @@
<node>
<!-- ISO-DEP specific extensions to org.sailfishos.nfc.Tag -->
<interface name="org.sailfishos.nfc.IsoDep">
+ <!--
+ Activation Parameters:
+ NFC-A:
+ "T0" - "y", Format Byte T0
+ "TA" - "y", Interface Bytes TA (optional)
+ "TB" - "y", Interface Bytes TB (optional)
+ "TC" - "y", Interface Bytes TC (optional)
+ "HB" - "ay", Historical Bytes
+
+ NFC-B:
+ "MBLI" - "y", Maximum Buffer Length Index
+ "DID" - "y", Device ID
+ "HLR" - "ay", Higher Layer Response (optional)
+ -->
<method name="GetAll">
<arg name="version" type="i" direction="out"/>
</method>
@@ -26,5 +40,15 @@
<arg name="SW1" type="y" direction="out"/>
<arg name="SW2" type="y" direction="out"/>
</method>
+ <!-- Interface version 2 -->
+ <method name="GetAll2">
+ <arg name="version" type="i" direction="out"/>
+ <arg name="parameters" type="a{sv}" direction="out"/>
+ </method>
+ <!--
+ <method name="GetActivationParameters">
+ <arg name="parameters" type="a{sv}" direction="out"/>
+ </method>
+ -->
</interface>
</node>
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/libgnfcdc/spec/org.sailfishos.nfc.Tag.xml
^
|
@@ -21,6 +21,18 @@
32 - NFC-DEP Protocol (ISO 18092)
The above codes are bitmasks elsewhere, but here used as enum values.
+
+ Poll Parameters:
+
+ NFC-A:
+ "SEL_RES" - "ay", SEL_RES Response
+ "NFCID1" - "ay", Device identifier
+
+ NFC-B:
+ "NFCID0" - "ay", NFCID0 (device identifier) part of SENSB_RES
+ "APPDATA" - "ay", Application Data part of SENSB_RES
+ "PROTINFO" - "ay", Protocol Info part of SENSB_RES
+
-->
<method name="GetAll">
<arg name="version" type="i" direction="out"/>
@@ -53,13 +65,47 @@
<method name="GetNdefRecords">
<arg name="ndef_records" type="ao" direction="out"/>
</method>
- <method name="Deactivate"/>
-->
+ <method name="Deactivate"/>
<!-- Interface version 2 -->
<signal name="Removed"/>
<method name="Acquire">
<arg name="wait" type="b" direction="in"/>
</method>
<method name="Release"/>
+ <!-- Interface version 3 -->
+ <method name="GetAll3">
+ <arg name="version" type="i" direction="out"/>
+ <arg name="present" type="b" direction="out"/>
+ <arg name="technology" type="u" direction="out"/>
+ <arg name="protocol" type="u" direction="out"/>
+ <arg name="type" type="u" direction="out"/>
+ <arg name="interfaces" type="as" direction="out"/>
+ <arg name="ndef_records" type="ao" direction="out"/>
+ <arg name="poll_parameters" type="a{sv}" direction="out"/>
+ </method>
+ <!--
+ <method name="GetPollParameters">
+ <arg name="poll_parameters" type="a{sv}" direction="out"/>
+ </method>
+ -->
+ <!-- Interface version 4 -->
+ <!--
+ <method name="Transceive">
+ <arg name="data" type="ay" direction="in">
+ <annotation name="org.gtk.GDBus.C.ForceGVariant" value="true"/>
+ </arg>
+ <arg name="response" type="ay" direction="out">
+ <annotation name="org.gtk.GDBus.C.ForceGVariant" value="true"/>
+ </arg>
+ </method>
+ -->
+ <!-- Interface version 5 -->
+ <!--
+ <method name="Acquire2">
+ <arg name="wait" type="b" direction="in"/>
+ </method>
+ <method name="Release2"/>
+ -->
</interface>
</node>
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/libgnfcdc/src/nfcdc_adapter.c
^
|
@@ -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 the 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
@@ -78,13 +78,15 @@
gboolean proxy_initializing;
} NfcAdapterClientObject;
-G_DEFINE_TYPE(NfcAdapterClientObject, nfc_adapter_client_object, \
- NFC_CLIENT_TYPE_BASE)
#define PARENT_CLASS nfc_adapter_client_object_parent_class
#define THIS_TYPE nfc_adapter_client_object_get_type()
#define THIS(obj) G_TYPE_CHECK_INSTANCE_CAST(obj, THIS_TYPE, \
NfcAdapterClientObject)
+GType THIS_TYPE G_GNUC_INTERNAL;
+G_DEFINE_TYPE(NfcAdapterClientObject, nfc_adapter_client_object, \
+ NFC_CLIENT_TYPE_BASE)
+
NFC_CLIENT_BASE_ASSERT_VALID(NFC_ADAPTER_PROPERTY_VALID);
NFC_CLIENT_BASE_ASSERT_COUNT(NFC_ADAPTER_PROPERTY_COUNT);
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/libgnfcdc/src/nfcdc_daemon.c
^
|
@@ -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 the BSD license as follows:
*
@@ -97,12 +97,14 @@
NfcModeRequestImpl* impl;
} NfcModeRequestPriv;
-G_DEFINE_TYPE(NfcDaemonClientObject, nfc_daemon_client_object, \
- NFC_CLIENT_TYPE_BASE)
#define PARENT_CLASS nfc_daemon_client_object_parent_class
#define THIS_TYPE nfc_daemon_client_object_get_type()
-#define THIS(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),\
- THIS_TYPE, NfcDaemonClientObject))
+#define THIS(obj) G_TYPE_CHECK_INSTANCE_CAST(obj, THIS_TYPE, \
+ NfcDaemonClientObject)
+
+GType THIS_TYPE G_GNUC_INTERNAL;
+G_DEFINE_TYPE(NfcDaemonClientObject, nfc_daemon_client_object, \
+ NFC_CLIENT_TYPE_BASE)
NFC_CLIENT_BASE_ASSERT_VALID(NFC_DAEMON_PROPERTY_VALID);
NFC_CLIENT_BASE_ASSERT_COUNT(NFC_DAEMON_PROPERTY_COUNT);
@@ -273,7 +275,7 @@
if (!gutil_strv_equal(self->adapters, adapters)) {
g_strfreev(self->adapters);
- pub->adapters = (self->adapters = g_strdupv(adapters)) ?
+ pub->adapters = (self->adapters = adapters) ?
self->adapters : &nfc_daemon_client_empty_strv;
nfc_daemon_client_queue_signal_(self, ADAPTERS);
} else {
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/libgnfcdc/src/nfcdc_default_adapter.c
^
|
@@ -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 the 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
@@ -62,12 +62,14 @@
GStrV* peers;
} NfcDefaultAdapterObject;
+#define PARENT_CLASS nfc_default_adapter_object_parent_class
+#define THIS_TYPE nfc_default_adapter_object_get_type()
+#define THIS(obj) G_TYPE_CHECK_INSTANCE_CAST(obj, THIS_TYPE, \
+ NfcDefaultAdapterObject)
+
+GType THIS_TYPE G_GNUC_INTERNAL;
G_DEFINE_TYPE(NfcDefaultAdapterObject, nfc_default_adapter_object, \
NFC_CLIENT_TYPE_BASE)
-#define PARENT_CLASS nfc_default_adapter_object_parent_class
-#define THIS_TYPE (nfc_default_adapter_object_get_type())
-#define THIS(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),\
- THIS_TYPE, NfcDefaultAdapterObject))
NFC_CLIENT_BASE_ASSERT_COUNT(NFC_DEFAULT_ADAPTER_PROPERTY_COUNT);
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/libgnfcdc/src/nfcdc_isodep.c
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2019-2020 Jolla Ltd.
- * Copyright (C) 2019-2020 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 the BSD license as follows:
*
@@ -38,8 +38,9 @@
#include "nfcdc_isodep.h"
#include "nfcdc_base.h"
#include "nfcdc_dbus.h"
-#include "nfcdc_tag_p.h"
#include "nfcdc_log.h"
+#include "nfcdc_tag_p.h"
+#include "nfcdc_util_p.h"
#include <gutil_macros.h>
#include <gutil_misc.h>
@@ -55,16 +56,20 @@
gulong tag_event_id;
GDBusConnection* connection;
OrgSailfishosNfcIsoDep* proxy;
+ GHashTable* act_params;
gboolean proxy_initializing;
gint version;
const char* name;
} NfcIsoDepClientObject;
+#define PARENT_CLASS nfc_isodep_client_object_parent_class
+#define THIS_TYPE nfc_isodep_client_object_get_type()
+#define THIS(obj) G_TYPE_CHECK_INSTANCE_CAST(obj, THIS_TYPE, \
+ NfcIsoDepClientObject)
+
+GType THIS_TYPE G_GNUC_INTERNAL;
G_DEFINE_TYPE(NfcIsoDepClientObject, nfc_isodep_client_object, \
- NFC_CLIENT_TYPE_BASE)
-#define NFC_CLIENT_TYPE_ISODEP (nfc_isodep_client_object_get_type())
-#define NFC_ISODEP_CLIENT_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),\
- NFC_CLIENT_TYPE_ISODEP, NfcIsoDepClientObject))
+ NFC_CLIENT_TYPE_BASE)
NFC_CLIENT_BASE_ASSERT_VALID(NFC_ISODEP_PROPERTY_VALID);
NFC_CLIENT_BASE_ASSERT_COUNT(NFC_ISODEP_PROPERTY_COUNT);
@@ -85,6 +90,8 @@
gulong cancel_id;
} NfcIsoDepTransmitData;
+#define NFC_ISODEP_ACT_PARAM_UNKNOWN NFC_ISODEP_ACT_PARAM_COUNT
+
static GHashTable* nfc_isodep_client_table;
static
@@ -102,11 +109,38 @@
NfcIsoDepClient* pub)
{
return G_LIKELY(pub) ?
- NFC_ISODEP_CLIENT_OBJECT(G_CAST(pub, NfcIsoDepClientObject, pub)) :
+ THIS(G_CAST(pub, NfcIsoDepClientObject, pub)) :
NULL;
}
static
+int
+nfc_isodep_client_act_param_key(
+ const char* key)
+{
+ if (key) {
+ if (!strcmp(key, "T0")) {
+ return NFC_ISODEP_ACT_PARAM_T0;
+ } else if (!strcmp(key, "TA")) {
+ return NFC_ISODEP_ACT_PARAM_TA;
+ } else if (!strcmp(key, "TB")) {
+ return NFC_ISODEP_ACT_PARAM_TB;
+ } else if (!strcmp(key, "TC")) {
+ return NFC_ISODEP_ACT_PARAM_TC;
+ } else if (!strcmp(key, "HB")) {
+ return NFC_ISODEP_ACT_PARAM_HB;
+ } else if (!strcmp(key, "MBLI")) {
+ return NFC_ISODEP_ACT_PARAM_MBLI;
+ } else if (!strcmp(key, "DID")) {
+ return NFC_ISODEP_ACT_PARAM_DID;
+ } else if (!strcmp(key, "HLR")) {
+ return NFC_ISODEP_ACT_PARAM_HLR;
+ }
+ }
+ return -1;
+}
+
+static
void
nfc_isodep_client_transmit_cancelled(
GCancellable* cancel,
@@ -157,7 +191,7 @@
g_variant_unref(response);
}
g_object_unref(data->object);
- g_slice_free1(sizeof(*data), data);
+ gutil_slice_free(data);
}
static
@@ -231,7 +265,7 @@
NFC_TAG_PROPERTY property,
void* user_data)
{
- NfcIsoDepClientObject* self = NFC_ISODEP_CLIENT_OBJECT(user_data);
+ NfcIsoDepClientObject* self = THIS(user_data);
nfc_isodep_client_update(self);
nfc_isodep_client_emit_queued_signals(self);
@@ -239,24 +273,64 @@
static
void
-nfc_isodep_client_init_4(
+nfc_isodep_client_init_5(
GObject* proxy,
GAsyncResult* result,
gpointer user_data)
{
- NfcIsoDepClientObject* self = NFC_ISODEP_CLIENT_OBJECT(user_data);
+ NfcIsoDepClientObject* self = THIS(user_data);
GError* error = NULL;
+ GVariant* dict = NULL;
+ int version = 0;
GASSERT(self->proxy_initializing);
self->proxy_initializing = FALSE;
+ if (!org_sailfishos_nfc_iso_dep_call_get_all2_finish(self->proxy,
+ &version, &dict, result, &error)) {
+ GERR("%s", GERRMSG(error));
+ g_error_free(error);
+ /* Need to retry? */
+ nfc_isodep_client_drop_proxy(self);
+ } else {
+ GDEBUG("%s: ISO-DEP activation parameters", self->name);
+ self->act_params = nfc_parse_dict(self->act_params, dict,
+ nfc_isodep_client_act_param_key);
+ self->version = version;
+ nfc_isodep_client_update_valid_and_present(self);
+ nfc_isodep_client_emit_queued_signals(self);
+ g_variant_unref(dict);
+ }
+ g_object_unref(self);
+}
+
+static
+void
+nfc_isodep_client_init_4(
+ GObject* proxy,
+ GAsyncResult* result,
+ gpointer user_data)
+{
+ NfcIsoDepClientObject* self = THIS(user_data);
+ GError* error = NULL;
+ int version = 0;
+
+ GASSERT(self->proxy_initializing);
if (!org_sailfishos_nfc_iso_dep_call_get_all_finish(self->proxy,
- &self->version, result, &error)) {
+ &version, result, &error)) {
GERR("%s", GERRMSG(error));
+ self->proxy_initializing = FALSE;
g_error_free(error);
/* Need to retry? */
nfc_isodep_client_drop_proxy(self);
+ } else if (version > 1) {
+ /* Version 2 or greater */
+ org_sailfishos_nfc_iso_dep_call_get_all2(self->proxy, NULL,
+ nfc_isodep_client_init_5, g_object_ref(self));
+ } else {
+ self->version = version;
+ self->proxy_initializing = FALSE;
+ nfc_isodep_client_update_valid_and_present(self);
}
- nfc_isodep_client_update_valid_and_present(self);
nfc_isodep_client_emit_queued_signals(self);
g_object_unref(self);
}
@@ -268,7 +342,7 @@
GAsyncResult* result,
gpointer user_data)
{
- NfcIsoDepClientObject* self = NFC_ISODEP_CLIENT_OBJECT(user_data);
+ NfcIsoDepClientObject* self = THIS(user_data);
GError* error = NULL;
GASSERT(!self->proxy);
@@ -304,7 +378,7 @@
GAsyncResult* result,
gpointer user_data)
{
- NfcIsoDepClientObject* self = NFC_ISODEP_CLIENT_OBJECT(user_data);
+ NfcIsoDepClientObject* self = THIS(user_data);
GError* error = NULL;
self->connection = g_bus_get_finish(result, &error);
@@ -341,7 +415,6 @@
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/libgnfcdc/src/nfcdc_log.c
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2019 Jolla Ltd.
- * Copyright (C) 2019 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 the 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
@@ -42,6 +42,14 @@
#if GUTIL_LOG_DEBUG
+static inline
+gboolean
+nfcdc_blank_str(
+ const char* prefix)
+{
+ return !prefix[strspn(prefix," \t")];
+}
+
void
nfcdc_dump_strv(
const char* prefix,
@@ -61,17 +69,61 @@
g_string_append(buf, *ptr);
}
if (prefix) {
- GDEBUG("%s: %s %s {%s}", prefix, name, sep, buf->str);
- } else {
+ if (sep) {
+ GDEBUG("%s%s%s %s {%s}", prefix, nfcdc_blank_str(prefix) ?
+ "" : ": ", name, sep, buf->str);
+ } else {
+ GDEBUG("%s: %s {%s}", prefix, name, buf->str);
+ }
+ } else if (sep) {
GDEBUG("%s %s {%s}", name, sep, buf->str);
+ } else {
+ GDEBUG("%s {%s}", name, buf->str);
}
g_string_free(buf, TRUE);
} else {
if (prefix) {
- GDEBUG("%s: %s %s", prefix, name, sep);
- } else {
+ GDEBUG("%s%s%s %s", prefix, nfcdc_blank_str(prefix) ?
+ "" : ": ", name, sep);
+ } else if (sep) {
GDEBUG("%s %s", name, sep);
+ } else {
+ GDEBUG("%s", name);
+ }
+ }
+ }
+}
+
+void
+nfcdc_dump_data(
+ const char* prefix,
+ const char* name,
+ const char* sep,
+ const GUtilData* data)
+{
+ if (GLOG_ENABLED(GLOG_LEVEL_DEBUG)) {
+ if (data && data->size) {
+ GString* buf = g_string_new(NULL);
+ gsize i;
+
+ g_string_printf(buf, "%02X", data->bytes[0]);
+ for (i = 1; i < data->size; i++) {
+ g_string_append_printf(buf, ":%02X", data->bytes[i]);
}
+ if (prefix) {
+ GDEBUG("%s%s%s %s %s", prefix, nfcdc_blank_str(prefix) ?
+ "" : ": ", name, sep, buf->str);
+ } else {
+ GDEBUG("%s %s %s", name, sep, buf->str);
+ }
+ g_string_free(buf, TRUE);
+ } else if (prefix) {
+ GDEBUG("%s%s%s %s", prefix, nfcdc_blank_str(prefix) ?
+ "" : ": ", name, sep);
+ } else if (sep) {
+ GDEBUG("%s %s", name, sep);
+ } else {
+ GDEBUG("%s", name);
}
}
}
@@ -85,30 +137,12 @@
{
if (GLOG_ENABLED(GLOG_LEVEL_DEBUG)) {
if (bytes) {
- gsize size;
- const guint8* data = g_bytes_get_data(bytes, &size);
+ GUtilData data;
- if (size > 0) {
- GString* buf = g_string_new(NULL);
- gsize i;
-
- g_string_printf(buf, "%02X", data[0]);
- for (i = 1; i < size; i++) {
- g_string_append_printf(buf, ":%02X", data[i]);
- }
- if (prefix) {
- GDEBUG("%s: %s %s %s", prefix, name, sep, buf->str);
- } else {
- GDEBUG("%s %s %s", name, sep, buf->str);
- }
- g_string_free(buf, TRUE);
- return;
- }
- }
- if (prefix) {
- GDEBUG("%s: %s %s", prefix, name, sep);
+ data.bytes = g_bytes_get_data(bytes, &data.size);
+ nfcdc_dump_data(prefix, name, sep, &data);
} else {
- GDEBUG("%s %s", name, sep);
+ nfcdc_dump_data(prefix, name, sep, NULL);
}
}
}
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/libgnfcdc/src/nfcdc_log.h
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2019 Jolla Ltd.
- * Copyright (C) 2019 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 the 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
@@ -46,28 +46,39 @@
#if GUTIL_LOG_DEBUG
-G_GNUC_INTERNAL
void
nfcdc_dump_strv(
const char* prefix,
const char* name,
const char* sep,
- const GStrV* strv);
+ const GStrV* strv)
+ G_GNUC_INTERNAL;
+
+void
+nfcdc_dump_data(
+ const char* prefix,
+ const char* name,
+ const char* sep,
+ const GUtilData* data)
+ G_GNUC_INTERNAL;
-G_GNUC_INTERNAL
void
nfcdc_dump_bytes(
const char* prefix,
const char* name,
const char* sep,
- GBytes* bytes);
+ GBytes* bytes)
+ G_GNUC_INTERNAL;
# define DUMP_STRV(prefix,name,sep,strv) \
nfcdc_dump_strv(prefix,name,sep,strv)
+# define DUMP_DATA(prefix,name,sep,data) \
+ nfcdc_dump_data(prefix,name,sep,data)
# define DUMP_BYTES(prefix,name,sep,bytes) \
nfcdc_dump_bytes(prefix,name,sep,bytes)
#else
# define DUMP_STRV(prefix,name,sep,strv) ((void)0)
+# define DUMP_DATA(prefix,name,sep,data) ((void)0)
# define DUMP_BYTES(prefix,name,sep,bytes) ((void)0)
#endif
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/libgnfcdc/src/nfcdc_tag.c
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2019-2020 Jolla Ltd.
- * Copyright (C) 2019-2020 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 the BSD license as follows:
*
@@ -38,8 +38,9 @@
#include "nfcdc_adapter_p.h"
#include "nfcdc_base.h"
#include "nfcdc_dbus.h"
-#include "nfcdc_tag_p.h"
#include "nfcdc_log.h"
+#include "nfcdc_tag_p.h"
+#include "nfcdc_util_p.h"
#include <gutil_macros.h>
#include <gutil_misc.h>
@@ -62,6 +63,7 @@
NfcAdapterClient* adapter;
gulong adapter_event_id[ADAPTER_SIGNAL_COUNT];
OrgSailfishosNfcTag* proxy;
+ GHashTable* poll_params;
gboolean proxy_initializing;
gint version;
const char* name;
@@ -69,11 +71,14 @@
GStrV* ndef_records;
} NfcTagClientObject;
+#define PARENT_CLASS nfc_tag_client_object_parent_class
+#define THIS_TYPE nfc_tag_client_object_get_type()
+#define THIS(obj) G_TYPE_CHECK_INSTANCE_CAST(obj, THIS_TYPE, \
+ NfcTagClientObject)
+
+GType THIS_TYPE G_GNUC_INTERNAL;
G_DEFINE_TYPE(NfcTagClientObject, nfc_tag_client_object, \
- NFC_CLIENT_TYPE_BASE)
-#define NFC_CLIENT_TYPE_TAG (nfc_tag_client_object_get_type())
-#define NFC_TAG_CLIENT_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),\
- NFC_CLIENT_TYPE_TAG, NfcTagClientObject))
+ NFC_CLIENT_TYPE_BASE)
NFC_CLIENT_BASE_ASSERT_VALID(NFC_TAG_PROPERTY_VALID);
NFC_CLIENT_BASE_ASSERT_COUNT(NFC_TAG_PROPERTY_COUNT);
@@ -85,6 +90,16 @@
#define nfc_tag_client_queue_signal(self,NAME) \
((self)->base.queued_signals |= SIGNAL_BIT_(NAME))
+typedef struct nfc_tag_client_call_data {
+ NfcTagClientObject* obj;
+ NfcTagClientCallFunc callback;
+ gboolean (*finish)(OrgSailfishosNfcTag*, GAsyncResult*, GError**);
+ GDestroyNotify destroy;
+ void* user_data;
+ GCancellable* cancel;
+ gulong cancel_id;
+} NfcTagClientCallData;
+
static char* nfc_tag_client_empty_strv = NULL;
static GHashTable* nfc_tag_client_table;
@@ -174,7 +189,7 @@
GASSERT(tag->lock);
nfc_tag_client_lock_unref(tag->lock);
nfc_tag_client_lock_data_deinit(data);
- g_slice_free1(sizeof(*idle), idle);
+ gutil_slice_free(idle);
}
static
@@ -204,7 +219,7 @@
GAsyncResult* result,
gpointer user_data)
{
- NfcTagClientObject* tag = NFC_TAG_CLIENT_OBJECT(user_data);
+ NfcTagClientObject* tag = THIS(user_data);
GError* error = NULL;
if (org_sailfishos_nfc_tag_call_release_finish(ORG_SAILFISHOS_NFC_TAG(
@@ -278,7 +293,7 @@
g_error_free(error);
}
nfc_tag_client_lock_data_deinit(data);
- g_slice_free1(sizeof(*data), data);
+ gutil_slice_free(data);
}
NfcTagClientLock*
@@ -306,7 +321,7 @@
tag->lock = NULL;
}
g_object_unref(tag);
- g_slice_free1(sizeof(*lock), lock);
+ gutil_slice_free(lock);
}
}
@@ -320,11 +335,75 @@
NfcTagClient* pub)
{
return G_LIKELY(pub) ?
- NFC_TAG_CLIENT_OBJECT(G_CAST(pub, NfcTagClientObject, pub)) :
+ THIS(G_CAST(pub, NfcTagClientObject, pub)) :
NULL;
}
static
+int
+nfc_tag_client_poll_param_key(
+ const char* key)
+{
+ if (key) {
+ if (!strcmp(key, "SEL_RES")) {
+ return NFC_TAG_POLL_PARAM_SELRES;
+ } else if (!strcmp(key, "NFCID1")) {
+ return NFC_TAG_POLL_PARAM_NFCID1;
+ } else if (!strcmp(key, "NFCID0")) {
+ return NFC_TAG_POLL_PARAM_NFCID0;
+ } else if (!strcmp(key, "APPDATA")) {
+ return NFC_TAG_POLL_PARAM_APPDATA;
+ } else if (!strcmp(key, "PROTINFO")) {
+ return NFC_TAG_POLL_PARAM_PROTINFO;
+ }
+ }
+ return -1;
+}
+
+static
+void
+nfc_tag_client_call_cancelled(
+ GCancellable* cancel,
+ NfcTagClientCallData* data)
+{
+ data->callback = NULL;
+}
+
+static
+void
+nfc_tag_client_call_done(
+ GObject* proxy,
+ GAsyncResult* result,
+ gpointer user_data)
+{
+ NfcTagClientCallData* call = user_data;
+ NfcTagClientObject* self = call->obj;
+ GError* error = NULL;
+
+ if (!call->finish(ORG_SAILFISHOS_NFC_TAG(proxy), result, &error)) {
+ GWARN("%s: %s", self->name, GERRMSG(error));
+ }
+ if (call->callback) {
+ NfcTagClientCallFunc callback = call->callback;
+
+ call->callback = NULL;
+ callback(&self->pub, error, call->user_data);
+ }
+ if (error) {
+ g_error_free(error);
+ }
+ if (call->cancel) {
+ g_signal_handler_disconnect(call->cancel, call->cancel_id);
+ g_object_unref(call->cancel);
+ }
+ if (call->destroy) {
+ call->destroy(call->user_data);
+ }
+ g_object_unref(self);
+ gutil_slice_free(call);
+}
+
+static
void
nfc_tag_client_update_valid_and_present(
NfcTagClientObject* self)
@@ -409,7 +488,7 @@
NFC_ADAPTER_PROPERTY property,
void* user_data)
{
- NfcTagClientObject* self = NFC_TAG_CLIENT_OBJECT(user_data);
+ NfcTagClientObject* self = THIS(user_data);
nfc_tag_client_update(self);
nfc_tag_client_emit_queued_signals(self);
@@ -417,60 +496,116 @@
static
void
-nfc_tag_client_init_4(
+nfc_tag_client_init_finished(
+ NfcTagClientObject* self,
+ gboolean present,
+ gchar** interfaces,
+ gchar** ndef_records,
+ GVariant* dict)
+{
+ NfcTagClient* tag = &self->pub;
+
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/libgnfcdc/src/nfcdc_tag_p.h
^
|
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2019 Jolla Ltd.
- * Copyright (C) 2019 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 the 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
@@ -40,10 +40,10 @@
#include "nfcdc_tag.h"
-G_GNUC_INTERNAL
GDBusConnection*
nfc_tag_client_connection(
- NfcTagClient* tag);
+ NfcTagClient* tag)
+ G_GNUC_INTERNAL;
#endif /* NFCDC_TAG_PRIVATE_H */
|
[-]
[+]
|
Added |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/libgnfcdc/src/nfcdc_util.c
^
|
@@ -0,0 +1,164 @@
+/*
+ * Copyright (C) 2022 Jolla Ltd.
+ * Copyright (C) 2022 Slava Monich <slava@monich.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.
+ *
+ * The views and conclusions contained in the software and documentation
+ * are those of the authors and should not be interpreted as representing
+ * any official policies, either expressed or implied.
+ */
+
+#include "nfcdc_util_p.h"
+#include "nfcdc_log.h"
+
+#include <gutil_misc.h>
+
+GUtilData*
+nfc_data_copy(
+ const void* data,
+ gsize size)
+{
+ /* Allocates GUtilData and the actual data from a single memory block */
+ if (data) {
+ GUtilData* copy = g_malloc(sizeof(GUtilData) + size);
+ void* buf = copy + 1;
+
+ copy->size = size;
+ copy->bytes = buf;
+ memcpy(buf, data, size);
+ return copy;
+ } else {
+ return g_new0(GUtilData, 1);
+ }
+}
+
+GUtilData*
+nfc_data_from_variant(
+ GVariant* var)
+{
+ GUtilData* data = NULL;
+ GVariant* tmp = NULL;
+
+ if (g_variant_is_of_type(var, G_VARIANT_TYPE_VARIANT)) {
+ var = tmp = g_variant_get_variant(var);
+ }
+
+ /* Allocate value as a single memory block */
+ if (g_variant_is_of_type(var, G_VARIANT_TYPE_BYTESTRING)) {
+ data = nfc_data_copy(g_variant_get_data(var), g_variant_get_size(var));
+ } else if (g_variant_is_of_type(var, G_VARIANT_TYPE_BYTE)) {
+ const guint8 b = g_variant_get_byte(var);
+ data = nfc_data_copy(&b, 1);
+ }
+
+ if (tmp) {
+ g_variant_unref(tmp);
+ }
+
+ /* Dispose of GUtilData and its contents with a single g_free() */
+ return data;
+}
+
+GHashTable*
+nfc_parse_dict(
+ GHashTable* params,
+ GVariant* dict,
+ NfcStringKeyFunc string_key)
+{
+ if (dict) {
+ GVariantIter it;
+ GVariant* entry;
+
+ if (!params) {
+ params = g_hash_table_new_full(g_direct_hash, g_direct_equal,
+ NULL, g_free);
+ }
+
+ for (g_variant_iter_init(&it, dict);
+ (entry = g_variant_iter_next_value(&it)) != NULL;
+ g_variant_unref(entry)) {
+ GVariant* dict_key = g_variant_get_child_value(entry, 0);
+ const char* name = g_variant_get_string(dict_key, NULL);
+ const int key = string_key(name);
+
+ if (key >= 0) {
+ GVariant* dict_value = g_variant_get_child_value(entry, 1);
+ GUtilData* data = nfc_data_from_variant(dict_value);
+
+ if (data) {
+ DUMP_DATA(" ", name, "=", data);
+ g_hash_table_insert(params, GINT_TO_POINTER(key), data);
+ }
+ g_variant_unref(dict_value);
+ }
+ g_variant_unref(dict_key);
+ }
+ }
+ return params;
+}
+
+gboolean
+nfc_params_equal(
+ GHashTable* params1,
+ GHashTable* params2)
+{
+ if (params1 == params2) {
+ return TRUE;
+ } else if (!params1 || !params2) {
+ return FALSE;
+ } else {
+ const guint size1 = g_hash_table_size(params1);
+ const guint size2 = g_hash_table_size(params2);
+
+ if (size1 != size2) {
+ return FALSE;
+ } else if (size1) {
+ GHashTableIter it;
+ gpointer key, value;
+
+ g_hash_table_iter_init(&it, params1);
+ while (g_hash_table_iter_next(&it, &key, &value)) {
+ if (!gutil_data_equal(g_hash_table_lookup(params2,
+ key), value)) {
+ return FALSE;
+ }
+ }
+ }
+ return TRUE;
+ }
+}
+
+/*
+ * Local Variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
|
[-]
[+]
|
Added |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/libgnfcdc/src/nfcdc_util_p.h
^
|
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2022 Jolla Ltd.
+ * Copyright (C) 2022 Slava Monich <slava@monich.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.
+ *
+ * The views and conclusions contained in the software and documentation
+ * are those of the authors and should not be interpreted as representing
+ * any official policies, either expressed or implied.
+ */
+
+#ifndef NFCDC_UTIL_PRIVATE_H
+#define NFCDC_UTIL_PRIVATE_H
+
+#include "nfcdc_types.h"
+
+typedef
+int
+(*NfcStringKeyFunc)(
+ const char*);
+
+GUtilData*
+nfc_data_copy(
+ const void* data,
+ gsize size)
+ G_GNUC_INTERNAL;
+
+GUtilData*
+nfc_data_from_variant(
+ GVariant* var)
+ G_GNUC_INTERNAL;
+
+GHashTable*
+nfc_parse_dict(
+ GHashTable* table,
+ GVariant* params,
+ NfcStringKeyFunc key)
+ G_GNUC_INTERNAL;
+
+gboolean
+nfc_params_equal(
+ GHashTable* params1,
+ GHashTable* params2)
+ G_GNUC_INTERNAL;
+
+#endif /* NFCDC_UTIL_PRIVATE_H */
+
+/*
+ * Local Variables:
+ * mode: C
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/qml/main.qml
^
|
@@ -60,7 +60,7 @@
property bool wasDimmed
onDisplayStatusChanged: {
- if (target.displayStatus === HarbourSystemState.MCE_DISPLAY_DIM) {
+ if (HarbourSystemState.displayStatus === HarbourSystemState.MCE_DISPLAY_DIM) {
wasDimmed = true
} else if (target.displayStatus === HarbourSystemState.MCE_DISPLAY_ON) {
wasDimmed = false
@@ -69,7 +69,7 @@
onLockedChanged: {
lockTimer.stop()
- if (target.locked) {
+ if (FoilNotesSettings.autoLock && HarbourSystemState.locked) {
if (wasDimmed) {
// Give the user some time to wake wake up the screen
// and prevent encrypted pictures from being locked
@@ -80,6 +80,19 @@
}
}
}
+
+ Connections {
+ target: FoilNotesSettings
+
+ onAutoLockChanged: {
+ lockTimer.stop()
+ // It's so unlikely that settings change when the device is locked
+ // But it's possible!
+ if (FoilNotesSettings.autoLock && HarbourSystemState.locked) {
+ FoilAuthModel.lock(false);
+ }
+ }
+ }
Component {
id: encryptedPageComponent
|
[-]
[+]
|
Added |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/settings/harbour-foilnotes.json
^
|
@@ -0,0 +1,14 @@
+{
+ "translation_catalog" : "harbour-foilnotes",
+ "entries": [
+ {
+ "path": "applications/harbour-foilnotes.desktop",
+ "title": "Foil Auth",
+ "type": "page",
+ "icon": "harbour-foilnotes",
+ "params": {
+ "source": "/usr/share/harbour-foilnotes/qml/settings/settings.qml"
+ }
+ }
+ ]
+}
|
[-]
[+]
|
Added |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/settings/settings.qml
^
|
@@ -0,0 +1,67 @@
+import QtQuick 2.0
+import Sailfish.Silica 1.0
+import org.nemomobile.configuration 1.0
+
+Page {
+ property alias title: pageHeader.title
+
+ // jolla-settings expects these properties:
+ property var applicationName
+ property var applicationIcon
+
+ readonly property string _rootPath: "/apps/harbour-foilnotes/"
+
+ SilicaFlickable {
+ anchors.fill: parent
+ contentHeight: content.height
+
+ Column {
+ id: content
+ width: parent.width
+
+ PageHeader {
+ id: pageHeader
+
+ rightMargin: Theme.horizontalPageMargin + (appIcon.visible ? (height - appIcon.padding) : 0)
+ title: applicationName ? applicationName : "Foil Notes"
+ description: applicationName ?
+ //: Settings page header description (app version)
+ //% "Version %1"
+ qsTrId("foilnotes-settings_page-header-version").arg("1.1.1") : ""
+
+ Image {
+ id: appIcon
+
+ readonly property int padding: Theme.paddingLarge
+ readonly property int size: pageHeader.height - 2 * padding
+ x: pageHeader.width - width - Theme.horizontalPageMargin
+ y: padding
+ width: size
+ height: size
+ sourceSize: Qt.size(size,size)
+ source: applicationIcon ? applicationIcon : ""
+ visible: appIcon.status === Image.Ready
+ }
+ }
+
+ TextSwitch {
+ //: Text switch label
+ //% "Automatic locking"
+ text: qsTrId("foilnotes-settings_page-autolock-text")
+ //: Text switch description
+ //% "Require to enter Foil password after unlocking the screen."
+ description: qsTrId("foilnotes-settings_page-autolock-description")
+ automaticCheck: false
+ checked: autoLockConfig.value
+ onClicked: autoLockConfig.value = !autoLockConfig.value
+
+ ConfigurationValue {
+ id: autoLockConfig
+
+ key: _rootPath + "autoLock"
+ defaultValue: true
+ }
+ }
+ }
+ }
+}
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/src/FoilNotesDefs.h
^
|
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2018-2019 Jolla Ltd.
- * Copyright (C) 2018-2019 Slava Monich <slava@monich.com>
+ * Copyright (C) 2018-2023 Slava Monich <slava@monich.com>
*
* You may use this file under the terms of the 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
@@ -36,12 +36,7 @@
#include <qnamespace.h>
-#ifdef OPENREPOS
-# define FOILNOTES_APP_NAME "openrepos-foilnotes"
-#else
-# define FOILNOTES_APP_NAME "harbour-foilnotes"
-#endif
-
+#define FOILNOTES_APP_NAME "harbour-foilnotes"
#define FOILNOTES_QML_IMPORT "harbour.foilnotes"
#define FOILNOTES_DCONF_ROOT "/apps/" FOILNOTES_APP_NAME "/"
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/src/FoilNotesSettings.cpp
^
|
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2018-2021 Jolla Ltd.
- * Copyright (C) 2018-2021 Slava Monich <slava@monich.com>
+ * Copyright (C) 2018-2023 Slava Monich <slava@monich.com>
*
* You may use this file under the terms of the BSD license as follows:
*
@@ -45,11 +45,13 @@
#define KEY_NEXT_COLOR_INDEX DCONF_KEY("nextColorIndex")
#define KEY_SHARED_KEY_WARNING DCONF_KEY("sharedKeyWarning")
#define KEY_SHARED_KEY_WARNING2 DCONF_KEY("sharedKeyWarning2")
+#define KEY_AUTO_LOCK DCONF_KEY("autoLock")
#define KEY_AUTO_LOCK_TIME DCONF_KEY("autoLockTime")
#define KEY_PLAINTEXT_VIEW DCONF_KEY("plaintextView")
#define DEFAULT_NEXT_COLOR_INDEX 0
#define DEFAULT_SHARED_KEY_WARNING true
+#define DEFAULT_AUTO_LOCK true
#define DEFAULT_AUTO_LOCK_TIME 15000
#define DEFAULT_PLAINTEXT_VIEW false
@@ -76,6 +78,7 @@
MGConfItem* iNextColorIndex;
MGConfItem* iSharedKeyWarning;
MGConfItem* iSharedKeyWarning2;
+ MGConfItem* iAutoLock;
MGConfItem* iAutoLockTime;
MGConfItem* iPlainTextView;
const QStringList iDefaultColors;
@@ -98,6 +101,7 @@
iNextColorIndex(new MGConfItem(KEY_NEXT_COLOR_INDEX, aParent)),
iSharedKeyWarning(new MGConfItem(KEY_SHARED_KEY_WARNING, aParent)),
iSharedKeyWarning2(new MGConfItem(KEY_SHARED_KEY_WARNING2, aParent)),
+ iAutoLock(new MGConfItem(KEY_AUTO_LOCK, aParent)),
iAutoLockTime(new MGConfItem(KEY_AUTO_LOCK_TIME, aParent)),
iPlainTextView(new MGConfItem(KEY_PLAINTEXT_VIEW, aParent)),
iDefaultColors(defaultColors()),
@@ -112,6 +116,8 @@
aParent, SIGNAL(sharedKeyWarningChanged()));
QObject::connect(iSharedKeyWarning2, SIGNAL(valueChanged()),
aParent, SIGNAL(sharedKeyWarning2Changed()));
+ QObject::connect(iAutoLock, SIGNAL(valueChanged()),
+ aParent, SIGNAL(autoLockChanged()));
QObject::connect(iAutoLockTime, SIGNAL(valueChanged()),
aParent, SIGNAL(autoLockTimeChanged()));
QObject::connect(iPlainTextView, SIGNAL(valueChanged()),
@@ -119,7 +125,8 @@
iAvailableColors = availableColors();
}
-QStringList FoilNotesSettings::Private::defaultColors()
+QStringList
+FoilNotesSettings::Private::defaultColors()
{
QStringList colors;
const uint n = sizeof(gAvailableColors)/sizeof(gAvailableColors[0]);
@@ -130,12 +137,14 @@
return colors;
}
-QStringList FoilNotesSettings::Private::availableColors() const
+QStringList
+FoilNotesSettings::Private::availableColors() const
{
return iAvailableColorsConf->value(iDefaultColors).toStringList();
}
-void FoilNotesSettings::Private::onAvailableColorsChanged()
+void
+FoilNotesSettings::Private::onAvailableColorsChanged()
{
const QStringList newColors(availableColors());
if (iAvailableColors != newColors) {
@@ -162,8 +171,8 @@
// Callback for qmlRegisterSingletonType<FoilNotesSettings>
QObject*
FoilNotesSettings::createSingleton(
- QQmlEngine* aEngine,
- QJSEngine* aScript)
+ QQmlEngine*,
+ QJSEngine*)
{
return new FoilNotesSettings();
}
@@ -184,7 +193,8 @@
}
void
-FoilNotesSettings::setAvailableColors(QStringList aColors)
+FoilNotesSettings::setAvailableColors(
+ QStringList aColors)
{
iPrivate->iAvailableColorsConf->set(aColors);
if (iPrivate->iAvailableColors != aColors) {
@@ -256,6 +266,22 @@
iPrivate->iSharedKeyWarning2->set(aValue);
}
+// autoLock
+
+bool
+FoilNotesSettings::autoLock() const
+{
+ return iPrivate->iAutoLock->value(DEFAULT_AUTO_LOCK).toBool();
+}
+
+void
+FoilNotesSettings::setAutoLock(
+ bool aValue)
+{
+ HDEBUG(aValue);
+ iPrivate->iAutoLock->set(aValue);
+}
+
// autoLockTime
int
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/src/FoilNotesSettings.h
^
|
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2018-2021 Jolla Ltd.
- * Copyright (C) 2018-2021 Slava Monich <slava@monich.com>
+ * Copyright (C) 2018-2023 Slava Monich <slava@monich.com>
*
* You may use this file under the terms of the BSD license as follows:
*
@@ -40,13 +40,15 @@
class QQmlEngine;
class QJSEngine;
-class FoilNotesSettings : public QObject {
+class FoilNotesSettings : public QObject
+{
Q_OBJECT
Q_PROPERTY(QStringList defaultColors READ defaultColors CONSTANT)
Q_PROPERTY(QStringList availableColors READ availableColors WRITE setAvailableColors NOTIFY availableColorsChanged)
Q_PROPERTY(int nextColorIndex READ nextColorIndex WRITE setNextColorIndex NOTIFY nextColorIndexChanged)
Q_PROPERTY(bool sharedKeyWarning READ sharedKeyWarning WRITE setSharedKeyWarning NOTIFY sharedKeyWarningChanged)
Q_PROPERTY(bool sharedKeyWarning2 READ sharedKeyWarning2 WRITE setSharedKeyWarning2 NOTIFY sharedKeyWarning2Changed)
+ Q_PROPERTY(bool autoLock READ autoLock WRITE setAutoLock NOTIFY autoLockChanged)
Q_PROPERTY(int autoLockTime READ autoLockTime WRITE setAutoLockTime NOTIFY autoLockTimeChanged)
Q_PROPERTY(bool plaintextView READ plaintextView WRITE setPlaintextView NOTIFY plaintextViewChanged)
@@ -55,25 +57,28 @@
~FoilNotesSettings();
// Callback for qmlRegisterSingletonType<FoilNotesSettings>
- static QObject* createSingleton(QQmlEngine* aEngine, QJSEngine* aScript);
+ static QObject* createSingleton(QQmlEngine*, QJSEngine*);
const QStringList defaultColors() const;
QStringList availableColors() const;
- void setAvailableColors(QStringList aColors);
+ void setAvailableColors(QStringList);
int nextColorIndex() const;
- void setNextColorIndex(int aValue);
+ void setNextColorIndex(int);
bool sharedKeyWarning() const;
bool sharedKeyWarning2() const;
- void setSharedKeyWarning(bool aValue);
- void setSharedKeyWarning2(bool aValue);
+ void setSharedKeyWarning(bool);
+ void setSharedKeyWarning2(bool);
+
+ bool autoLock() const;
+ void setAutoLock(bool);
int autoLockTime() const;
- void setAutoLockTime(int aValue);
+ void setAutoLockTime(int);
bool plaintextView() const;
- void setPlaintextView(bool aValue);
+ void setPlaintextView(bool);
Q_INVOKABLE int pickColorIndex();
Q_INVOKABLE QColor pickColor();
@@ -83,6 +88,7 @@
void nextColorIndexChanged();
void sharedKeyWarningChanged();
void sharedKeyWarning2Changed();
+ void autoLockChanged();
void autoLockTimeChanged();
void plaintextViewChanged();
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/translations/harbour-foilnotes-de.ts
^
|
@@ -397,5 +397,20 @@
<extracomment>Full screen info label</extracomment>
<translation type="unfinished">Berühren Sie ein anderes NFC-fähiges Gerät, während Foil Notes im Vollbildmodus ausgeführt wird.</translation>
</message>
+ <message id="foilnotes-settings_page-header-version">
+ <source>Version %1</source>
+ <extracomment>Settings page header description (app version)</extracomment>
+ <translation type="unfinished">Version %1</translation>
+ </message>
+ <message id="foilnotes-settings_page-autolock-text">
+ <source>Automatic locking</source>
+ <extracomment>Text switch label</extracomment>
+ <translation type="unfinished">Automatische Sperrung</translation>
+ </message>
+ <message id="foilnotes-settings_page-autolock-description">
+ <source>Require to enter Foil password after unlocking the screen.</source>
+ <extracomment>Text switch description</extracomment>
+ <translation type="unfinished">Nach dem Entsperren des Bildschirms muss das Foil-Passwort eingegeben werden.</translation>
+ </message>
</context>
</TS>
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/translations/harbour-foilnotes-es.ts
^
|
@@ -397,5 +397,20 @@
<extracomment>Full screen info label</extracomment>
<translation type="unfinished">Toque otro dispositivo compatible con NFC con Foil Notes en pantalla completa.</translation>
</message>
+ <message id="foilnotes-settings_page-header-version">
+ <source>Version %1</source>
+ <extracomment>Settings page header description (app version)</extracomment>
+ <translation type="unfinished">Versión %1</translation>
+ </message>
+ <message id="foilnotes-settings_page-autolock-text">
+ <source>Automatic locking</source>
+ <extracomment>Text switch label</extracomment>
+ <translation type="unfinished">Bloqueo automático</translation>
+ </message>
+ <message id="foilnotes-settings_page-autolock-description">
+ <source>Require to enter Foil password after unlocking the screen.</source>
+ <extracomment>Text switch description</extracomment>
+ <translation type="unfinished">Requiere ingresar la contraseña de Foil después de desbloquear la pantalla.</translation>
+ </message>
</context>
</TS>
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/translations/harbour-foilnotes-fr.ts
^
|
@@ -397,5 +397,20 @@
<extracomment>Full screen info label</extracomment>
<translation type="unfinished">Touchez un autre appareil compatible NFC avec Foil Notes en plein écran.</translation>
</message>
+ <message id="foilnotes-settings_page-header-version">
+ <source>Version %1</source>
+ <extracomment>Settings page header description (app version)</extracomment>
+ <translation type="unfinished">Version %1</translation>
+ </message>
+ <message id="foilnotes-settings_page-autolock-text">
+ <source>Automatic locking</source>
+ <extracomment>Text switch label</extracomment>
+ <translation type="unfinished">Verrouillage automatique</translation>
+ </message>
+ <message id="foilnotes-settings_page-autolock-description">
+ <source>Require to enter Foil password after unlocking the screen.</source>
+ <extracomment>Text switch description</extracomment>
+ <translation type="unfinished">Nécessite d'entrer le mot de passe Foil après avoir déverrouillé l'écran.</translation>
+ </message>
</context>
</TS>
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/translations/harbour-foilnotes-pl.ts
^
|
@@ -400,5 +400,20 @@
<extracomment>Full screen info label</extracomment>
<translation>Dotknij innego urządzenia obsługującego NFC z Foil Notes otwartym na pełnym ekranie. </translation>
</message>
+ <message id="foilnotes-settings_page-header-version">
+ <source>Version %1</source>
+ <extracomment>Settings page header description (app version)</extracomment>
+ <translation>Wersja %1</translation>
+ </message>
+ <message id="foilnotes-settings_page-autolock-text">
+ <source>Automatic locking</source>
+ <extracomment>Text switch label</extracomment>
+ <translation>Automatyczne blokowanie</translation>
+ </message>
+ <message id="foilnotes-settings_page-autolock-description">
+ <source>Require to enter Foil password after unlocking the screen.</source>
+ <extracomment>Text switch description</extracomment>
+ <translation>Wymagaj podania Foil hasła po odblokowaniu ekranu.</translation>
+ </message>
</context>
</TS>
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/translations/harbour-foilnotes-ru.ts
^
|
@@ -400,5 +400,20 @@
<extracomment>Full screen info label</extracomment>
<translation>Прикоснитесь NFC сенсором к другому устройству, на котором приложение Foil Notes открыто на весь экран. Возможно, произойдёт чудо!</translation>
</message>
+ <message id="foilnotes-settings_page-header-version">
+ <source>Version %1</source>
+ <extracomment>Settings page header description (app version)</extracomment>
+ <translation>Версия %1</translation>
+ </message>
+ <message id="foilnotes-settings_page-autolock-text">
+ <source>Automatic locking</source>
+ <extracomment>Text switch label</extracomment>
+ <translation>Автоматическая блокировка</translation>
+ </message>
+ <message id="foilnotes-settings_page-autolock-description">
+ <source>Require to enter Foil password after unlocking the screen.</source>
+ <extracomment>Text switch description</extracomment>
+ <translation>Требовать ввода пароля после разблокировки экрана.</translation>
+ </message>
</context>
</TS>
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/translations/harbour-foilnotes-sv.ts
^
|
@@ -397,5 +397,20 @@
<extracomment>Full screen info label</extracomment>
<translation type="unfinished">Tryck på en annan NFC-kompatibel enhet med Foil Notes på helskärm.</translation>
</message>
+ <message id="foilnotes-settings_page-header-version">
+ <source>Version %1</source>
+ <extracomment>Settings page header description (app version)</extracomment>
+ <translation>Version %1</translation>
+ </message>
+ <message id="foilnotes-settings_page-autolock-text">
+ <source>Automatic locking</source>
+ <extracomment>Text switch label</extracomment>
+ <translation>Automatisk låsning</translation>
+ </message>
+ <message id="foilnotes-settings_page-autolock-description">
+ <source>Require to enter Foil password after unlocking the screen.</source>
+ <extracomment>Text switch description</extracomment>
+ <translation>Kräv Foil-lösenord efter att skärmen låsts upp.</translation>
+ </message>
</context>
</TS>
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/translations/harbour-foilnotes-zh_CN.ts
^
|
@@ -394,5 +394,20 @@
<extracomment>Full screen info label</extracomment>
<translation type="unfinished">在 Foil Notes 全屏运行时触摸另一个支持 NFC 的设备</translation>
</message>
+ <message id="foilnotes-settings_page-header-version">
+ <source>Version %1</source>
+ <extracomment>Settings page header description (app version)</extracomment>
+ <translation type="unfinished">版本 %1</translation>
+ </message>
+ <message id="foilnotes-settings_page-autolock-text">
+ <source>Automatic locking</source>
+ <extracomment>Text switch label</extracomment>
+ <translation type="unfinished">自动锁定</translation>
+ </message>
+ <message id="foilnotes-settings_page-autolock-description">
+ <source>Require to enter Foil password after unlocking the screen.</source>
+ <extracomment>Text switch description</extracomment>
+ <translation type="unfinished">解锁屏幕后需要输入Foil密码。</translation>
+ </message>
</context>
</TS>
|
[-]
[+]
|
Changed |
_service:tar_git:harbour-foilnotes-1.1.1.tar.gz/translations/harbour-foilnotes.ts
^
|
@@ -397,5 +397,20 @@
<extracomment>Full screen info label</extracomment>
<translation>Touch another NFC capable device with Foil Notes running full screen.</translation>
</message>
+ <message id="foilnotes-settings_page-header-version">
+ <source>Version %1</source>
+ <extracomment>Settings page header description (app version)</extracomment>
+ <translation>Version %1</translation>
+ </message>
+ <message id="foilnotes-settings_page-autolock-text">
+ <source>Automatic locking</source>
+ <extracomment>Text switch label</extracomment>
+ <translation>Automatic locking</translation>
+ </message>
+ <message id="foilnotes-settings_page-autolock-description">
+ <source>Require to enter Foil password after unlocking the screen.</source>
+ <extracomment>Text switch description</extracomment>
+ <translation>Require to enter Foil password after unlocking the screen.</translation>
+ </message>
</context>
</TS>
|