This commit is contained in:
2025-11-05 06:40:22 +00:00
parent 22299a1676
commit 299586e6ee
2 changed files with 11 additions and 46 deletions
+8 -46
View File
@@ -14,12 +14,9 @@ Exports:
- alloc_aligned(size, alignment): return (void*) pointer with requested alignment - alloc_aligned(size, alignment): return (void*) pointer with requested alignment
""" """
from __future__ import annotations
import os import os
import sys import sys
from pathlib import Path from typing import Any
from typing import Any, Iterable
from cffi import FFI from cffi import FFI
@@ -410,34 +407,6 @@ ffi.cdef(
) )
def _candidate_paths() -> Iterable[str]:
# 1) Explicit override
p = os.environ.get("AEGIS_LIB_PATH")
if p:
yield p
# 2) Directory override
d = os.environ.get("AEGIS_LIB_DIR")
if d:
yield str(Path(d) / _platform_lib_name())
# 3) Local builds relative to this file
here = Path(__file__).resolve()
repo_root = here.parents[2] # python/aegis/_loader.py -> repo root
for rel in (
"build-shared-clang/libaegis.so",
"build-shared/libaegis.so",
"build/libaegis.so",
"zig-out/lib/libaegis.so",
):
path = repo_root / rel
if path.exists():
yield str(path)
# 4) Let the dynamic loader search system paths
yield _platform_lib_name() # e.g. "libaegis.so" or "aegis"
def _platform_lib_name() -> str: def _platform_lib_name() -> str:
if sys.platform.startswith("linux"): if sys.platform.startswith("linux"):
return "libaegis.so" return "libaegis.so"
@@ -449,20 +418,13 @@ def _platform_lib_name() -> str:
def _load_libaegis(): def _load_libaegis():
last_err: Exception | None = None # Let the dynamic loader search system paths
for cand in _candidate_paths(): try:
try: lib = ffi.dlopen(_platform_lib_name())
lib = ffi.dlopen(str(cand)) return lib
return lib except Exception as e:
except Exception as e: # try next candidate hint = "Install libaegis system-wide."
last_err = e raise OSError(f"Could not load libaegis: {e}\n{hint}")
continue
# If we get here, we couldn't load the library
hint = (
"Set AEGIS_LIB_PATH to the full path of libaegis or AEGIS_LIB_DIR to the folder "
"containing it, or install libaegis system-wide."
)
raise OSError(f"Could not load libaegis: {last_err}\n{hint}")
def _load_libc(): def _load_libc():
+3
View File
@@ -15,6 +15,9 @@ classifiers = [
"Operating System :: OS Independent", "Operating System :: OS Independent",
"Topic :: Security :: Cryptography", "Topic :: Security :: Cryptography",
] ]
dependencies = [
"cffi>=2.0.0",
]
[project.urls] [project.urls]
Homepage = "https://github.com/aegis-aead/libaegis" Homepage = "https://github.com/aegis-aead/libaegis"