File tree Expand file tree Collapse file tree
app/src/main/java/io/nekohasekai/sagernet/fmt/wireguard Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package io.nekohasekai.sagernet.fmt.wireguard
22
33import moe.matsuri.nb4a.SingBoxOptions
4+ import moe.matsuri.nb4a.utils.Util
45import 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+
629fun 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}
You can’t perform that action at this time.
0 commit comments