Browse files

Document HMACHasher.{format,parse}

  • Loading branch information...
1 parent e6e8752 commit c20cbab1f93cb935d61d2cc7fab9d9896565dda6 @DasIch committed Apr 4, 2013
Showing with 13 additions and 0 deletions.
  1. +13 −0 pwhash/hashers.py
View
13 pwhash/hashers.py
@@ -543,13 +543,26 @@ def _create_from_bytes(self, password):
))
def format(self, parsed_hash):
+ """
+ Takes a :class:`PasswordHash` object as returned by :meth:`parse` and
+ returns a byte string that must be parseable by :meth:`parse`.
+
+ The given hash object is expected to have a `salt` parameter of type
+ `str`.
+ """
return b"$".join([
native_to_bytes(parsed_hash.name),
hexlify(parsed_hash.salt),
hexlify(parsed_hash.hash)
])
def parse(self, formatted_hash):
+ """
+ Parses a `formatted_hash` as returned by :meth:`format` and returns a
+ :class:`PasswordHash` object.
+
+ The returned hash object is expected to have a `salt` parameter.
+ """
salt, hash = UpgradeableHasher.parse(self, formatted_hash).split(b"$", 1)
return PasswordHash(self.name, hash, salt=unhexlify(salt))

0 comments on commit c20cbab

Please sign in to comment.