Skip to content

Commit 1e71d9b

Browse files
committed
Add GetKey method in Python 3 for #18
1 parent c09b439 commit 1e71d9b

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

licensing/methods.py

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,46 @@ def activate(token, rsa_pub_key, product_id, key, machine_code, fields_to_return
5959
return (None, "The signature check failed.")
6060
except Exception:
6161
return (None, "The signature check failed.")
62-
62+
63+
@staticmethod
64+
def get_key(token, rsa_pub_key, product_id, key, fields_to_return = 0,\
65+
metadata = False, floating_time_interval = 0):
66+
67+
"""
68+
Calls the GetKey method in Web API 3 and returns a tuple containing
69+
(LicenseKey, Message). If an error occurs, LicenseKey will be None. If
70+
everything went well, no message will be returned.
71+
72+
More docs: https://app.cryptolens.io/docs/api/v3/GetKey
73+
"""
74+
75+
response = Response("","",0,"")
76+
77+
try:
78+
response = Response.from_string(HelperMethods.send_request("key/getkey", {"token":token,\
79+
"ProductId":product_id,\
80+
"key":key,\
81+
"FieldsToReturn":fields_to_return,\
82+
"metadata":metadata,\
83+
"FloatingTimeInterval": floating_time_interval,\
84+
"Sign":"True",\
85+
"SignMethod":1}))
86+
except Exception:
87+
return (None, "Could not contact the server.")
88+
89+
pubkey = RSAPublicKey.from_string(rsa_pub_key)
90+
91+
if response.result == 1:
92+
return (None, response.message)
93+
else:
94+
try:
95+
if HelperMethods.verify_signature(response, pubkey):
96+
return (LicenseKey.from_response(response), response.message)
97+
else:
98+
return (None, "The signature check failed.")
99+
except Exception:
100+
return (None, "The signature check failed.")
101+
63102
@staticmethod
64103
def create_trial_key(token, product_id, machine_code):
65104
"""

0 commit comments

Comments
 (0)