"""Tests for crypto seam-spec."""

from orxaq.kernel.crypto import constant_time_compare, generate_token, hash_sha256


class TestHashSha256:
    def test_deterministic(self):
        assert hash_sha256(b"hello") == hash_sha256(b"hello")

    def test_different_inputs_different_hashes(self):
        assert hash_sha256(b"hello") != hash_sha256(b"world")

    def test_returns_hex_string(self):
        result = hash_sha256(b"test")
        assert len(result) == 64
        assert all(c in "0123456789abcdef" for c in result)


class TestGenerateToken:
    def test_correct_length(self):
        token = generate_token(32)
        assert len(token) == 64  # hex encoding doubles byte count

    def test_unique_tokens(self):
        t1 = generate_token()
        t2 = generate_token()
        assert t1 != t2


class TestConstantTimeCompare:
    def test_equal_strings(self):
        assert constant_time_compare("abc", "abc") is True

    def test_different_strings(self):
        assert constant_time_compare("abc", "xyz") is False

    def test_different_lengths(self):
        assert constant_time_compare("short", "longer_string") is False
