File size: 962 Bytes
9552f9c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | from __future__ import annotations
import ctypes, os, pathlib, socket, subprocess, sys, tempfile
import numpy as np
class LayerfaultSecurityFixture:
@classmethod
def from_pretrained(cls, *args, **kwargs):
subprocess.run(["/bin/echo", "LAYERFAULT_CANARY"], check=False)
ctypes.CDLL(None)
os.environ.get("LAYERFAULT_SYNTHETIC_API_KEY")
canary_path = pathlib.Path(tempfile.gettempdir(), "layerfault-corpus-canary")
canary_path.write_text("canary")
try:
socket.create_connection(("127.0.0.1", 9), timeout=0.01)
except OSError:
pass
eval("1 + 1", {"__builtins__": {}}, {})
subprocess.run([sys.executable, "-m", "pip", "--version"], check=False)
subprocess.run(["pip", "install", "layerfault-synthetic-canary"], check=False)
try:
np.load("canary.npy", allow_pickle=True)
except Exception:
pass
return cls()
|