gitscope
https://dev.kronoz.win/r/marzneshin.git
app/utils/keygen.py · v0.1.4
Source
1 a47eb4c Dawsh 2y ago # import hashlib
2 a47eb4c Dawsh 2y ago import xxhash
3 a47eb4c Dawsh 2y ago import uuid
4 a47eb4c Dawsh 2y ago from app.models.proxy import ProxyTypes
5 a47eb4c Dawsh 2y ago
6 a47eb4c Dawsh 2y ago def gen_uuid(key: str) -> str:
7 a47eb4c Dawsh 2y ago return str(uuid.UUID(bytes=xxhash.xxh128(key.encode()).digest()))
8 a47eb4c Dawsh 2y ago
9 a47eb4c Dawsh 2y ago def gen_password(key: str) -> str:
10 a47eb4c Dawsh 2y ago return xxhash.xxh128(key.encode()).hexdigest()
11 a47eb4c Dawsh 2y ago
12 a47eb4c Dawsh 2y ago def generate_settings(key: str, protocol: ProxyTypes) -> dict:
13 a47eb4c Dawsh 2y ago if protocol in (ProxyTypes.Trojan, ProxyTypes.Shadowsocks):
14 a47eb4c Dawsh 2y ago return ProxyTypes(protocol).settings_model(password=gen_password(key)).dict(no_obj=True)
15 a47eb4c Dawsh 2y ago elif protocol in (ProxyTypes.VMess, ProxyTypes.VLESS):
16 a47eb4c Dawsh 2y ago return ProxyTypes(protocol).settings_model(id=gen_uuid(key)).dict(no_obj=True)
17 a47eb4c Dawsh 2y ago