Skip to content

Commit 9ab3f70

Browse files
grpc: add support for session crypto info to backend.py
Signed-off-by: John Mulligan <[email protected]>
1 parent b9b929d commit 9ab3f70

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

sambacc/grpc/backend.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# along with this program. If not, see <http://www.gnu.org/licenses/>
1717
#
1818

19-
from typing import Any, Union
19+
from typing import Any, Union, Optional
2020

2121
import dataclasses
2222
import json
@@ -35,6 +35,19 @@ class Versions:
3535
container_version: str = ""
3636

3737

38+
@dataclasses.dataclass
39+
class SessionCrypto:
40+
cipher: str
41+
degree: str
42+
43+
@classmethod
44+
def load(cls, json_object: dict[str, Any]) -> Self:
45+
cipher = json_object.get("cipher", "")
46+
cipher = "" if cipher == "-" else cipher
47+
degree = json_object.get("degree", "")
48+
return cls(cipher=cipher, degree=degree)
49+
50+
3851
@dataclasses.dataclass
3952
class Session:
4053
session_id: str
@@ -45,9 +58,15 @@ class Session:
4558
session_dialect: str
4659
uid: int
4760
gid: int
61+
encryption: Optional[SessionCrypto] = None
62+
signing: Optional[SessionCrypto] = None
4863

4964
@classmethod
5065
def load(cls, json_object: dict[str, Any]) -> Self:
66+
_encryption = json_object.get("encryption")
67+
encryption = SessionCrypto.load(_encryption) if _encryption else None
68+
_signing = json_object.get("signing")
69+
signing = SessionCrypto.load(_signing) if _signing else None
5170
return cls(
5271
session_id=json_object.get("session_id", ""),
5372
username=json_object.get("username", ""),
@@ -57,6 +76,8 @@ def load(cls, json_object: dict[str, Any]) -> Self:
5776
session_dialect=json_object.get("session_dialect", ""),
5877
uid=int(json_object.get("uid", -1)),
5978
gid=int(json_object.get("gid", -1)),
79+
encryption=encryption,
80+
signing=signing,
6081
)
6182

6283

0 commit comments

Comments
 (0)