summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2022-02-10 13:36:09 +0100
committerjwijenbergh <jeroenwijenbergh@protonmail.com>2022-04-05 12:26:10 +0200
commit53b31fa9f103d8262b7c1d28c5714238902e5081 (patch)
tree5aa56e5e756f33f3753f5b5b4decdefe4782db61
parent23e63807085b13a9b221c3374d05099559583011 (diff)
Move python library load to init and fix build
Signed-off-by: jwijenbergh <jeroenwijenbergh@protonmail.com>
-rw-r--r--Makefile2
-rw-r--r--exports/Makefile2
-rw-r--r--exports/exports.go12
-rw-r--r--wrappers/csharp/EduVpnCommonTests/VerifyTests.cs2
-rw-r--r--wrappers/java-android/README.md2
-rw-r--r--wrappers/java-android/lib/build.gradle2
-rw-r--r--wrappers/php/tests/DiscoveryTest.php2
-rw-r--r--wrappers/python/eduvpncommon/__init__.py30
-rw-r--r--wrappers/python/eduvpncommon/discovery.py39
-rwxr-xr-xwrappers/python/test_discovery.py2
-rw-r--r--wrappers/swift/Tests/EduVpnCommonTests/EduVpnCommonTests.swift2
11 files changed, 50 insertions, 47 deletions
diff --git a/Makefile b/Makefile
index 45c75c3..36a19da 100644
--- a/Makefile
+++ b/Makefile
@@ -6,7 +6,7 @@ build:
test: test-go test-wrappers
test-go:
- go test
+ go test github.com/jwijenbergh/eduvpn-common/src
WRAPPERS ?= $(notdir $(patsubst %/,%,$(wildcard wrappers/*/)))
diff --git a/exports/Makefile b/exports/Makefile
index 3dcf2f0..a23f211 100644
--- a/exports/Makefile
+++ b/exports/Makefile
@@ -16,7 +16,7 @@ endif
# Build shared library and remove lib prefix (if any) from header name
# GOOS and GOARCH envvars are set by common.mk
# This extra target prevents unnecessary rebuild
-lib/$(GOOS)/$(GOARCH)/$(LIB_FILE): exports.go ../verify.go
+lib/$(GOOS)/$(GOARCH)/$(LIB_FILE): exports.go ../src/verify.go
CGO_ENABLED=1 go build -o $@ -buildmode=c-shared $<
mv lib/$(GOOS)/$(GOARCH)/$(LIB_PREFIX)$(LIB_NAME).h lib/$(GOOS)/$(GOARCH)/$(LIB_NAME).h || true # Normalize header name
diff --git a/exports/exports.go b/exports/exports.go
index c1ae79b..9ea8cba 100644
--- a/exports/exports.go
+++ b/exports/exports.go
@@ -2,20 +2,20 @@ package main
import "C"
-import "eduvpn-common"
+import "github.com/jwijenbergh/eduvpn-common/src"
// Functions here should probably not take string parameters, see https://pkg.go.dev/cmd/cgo#hdr-C_references_to_Go
-// Verify verifies a signature on a JSON file. See eduvpn_discovery.Verify for more details.
-// It returns 0 for a valid signature and a nonzero eduvpn_discovery.VerifyErrorCode otherwise.
+// Verify verifies a signature on a JSON file. See eduvpn.Verify for more details.
+// It returns 0 for a valid signature and a nonzero eduvpn.VerifyErrorCode otherwise.
// signatureFileContent must be UTF-8-encoded.
//export Verify
func Verify(signatureFileContent []byte, signedJson []byte, expectedFileName []byte, minSignTime uint64) int8 {
- valid, err := eduvpn_discovery.Verify(string(signatureFileContent), signedJson, string(expectedFileName), minSignTime)
+ valid, err := eduvpn.Verify(string(signatureFileContent), signedJson, string(expectedFileName), minSignTime, false)
if valid {
return 0
} else {
- return int8(err.(eduvpn_discovery.VerifyError).Code)
+ return int8(err.(eduvpn.VerifyError).Code)
}
}
@@ -24,7 +24,7 @@ func Verify(signatureFileContent []byte, signedJson []byte, expectedFileName []b
// keyString must be an ASCII Base64-encoded key.
//export InsecureTestingSetExtraKey
func InsecureTestingSetExtraKey(keyString []byte) {
- eduvpn_discovery.InsecureTestingSetExtraKey(string(keyString))
+ eduvpn.InsecureTestingSetExtraKey(string(keyString))
}
// Not used in library, but needed to compile.
diff --git a/wrappers/csharp/EduVpnCommonTests/VerifyTests.cs b/wrappers/csharp/EduVpnCommonTests/VerifyTests.cs
index c41696b..fba2161 100644
--- a/wrappers/csharp/EduVpnCommonTests/VerifyTests.cs
+++ b/wrappers/csharp/EduVpnCommonTests/VerifyTests.cs
@@ -10,7 +10,7 @@ namespace EduVpnCommonTests
public class VerifyTests
{
// Relative to e.g. EduVpnCommonTests/bin/Debug/net5.0
- readonly string testDataDir_ = $"{TestContext.CurrentContext.TestDirectory}/../../../../../../test_data";
+ readonly string testDataDir_ = $"{TestContext.CurrentContext.TestDirectory}/../../../../../../src/test_data";
[OneTimeSetUp]
public void OneTimeSetUp() =>
diff --git a/wrappers/java-android/README.md b/wrappers/java-android/README.md
index db55673..50e1868 100644
--- a/wrappers/java-android/README.md
+++ b/wrappers/java-android/README.md
@@ -79,7 +79,7 @@ Specify `NO_DAEMON=1` to add `--no-daemon`.
## Notes
The same Java code is used for the Android instrumented tests as for the unit tests. Both use Java resources that are
-copied from the `../../test_data` folder by Gradle.
+copied from the `../../src/test_data` folder by Gradle.
This library uses JNA, not JNI. Hence, there is no C wrapper. The library is dynamically opened with `dlopen`
via `libjnidispatch.so` which comes with the JNA AAR.
diff --git a/wrappers/java-android/lib/build.gradle b/wrappers/java-android/lib/build.gradle
index be666aa..04cb00e 100644
--- a/wrappers/java-android/lib/build.gradle
+++ b/wrappers/java-android/lib/build.gradle
@@ -54,7 +54,7 @@ android {
}
task copyTestData(type: Copy, description: 'Copy test_data to test resources') {
- from('../../../test_data') {
+ from('../../../src/test_data') {
exclude '**/*.py', '**/*.sh'
}
into sourceSets.test.resources.srcDirs[0].toPath().resolve('org/eduvpn/common')
diff --git a/wrappers/php/tests/DiscoveryTest.php b/wrappers/php/tests/DiscoveryTest.php
index 0653eaa..9a3e14c 100644
--- a/wrappers/php/tests/DiscoveryTest.php
+++ b/wrappers/php/tests/DiscoveryTest.php
@@ -8,7 +8,7 @@ use PHPUnit\Framework\TestCase;
class DiscoveryTest extends TestCase
{
- private const TEST_DATA_DIR = '../../test_data';
+ private const TEST_DATA_DIR = '../../src/test_data';
public static function setUpBeforeClass(): void
{
diff --git a/wrappers/python/eduvpncommon/__init__.py b/wrappers/python/eduvpncommon/__init__.py
index e69de29..e9d0284 100644
--- a/wrappers/python/eduvpncommon/__init__.py
+++ b/wrappers/python/eduvpncommon/__init__.py
@@ -0,0 +1,30 @@
+from ctypes import *
+from collections import defaultdict
+import pathlib
+import platform
+
+_lib_prefixes = defaultdict(lambda: "lib", {
+ "windows": "",
+})
+
+_lib_suffixes = defaultdict(lambda: ".so", {
+ "windows": ".dll",
+ "darwin": ".dylib",
+})
+
+_os = platform.system().lower()
+
+_libname = "eduvpn_common"
+_libfile = f"{_lib_prefixes[_os]}{_libname}{_lib_suffixes[_os]}"
+# Library should have been copied to the lib/ folder
+lib = cdll.LoadLibrary(str(pathlib.Path(__file__).parent / "lib" / _libfile))
+
+
+class GoSlice(Structure):
+ _fields_ = [("data", POINTER(c_char)), ("len", c_int64), ("cap", c_int64)]
+
+ @staticmethod
+ def make(bs: bytes) -> "GoSlice":
+ return GoSlice((c_char * len(bs))(*bs), len(bs), len(bs))
+
+
diff --git a/wrappers/python/eduvpncommon/discovery.py b/wrappers/python/eduvpncommon/discovery.py
index 34a03ba..371bd71 100644
--- a/wrappers/python/eduvpncommon/discovery.py
+++ b/wrappers/python/eduvpncommon/discovery.py
@@ -1,36 +1,9 @@
-import pathlib
-import platform
-from collections import defaultdict
+from . import lib, GoSlice
from ctypes import *
from enum import Enum
-_lib_prefixes = defaultdict(lambda: "lib", {
- "windows": "",
-})
-
-_lib_suffixes = defaultdict(lambda: ".so", {
- "windows": ".dll",
- "darwin": ".dylib",
-})
-
-_os = platform.system().lower()
-
-_libname = "eduvpn_common"
-_libfile = f"{_lib_prefixes[_os]}{_libname}{_lib_suffixes[_os]}"
-# Library should have been copied to the lib/ folder
-_lib = cdll.LoadLibrary(str(pathlib.Path(__file__).parent / "lib" / _libfile))
-
-
-class _GoSlice(Structure):
- _fields_ = [("data", POINTER(c_char)), ("len", c_int64), ("cap", c_int64)]
-
- @staticmethod
- def make(bs: bytes) -> "_GoSlice":
- return _GoSlice((c_char * len(bs))(*bs), len(bs), len(bs))
-
-
-_lib.Verify.argtypes, _lib.Verify.restype = [_GoSlice, _GoSlice, _GoSlice, c_uint64], c_int8
-_lib.InsecureTestingSetExtraKey.argtypes, _lib.InsecureTestingSetExtraKey.restype = [_GoSlice], None
+lib.Verify.argtypes, lib.Verify.restype = [GoSlice, GoSlice, GoSlice, c_uint64], c_int64
+lib.InsecureTestingSetExtraKey.argtypes, lib.InsecureTestingSetExtraKey.restype = [GoSlice], None
class VerifyErrorCode(Enum):
@@ -76,8 +49,8 @@ def verify(signature: bytes, signed_json: bytes, expected_file_name: str, min_si
:raises VerifyException: If signature verification fails or expectedFileName is not one of the allowed values.
"""
- err = _lib.Verify(_GoSlice.make(signature), _GoSlice.make(signed_json),
- _GoSlice.make(expected_file_name.encode()), min_sign_time)
+ err = lib.Verify(GoSlice.make(signature), GoSlice.make(signed_json),
+ GoSlice.make(expected_file_name.encode()), min_sign_time)
if err:
raise VerifyError(err)
@@ -85,4 +58,4 @@ def verify(signature: bytes, signed_json: bytes, expected_file_name: str, min_si
def _insecure_testing_set_extra_key(key_string: str) -> None:
"""Use for testing only, see Go documentation."""
- _lib.InsecureTestingSetExtraKey(_GoSlice.make(key_string.encode()))
+ lib.InsecureTestingSetExtraKey(GoSlice.make(key_string.encode()))
diff --git a/wrappers/python/test_discovery.py b/wrappers/python/test_discovery.py
index eaf68dd..a1a70af 100755
--- a/wrappers/python/test_discovery.py
+++ b/wrappers/python/test_discovery.py
@@ -3,7 +3,7 @@
import unittest
import eduvpncommon.discovery as discovery
-test_data_dir = "../../test_data"
+test_data_dir = "../../src/test_data"
def read_bytes(path: str) -> bytes:
diff --git a/wrappers/swift/Tests/EduVpnCommonTests/EduVpnCommonTests.swift b/wrappers/swift/Tests/EduVpnCommonTests/EduVpnCommonTests.swift
index 7254509..bd2eabd 100644
--- a/wrappers/swift/Tests/EduVpnCommonTests/EduVpnCommonTests.swift
+++ b/wrappers/swift/Tests/EduVpnCommonTests/EduVpnCommonTests.swift
@@ -2,7 +2,7 @@ import XCTest
@testable import EduVpnCommon
final class EduVpnCommonTests: XCTestCase {
- private static let testDataDir = "../../test_data"
+ private static let testDataDir = "../../src/test_data"
override class func setUp() {
// Swift is confused by CRLF, so on some systems we cannot just take the second-to-last element