summaryrefslogtreecommitdiff
path: root/wrappers/python/eduvpncommon/discovery.py
diff options
context:
space:
mode:
Diffstat (limited to 'wrappers/python/eduvpncommon/discovery.py')
-rw-r--r--wrappers/python/eduvpncommon/discovery.py39
1 files changed, 6 insertions, 33 deletions
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()))