-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path_base_classes.py
51 lines (38 loc) · 1.09 KB
/
_base_classes.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
import base64
import typing as t
from pydantic import BaseModel
__all__ = ["RequestModel", "ResponseModel", "parse_sm2_pri", "parse_sm2_pub"]
class RequestModel(BaseModel):
secure: bool
host: str
port: int
version: str
method: str
path: str
query: t.Dict[str, t.List[str]]
headers: t.Dict[str, t.List[str]]
contentBase64: str
@property
def content(self) -> bytes:
return base64.b64decode(self.contentBase64)
@content.setter
def content(self, content: bytes):
self.contentBase64 = base64.b64encode(content).decode()
class ResponseModel(BaseModel):
version: str
statusCode: int
reason: str
headers: t.Dict[str, t.List[str]]
contentBase64: str
@property
def content(self) -> bytes:
return base64.b64decode(self.contentBase64)
@content.setter
def content(self, content: bytes):
self.contentBase64 = base64.b64encode(content).decode()
def parse_sm2_pri(pri):
pri_hex = pri.hex()
return pri_hex[72 : 72 + 64]
def parse_sm2_pub(pub):
pub_hex = pub.hex()
return pub_hex[-128:]