package com.rosetta.messenger.crypto

import org.junit.Test
import org.junit.Assert.*

/**
 * Unit tests for cryptographic utility functions
 */
class CryptoUtilsTest {
    
    @Test
    fun `hex encoding and decoding should work correctly`() {
        val original = "Hello, World!"
        val bytes = original.toByteArray()
        val hex = bytes.joinToString("") { "%02x".format(it) }
        val decoded = hex.chunked(2).map { it.toInt(16).toByte() }.toByteArray()
        val result = String(decoded)
        
        assertEquals("Hex encoding and decoding should preserve data", original, result)
    }
    
    @Test
    fun `publicKey should always be 130 characters hex`() {
        // Simulated valid public key format
        val validPublicKey = "04" + "a".repeat(128)
        
        assertTrue("Public key should start with 04", validPublicKey.startsWith("04"))
        assertEquals("Public key should be 130 chars", 130, validPublicKey.length)
        assertTrue("Public key should be valid hex", validPublicKey.all { it in '0'..'9' || it in 'a'..'f' || it in 'A'..'F' })
    }
    
    @Test
    fun `privateKey should always be 64 characters hex`() {
        // Simulated valid private key format
        val validPrivateKey = "a".repeat(64)
        
        assertEquals("Private key should be 64 chars", 64, validPrivateKey.length)
        assertTrue("Private key should be valid hex", validPrivateKey.all { it in '0'..'9' || it in 'a'..'f' || it in 'A'..'F' })
    }
}
