-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecreq.py
96 lines (66 loc) · 2.16 KB
/
decreq.py
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# Copyright (c) 2023
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""
ilafalseone.decreq
Decrypting request manager.
"""
import logging
from abc import abstractmethod
from .basemodule import Module
from .session import Session
from .restype import ResType, ResTypeManager, Resource, Serializable
from .utils import Inner
class Cryptic(Serializable):
"""Cryptic class."""
__slots__ = ()
@property
@abstractmethod
def material(self) -> Serializable:
"""Material."""
def is_decrypted(self) -> bool:
"""If self is decrypted."""
return self.material is not None
def has_access(self, con: Session) -> bool:
"""If other has access to the material."""
raise NotImplementedError
class InnerSer[T: Serializable](Serializable, Inner[T]):
"""Inner Serializable class."""
@property
def rtype(self) -> ResType:
return self._outer.rtype
@property
def rdig(self) -> bytes:
return self._outer.rdig
class InnerRes[T: Resource](InnerSer[T]):
"""Inner Resource class."""
__eq__ = Serializable.__eq__
__hash__ = Serializable.__hash__
@property
def rid(self) -> int:
return self._outer.rid
class ResReqManager(Module):
"""Cryptic resource request manager."""
name = '.decreq'
def __init__(self):
super().__init__()
self._rtyper: ResTypeManager = None
def start(self):
"""Start the module."""
account = self._account
self._rtyper = account.modules[ResTypeManager.name]
logging.debug("module decreq started")
def serv_req(self, con, buf):
try:
type_ = self.restype_manager.type.mapping.read(con, buf)
res = type_.mapping.read(con, buf)
if isinstance(res, Cryptic) and res.has_access(con):
raise NotImplementedError
except ValueError:
buf.read()
return
logging.debug("handled req")
@property
def restype_manager(self) -> ResTypeManager:
"""RTypeMapping instance bounded."""
return self._rtyper