Example #1
0
    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 an `cost` parameter
        corresponding to the `cost` argument :class:`BCryptHasher` takes.
        """
        return b"$".join([
            native_to_bytes(parsed_hash.name),
            int_to_bytes(parsed_hash.cost),
            parsed_hash.hash
        ])
Example #2
0
    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 `rounds` and `method`
        parameter, corresponding to the arguments passed to
        :class:`PBKDF2Hasher` as well as a `salt` parameter of type `str`.
        """
        return b"$".join([
            native_to_bytes(parsed_hash.name),
            parsed_hash.method.encode("ascii"),
            int_to_bytes(parsed_hash.rounds),
            hexlify(parsed_hash.salt),
            hexlify(parsed_hash.hash)
        ])