Skip to content

Commit e472695

Browse files
committed
wireguard: reserved int list
1 parent 0ac26db commit e472695

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

app/src/main/java/io/nekohasekai/sagernet/fmt/wireguard/WireGuardFmt.kt

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,31 @@
11
package io.nekohasekai.sagernet.fmt.wireguard
22

33
import moe.matsuri.nb4a.SingBoxOptions
4+
import moe.matsuri.nb4a.utils.Util
45
import moe.matsuri.nb4a.utils.listByLineOrComma
56

7+
fun genReserved(anyStr: String): String {
8+
try {
9+
val list = anyStr.listByLineOrComma()
10+
val ba = ByteArray(3)
11+
if (list.size == 3) {
12+
list.forEachIndexed { index, s ->
13+
val i = s
14+
.replace("[", "")
15+
.replace("]", "")
16+
.replace(" ", "")
17+
.toIntOrNull() ?: return anyStr
18+
ba[index] = i.toByte()
19+
}
20+
return Util.b64EncodeOneLine(ba)
21+
} else {
22+
return anyStr
23+
}
24+
} catch (e: Exception) {
25+
return anyStr
26+
}
27+
}
28+
629
fun buildSingBoxOutboundWireguardBean(bean: WireGuardBean): SingBoxOptions.Outbound_WireGuardOptions {
730
return SingBoxOptions.Outbound_WireGuardOptions().apply {
831
type = "wireguard"
@@ -13,6 +36,6 @@ fun buildSingBoxOutboundWireguardBean(bean: WireGuardBean): SingBoxOptions.Outbo
1336
peer_public_key = bean.peerPublicKey
1437
pre_shared_key = bean.peerPreSharedKey
1538
mtu = bean.mtu
16-
if (bean.reserved.isNotBlank()) reserved = bean.reserved
39+
if (bean.reserved.isNotBlank()) reserved = genReserved(bean.reserved)
1740
}
1841
}

0 commit comments

Comments
 (0)