mirror of
https://github.com/MatsuriDayo/NekoBoxForAndroid.git
synced 2025-12-19 06:30:05 +08:00
wireguard: reserved int list
This commit is contained in:
parent
0ac26db5ba
commit
e4726952e8
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user