refactor: extract EditBase64Preference from EditChannelDialog

closes #944
This commit is contained in:
andrekir 2024-08-22 19:58:24 -03:00
parent d387c7bd04
commit fa85955e85
4 changed files with 128 additions and 72 deletions

View file

@ -6,6 +6,7 @@ import com.geeksville.mesh.ConfigKt.loRaConfig
import com.geeksville.mesh.ConfigProtos
import com.geeksville.mesh.channelSettings
import com.google.protobuf.ByteString
import java.security.SecureRandom
/** Utility function to make it easy to declare byte arrays - FIXME move someplace better */
fun byteArrayOfInts(vararg ints: Int) = ByteArray(ints.size) { pos -> ints[pos].toByte() }
@ -37,6 +38,13 @@ data class Channel(
txEnabled = true
}
)
fun getRandomKey(size: Int = 32): ByteString {
val bytes = ByteArray(size)
val random = SecureRandom()
random.nextBytes(bytes)
return ByteString.copyFrom(bytes)
}
}
/// Return the name of our channel as a human readable string. If empty string, assume "Default" per mesh.proto spec