TorBridgeTransports.kt 1.74 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package org.mozilla.fenix.tor

import android.os.Parcelable
import androidx.annotation.StringRes
import kotlinx.android.parcel.Parcelize
import org.mozilla.fenix.R

@Parcelize
enum class TorBridgeTransportConfig(
    @StringRes val preferenceKey: Int,
    val transportName: String
) : Parcelable {

    BUILTIN_OBFS4(
        preferenceKey = R.string.pref_key_tor_network_settings_bridge_config_builtin_bridge_obfs4,
        transportName = "obfs4"
    ),
    BUILTIN_MEEK_AZURE(
        preferenceKey = R.string.pref_key_tor_network_settings_bridge_config_builtin_bridge_meek_azure,
        transportName = "meek"
    ),
    BUILTIN_SNOWFLAKE(
        preferenceKey = R.string.pref_key_tor_network_settings_bridge_config_builtin_bridge_snowflake,
        transportName = "snowflake"
    ),
    USER_PROVIDED(
        preferenceKey = R.string.pref_key_tor_network_settings_bridge_config_user_provided_bridge,
        transportName = "user_provided"
    )
}

object TorBridgeTransportConfigUtil {
    fun getStringToBridgeTransport(bridge: String): TorBridgeTransportConfig {
        return when (bridge) {
            TorBridgeTransportConfig.BUILTIN_OBFS4.transportName ->
                TorBridgeTransportConfig.BUILTIN_OBFS4
            TorBridgeTransportConfig.BUILTIN_MEEK_AZURE.transportName ->
                TorBridgeTransportConfig.BUILTIN_MEEK_AZURE
            TorBridgeTransportConfig.BUILTIN_SNOWFLAKE.transportName ->
                TorBridgeTransportConfig.BUILTIN_SNOWFLAKE
            else -> TorBridgeTransportConfig.USER_PROVIDED
        }
    }
}