-
Notifications
You must be signed in to change notification settings - Fork 5
/
rsa.py
56 lines (46 loc) · 1.41 KB
/
rsa.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
import jwt
import json
policy = ([{
'att': 'patient+thepatientid',
'act': 'read'
}, {
'att': 'doctor, thepatientdoctor',
'act': 'write'
}])
# policies = json.loads(policy)
def validate(policies, att1, att2):
for policy in policies:
print(policy)
att = policy['att']
act = policy['act']
if att1 in att:
print("You can access that data")
print(f'You have an access to {policy["act"]}')
if act == 'write':
return 'rw'
elif act == 'read':
return 'r'
else:
return 'rw'
elif att1 in att:
print("You can access that data")
print(f'You have an access to {policy["act"]}')
if act == 'write':
return 'rw'
elif act == 'read':
return 'r'
else:
return 'rw'
continue
else:
return 'none'
action = validate(policy, 'patient+thepatientid', 'patient-thepatientid')
print(action)
# secret_key = open('keypair.pem').read()
# token = jwt.encode({'policy': policy}, secret_key,
# algorithm='RS256')
# print(token.split('.'))
# # print(secret_key)
# public_key = open('publickey.crt').read()
# string = jwt.decode(token, public_key, algorithms='RS256')
# print(string)