Skip to content

Commit

Permalink
fix cipher init
Browse files Browse the repository at this point in the history
Signed-off-by: sagewe <wbwmat@gmail.com>
  • Loading branch information
sagewe committed Nov 21, 2023
1 parent cc734f3 commit a443e04
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
10 changes: 8 additions & 2 deletions python/fate/arch/context/_cipher.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@


class CipherKit:
def __init__(self, ctx: "Context", device: device, cipher_mapping: typing.Optional[dict] = None) -> None:
self.ctx = ctx
def __init__(self, device: device, cipher_mapping: typing.Optional[dict] = None) -> None:
self._device = device
if cipher_mapping is None:
self._cipher_mapping = {}
Expand All @@ -35,6 +34,11 @@ def __init__(self, ctx: "Context", device: device, cipher_mapping: typing.Option
self._allow_custom_random_seed = False
self._custom_random_seed = 42

self.ctx = None

def set_ctx(self, ctx: "Context"):
self.ctx = ctx

def set_phe(self, device: device, options: typing.Optional[dict]):
if "phe" not in self._cipher_mapping:
self._cipher_mapping["phe"] = {}
Expand All @@ -54,6 +58,8 @@ def _set_default_phe(self):

@property
def phe(self):
if self.ctx is None:
raise ValueError("context not set")
self._set_default_phe()
if self._device not in self._cipher_mapping["phe"]:
raise ValueError(f"no impl exists for device {self._device}")
Expand Down
3 changes: 2 additions & 1 deletion python/fate/arch/context/_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ def __init__(
if self._namespace is None:
self._namespace = default_ns
if self._cipher is None:
self._cipher: CipherKit = CipherKit(self, device)
self._cipher: CipherKit = CipherKit(device)
self._cipher.set_ctx(self)

self._role_to_parties = None
self._is_destroyed = False
Expand Down

0 comments on commit a443e04

Please sign in to comment.