Skip to content

Commit bf64c27

Browse files
committed
Add GetKey to python2, closes #18
1 parent 1e71d9b commit bf64c27

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

cryptolens_python2.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,45 @@ def activate(token, rsa_pub_key, product_id, key, machine_code, fields_to_return
246246
except Exception:
247247
return (None, "The signature check failed.")
248248

249+
@staticmethod
250+
def get_key(token, rsa_pub_key, product_id, key, fields_to_return = 0,\
251+
metadata = False, floating_time_interval = 0):
252+
253+
"""
254+
Calls the GetKey method in Web API 3 and returns a tuple containing
255+
(LicenseKey, Message). If an error occurs, LicenseKey will be None. If
256+
everything went well, no message will be returned.
257+
258+
More docs: https://app.cryptolens.io/docs/api/v3/GetKey
259+
"""
260+
261+
response = Response("","",0,"")
262+
263+
try:
264+
response = Response.from_string(HelperMethods.send_request("key/getkey", {"token":token,\
265+
"ProductId":product_id,\
266+
"key":key,\
267+
"FieldsToReturn":fields_to_return,\
268+
"metadata":metadata,\
269+
"FloatingTimeInterval": floating_time_interval,\
270+
"Sign":"True",\
271+
"SignMethod":1}))
272+
except Exception:
273+
return (None, "Could not contact the server.")
274+
275+
pubkey = RSAPublicKey.from_string(rsa_pub_key)
276+
277+
if response.result == 1:
278+
return (None, response.message)
279+
else:
280+
try:
281+
if HelperMethods.verify_signature(response, pubkey):
282+
return (LicenseKey.from_response(response), response.message)
283+
else:
284+
return (None, "The signature check failed.")
285+
except Exception:
286+
return (None, "The signature check failed.")
287+
249288
@staticmethod
250289
def create_trial_key(token, product_id, machine_code):
251290
"""

0 commit comments

Comments
 (0)