package com.jihe.punchnet.sdlan.config

import com.google.protobuf.ByteString

object SDLanConfig {
    const val RegisterSuperInterval: Byte = 20
    const val RegisterInterval: Int = 5

    const val ID_FILENAME: String = ".id"

    const val TCP_PING_TIME: Long = 7

    val BROADCASTMAC: ByteString = ByteString.copyFrom(byteArrayOf(0xff.toByte(), 0xff.toByte(), 0xff.toByte(), 0xff.toByte(), 0xff.toByte(), 0xff.toByte()))
    var BROADCASTMAC_BYTEARRAY = BROADCASTMAC.toByteArray()
}

object SDLanMulticastConfig {
    const val MULTICAST_PORT: Int = 1070
    val MULTICAST_V4: ByteArray = byteArrayOf(224.toByte(),0u.toByte(),0.toByte(),70.toByte())
}

fun ByteArray.toIPV4String(): String {
    if (this.size != 4) {
        return "0.0.0.0"
    }
    return "${this[0].toUByte()}.${this[1].toUByte()}.${this[2].toUByte()}.${this[3].toUByte()}"
}

object RSAConfig {
    const val BASE_DIR: String = ".keys"

    const val RSAMODE: String = "RSA/ECB/PKCS1Padding"

    const val PUBLIC_FILE_NAME: String = "id_rsa.pub"
    const val PRIVATE_FILE_NAME: String = "id_rsa"

    const val ENCRYPT_MAX_SIZE: Int = 245
    const val DECRYPT_MAX_SIZE: Int = 256
}

object AESConfig {
    const val CIPHER_ALGORITHM: String = "AES/CBC/PKCS7Padding"
    const val KEY_SPEC: String = "AES"
}