def test_is_bytes(self):
        """
        Bytes are just returned.
        """
        s = "föö".encode()

        rv = _ensure_bytes(s, "doesntmatter")

        assert isinstance(rv, bytes)
        assert s == rv
    def test_is_unicode(self):
        """
        Unicode is encoded using the specified encoding.
        """
        s = u"föö"

        rv = _ensure_bytes(s, "latin1")

        assert isinstance(rv, bytes)
        assert s.encode("latin1") == rv
    def test_is_str(self):
        """
        Unicode str is encoded using the specified encoding.
        """
        s = "föö"

        rv = _ensure_bytes(s, "latin1")

        assert isinstance(rv, bytes)
        assert s.encode("latin1") == rv
    def test_is_bytes(self):
        """
        Bytes are just returned.
        """
        s = u"föö".encode("utf-8")

        rv = _ensure_bytes(s, "doesntmatter")

        assert isinstance(rv, bytes)
        assert s == rv
Exemple #5
0
    def hashWithFixedSalt(self, password, salt):
        """
        Hash *password* and return an encoded hash.

        :param password: Password to hash.
        :param salt: Password salt, should be array of bytes (generate using os.urandom)
        :type password: ``bytes`` or ``unicode``

        :raises argon2.exceptions.HashingError: If hashing fails.

        :rtype: unicode
        """
        return low_level.hash_secret(
            secret=_ensure_bytes(password, self.encoding),
            salt=salt,
            time_cost=self.time_cost,
            memory_cost=self.memory_cost,
            parallelism=self.parallelism,
            hash_len=self.hash_len,
            type=Type.I,
        ).decode("ascii")