wireguard: reserved int list

This commit is contained in:
arm64v8a 2023-07-19 13:29:24 +09:00
parent 0ac26db5ba
commit e4726952e8

View File

@ -1,8 +1,31 @@
package io.nekohasekai.sagernet.fmt.wireguard
import moe.matsuri.nb4a.SingBoxOptions
import moe.matsuri.nb4a.utils.Util
import moe.matsuri.nb4a.utils.listByLineOrComma
fun genReserved(anyStr: String): String {
try {
val list = anyStr.listByLineOrComma()
val ba = ByteArray(3)
if (list.size == 3) {
list.forEachIndexed { index, s ->
val i = s
.replace("[", "")
.replace("]", "")
.replace(" ", "")
.toIntOrNull() ?: return anyStr
ba[index] = i.toByte()
}
return Util.b64EncodeOneLine(ba)
} else {
return anyStr
}
} catch (e: Exception) {
return anyStr
}
}
fun buildSingBoxOutboundWireguardBean(bean: WireGuardBean): SingBoxOptions.Outbound_WireGuardOptions {
return SingBoxOptions.Outbound_WireGuardOptions().apply {
type = "wireguard"
@ -13,6 +36,6 @@ fun buildSingBoxOutboundWireguardBean(bean: WireGuardBean): SingBoxOptions.Outbo
peer_public_key = bean.peerPublicKey
pre_shared_key = bean.peerPreSharedKey
mtu = bean.mtu
if (bean.reserved.isNotBlank()) reserved = bean.reserved
if (bean.reserved.isNotBlank()) reserved = genReserved(bean.reserved)
}
}