Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

Commit

Permalink
clarify EncryptingPacker API a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
chadwhitacre committed May 7, 2016
1 parent ae6ace0 commit 8a22427
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions gratipay/security/crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,17 @@ def __init__(self, key, *old_keys):
self.fernet = MultiFernet([Fernet(k) for k in keys])

def pack(self, obj):
"""Given a JSON-serializable object, return an encrypted byte string.
"""Given a JSON-serializable object, return a `Fernet`_ token.
"""
obj = json.dumps(obj) # serialize to unicode
obj = obj.encode('utf8') # convert to bytes
obj = self.fernet.encrypt(obj) # encrypt
return obj

def unpack(self, obj):
"""Given an encrypted byte string, return a Python object.
def unpack(self, token):
"""Given a `Fernet`_ token with JSON in the ciphertext, return a Python object.
"""
obj = token
if not type(obj) is bytes:
raise TypeError("need bytes, got {}".format(type(obj)))
obj = self.fernet.decrypt(obj) # decrypt
Expand Down

0 comments on commit 8a22427

Please sign in to comment.