-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecrypt_message.py
More file actions
executable file
·72 lines (55 loc) · 1.89 KB
/
decrypt_message.py
File metadata and controls
executable file
·72 lines (55 loc) · 1.89 KB
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
#!/usr/local/bin/python3
import check
import my_errors
my_errors.make_classes(my_errors.errors)
from itsdangerous import (TimedJSONWebSignatureSerializer as Serializer)
import catch
"""
Provides a number of decorators to decode encrypted messages.
Each of these decorators will decrypt a corresponding encryption
from its pair module 'send_securily'
"""
def decrypt_m(message, key):
s = Serializer(key)
return s.loads(message)
@catch.decode
def with_token(f):
@check.reqs(['token', 'message'])
def wrapped_f(self, *args, **kwargs):
token = kwargs.get('token')
message = kwargs.get('message')
data = self.s.loads(token)
s = Serializer(data['key'])
decoded_message = s.loads(message)
return data['key'], f(self, *args, **decoded_message)
return wrapped_f
@catch.decode
def with_key(f):
def wrapped_f(self, *args, **kwargs):
r = f(self, *args, **kwargs)
if r.status_code != 200:
return {'status': r.status_code, 'message': r.json()}
message = r.json()['message']
c = r.status_code
decoded_message = decrypt_m(message, self.key)
return {'status': c, 'message': decoded_message}
return wrapped_f
@catch.decode
def with_password(f):
def wrapped_f(self, *args, **kwargs):
r = f(self, *args, **kwargs)
if r.status_code != 200:
return {'status': r.status_code, 'message': r.json()}
message = r.json()['message']
c = r.status_code
decoded_message = decrypt_m(message, self.password)
return {'status': c, 'message': decoded_message}
return wrapped_f
@catch.decode
def with_public_key(f):
@check.reqs(['message'])
def wrapped_f(self, *args, **kwargs):
message = kwargs.get('message')
decoded_message = self.s_pub.loads(message)
return f(self, *args, **decoded_message)
return wrapped_f