refactor(data): общий ByteArray.toHex вместо трёх копий форматирования
This commit is contained in:
1 parent
cc54b2892f
commit
80ed5dcb1a
2 files changed
+16
-4
No files matched your search
@@ -2,6 +2,18 @@ package com.freeturn.app.data.config
|
|||||||
|
|
||||||
import java.security.SecureRandom
|
import java.security.SecureRandom
|
||||||
|
|
||||||
|
private val HEX_DIGITS = "0123456789abcdef".toCharArray()
|
||||||
|
|
||||||
|
internal fun ByteArray.toHex(): String {
|
||||||
|
val out = CharArray(size * 2)
|
||||||
|
for (i in indices) {
|
||||||
|
val v = this[i].toInt() and 0xFF
|
||||||
|
out[i * 2] = HEX_DIGITS[v ushr 4]
|
||||||
|
out[i * 2 + 1] = HEX_DIGITS[v and 0x0F]
|
||||||
|
}
|
||||||
|
return String(out)
|
||||||
|
}
|
||||||
|
|
||||||
object DnsMode {
|
object DnsMode {
|
||||||
const val AUTO = "auto"
|
const val AUTO = "auto"
|
||||||
const val PLAIN = "plain"
|
const val PLAIN = "plain"
|
||||||
@@ -32,7 +44,7 @@ object ObfProfile {
|
|||||||
fun isValidKey(key: String): Boolean = key.matches(KEY_REGEX)
|
fun isValidKey(key: String): Boolean = key.matches(KEY_REGEX)
|
||||||
|
|
||||||
fun generateKey(): String =
|
fun generateKey(): String =
|
||||||
ByteArray(32).also { SecureRandom().nextBytes(it) }.joinToString("") { "%02x".format(it) }
|
ByteArray(32).also { SecureRandom().nextBytes(it) }.toHex()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ядро не принимает IPv6-адреса в скобках.
|
// Ядро не принимает IPv6-адреса в скобках.
|
||||||
@@ -49,7 +61,7 @@ object ClientId {
|
|||||||
fun isValid(id: String): Boolean = id.matches(ID_REGEX)
|
fun isValid(id: String): Boolean = id.matches(ID_REGEX)
|
||||||
|
|
||||||
fun generate(): String =
|
fun generate(): String =
|
||||||
ByteArray(16).also { SecureRandom().nextBytes(it) }.joinToString("") { "%02x".format(it) }
|
ByteArray(16).also { SecureRandom().nextBytes(it) }.toHex()
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Режим проброса (-mode): udp - датаграммы WireGuard, tcp - поток Xray/sing-box. */
|
/** Режим проброса (-mode): udp - датаграммы WireGuard, tcp - поток Xray/sing-box. */
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import android.content.pm.PackageManager
|
|||||||
import android.content.pm.Signature
|
import android.content.pm.Signature
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import androidx.core.content.FileProvider
|
import androidx.core.content.FileProvider
|
||||||
|
import com.freeturn.app.data.config.toHex
|
||||||
import com.freeturn.app.domain.UpdateState
|
import com.freeturn.app.domain.UpdateState
|
||||||
import kotlinx.coroutines.CancellationException
|
import kotlinx.coroutines.CancellationException
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
@@ -195,8 +196,7 @@ class AppUpdater(private val context: Context) {
|
|||||||
info.signatures
|
info.signatures
|
||||||
}
|
}
|
||||||
return sigs.orEmpty().map { sig ->
|
return sigs.orEmpty().map { sig ->
|
||||||
MessageDigest.getInstance("SHA-256").digest(sig.toByteArray())
|
MessageDigest.getInstance("SHA-256").digest(sig.toByteArray()).toHex()
|
||||||
.joinToString("") { "%02x".format(it) }
|
|
||||||
}.toSet()
|
}.toSet()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user