Skip to content

Commit

Permalink
making enum for shadow-socks ciphers
Browse files Browse the repository at this point in the history
  • Loading branch information
mojganii committed Dec 13, 2023
1 parent d19ff06 commit 8c5fa53
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 66 deletions.
9 changes: 4 additions & 5 deletions ios/MullvadVPN.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@
5846227726E22A7C0035F7C2 /* StorePaymentManagerDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5846227626E22A7C0035F7C2 /* StorePaymentManagerDelegate.swift */; };
584D26C4270C855B004EA533 /* PreferencesDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 584D26C3270C855A004EA533 /* PreferencesDataSource.swift */; };
584D26C6270C8741004EA533 /* SettingsDNSTextCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 584D26C5270C8741004EA533 /* SettingsDNSTextCell.swift */; };
584EBDBD2747C98F00A0C9FD /* NSAttributedString+Markdown.swift in Sources */ = {isa = PBXBuildFile; fileRef = 584EBDBC2747C98F00A0C9FD /* NSAttributedString+Markdown.swift */; };
5859A55529CD9DD900F66591 /* changes.txt in Resources */ = {isa = PBXBuildFile; fileRef = 5859A55429CD9DD800F66591 /* changes.txt */; };
585A02E92A4B283000C6CAFF /* TCPUnsafeListener.swift in Sources */ = {isa = PBXBuildFile; fileRef = 585A02E82A4B283000C6CAFF /* TCPUnsafeListener.swift */; };
585A02EB2A4B285800C6CAFF /* UDPConnection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 585A02EA2A4B285800C6CAFF /* UDPConnection.swift */; };
Expand Down Expand Up @@ -403,7 +402,7 @@
58DFF7D22B0256A300F864E0 /* MarkdownStylingOptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58DFF7D12B0256A300F864E0 /* MarkdownStylingOptions.swift */; };
58DFF7D32B02570000F864E0 /* MarkdownStylingOptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58DFF7D12B0256A300F864E0 /* MarkdownStylingOptions.swift */; };
58DFF7D82B02774C00F864E0 /* ListItemPickerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58DFF7D72B02774C00F864E0 /* ListItemPickerViewController.swift */; };
58DFF7DA2B02862E00F864E0 /* ShadowsocksCipher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58DFF7D92B02862E00F864E0 /* ShadowsocksCipher.swift */; };
58DFF7DA2B02862E00F864E0 /* ShadowsocksCipherOptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58DFF7D92B02862E00F864E0 /* ShadowsocksCipherOptions.swift */; };
58E0729F28814ACC008902F8 /* WireGuardLogLevel+Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58E0729E28814ACC008902F8 /* WireGuardLogLevel+Logging.swift */; };
58E0A98827C8F46300FE6BDD /* Tunnel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58E0A98727C8F46300FE6BDD /* Tunnel.swift */; };
58E11188292FA11F009FCA84 /* SettingsMigrationUIHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58E11187292FA11F009FCA84 /* SettingsMigrationUIHandler.swift */; };
Expand Down Expand Up @@ -1546,7 +1545,7 @@
58DFF7CF2B02560400F864E0 /* NSAttributedString+Markdown.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSAttributedString+Markdown.swift"; sourceTree = "<group>"; };
58DFF7D12B0256A300F864E0 /* MarkdownStylingOptions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MarkdownStylingOptions.swift; sourceTree = "<group>"; };
58DFF7D72B02774C00F864E0 /* ListItemPickerViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListItemPickerViewController.swift; sourceTree = "<group>"; };
58DFF7D92B02862E00F864E0 /* ShadowsocksCipher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShadowsocksCipher.swift; sourceTree = "<group>"; };
58DFF7D92B02862E00F864E0 /* ShadowsocksCipherOptions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShadowsocksCipherOptions.swift; sourceTree = "<group>"; };
58E07298288031D5008902F8 /* WireGuardAdapterError+Localization.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "WireGuardAdapterError+Localization.swift"; sourceTree = "<group>"; };
58E0729E28814ACC008902F8 /* WireGuardLogLevel+Logging.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "WireGuardLogLevel+Logging.swift"; sourceTree = "<group>"; };
58E0A98727C8F46300FE6BDD /* Tunnel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Tunnel.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2138,7 +2137,7 @@
586C0D962B04E0AC00E7CDD7 /* PersistentAccessMethod.swift */,
58EF87562B16330B00C098B2 /* ProxyConfigurationTester.swift */,
58EF875C2B1638BF00C098B2 /* ProxyConfigurationTesterProtocol.swift */,
58DFF7D92B02862E00F864E0 /* ShadowsocksCipher.swift */,
58DFF7D92B02862E00F864E0 /* ShadowsocksCipherOptions.swift */,
);
path = AccessMethodRepository;
sourceTree = "<group>";
Expand Down Expand Up @@ -4809,7 +4808,7 @@
5878A27329091D6D0096FC88 /* TunnelBlockObserver.swift in Sources */,
A9E034642ABB302000E59A5A /* UIEdgeInsets+Extensions.swift in Sources */,
58CEB2E92AFBBA4A00E6E088 /* AddAccessMethodCoordinator.swift in Sources */,
58DFF7DA2B02862E00F864E0 /* ShadowsocksCipher.swift in Sources */,
58DFF7DA2B02862E00F864E0 /* ShadowsocksCipherOptions.swift in Sources */,
58DFF7D02B02560400F864E0 /* NSAttributedString+Markdown.swift in Sources */,
58E0A98827C8F46300FE6BDD /* Tunnel.swift in Sources */,
7A12D0762B062D5C00E9602D /* URLSessionProtocol.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class AccessMethodRepository: AccessMethodRepositoryProtocol {
func delete(id: UUID) {
guard let index = memoryStore.firstIndex(where: { $0.id == id }) else { return }

// Prevent removing methods that have static UUIDs and always present.
// Prevent removing methods that have static UUIDs and are always present.
let permanentMethod = memoryStore[index]
if !permanentMethod.kind.isPermanent {
memoryStore.remove(at: index)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ protocol AccessMethodRepositoryProtocol {
/// - Parameter method: persistent access method model.
func add(_ method: PersistentAccessMethod)

/// Persist modified access method locating existing entry by id.
/// Update access method locating existing entry by id.
/// - Parameter method: persistent access method model.
func update(_ method: PersistentAccessMethod)

Expand All @@ -30,7 +30,7 @@ protocol AccessMethodRepositoryProtocol {
/// - Returns: a persistent access method model upon success, otherwise `nil`.
func fetch(by id: UUID) -> PersistentAccessMethod?

/// Fetch all access method from the persistent store.
/// Fetch all access methods from the persistent store.
/// - Returns: an array of all persistent access method.
func fetchAll() -> [PersistentAccessMethod]
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ extension PersistentProxyConfiguration {
var password: String

/// Server cipher.
var cipher: ShadowsocksCipher
var cipher: ShadowsocksCipherOptions
}
}

Expand Down
48 changes: 0 additions & 48 deletions ios/MullvadVPN/AccessMethodRepository/ShadowsocksCipher.swift

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//
// ShadowsocksCipherOptions.swift
// MullvadVPN
//
// Created by pronebird on 13/11/2023.
// Copyright © 2023 Mullvad VPN AB. All rights reserved.
//

import Foundation

/// Type representing a shadowsocks cipher.
struct ShadowsocksCipherOptions: RawRepresentable, Codable, Hashable {
let rawValue: CipherIdentifiers

/// Default cipher.
static let `default` = ShadowsocksCipherOptions(rawValue: .CHACHA20)

/// All supported ciphers.
static let all = CipherIdentifiers.allCases.map { ShadowsocksCipherOptions(rawValue: $0) }
}

enum CipherIdentifiers: String, CaseIterable, CustomStringConvertible, Codable {
// Stream ciphers.
case CFB_AES128 = "aes-128-cfb"
case CFB1_AES128 = "aes-128-cfb1"
case CFB8_AES128 = "aes-128-cfb8"
case CFB128_AES128 = "aes-128-cfb128"
case CFB_AES256 = "aes-256-cfb"
case CFB1_AES256 = "aes-256-cfb1"
case CFB8_AES256 = "aes-256-cfb8"
case CFB128_AES256 = "aes-256-cfb128"
case RC4 = "rc4"
case RC4_MD5 = "rc4-md5"
case CHACHA20 = "chacha20"
case SALSA20 = "salsa20"
case CHACHA20_IETF = "chacha20-ietf"

// AEAD ciphers.
case GCM_AES128 = "aes-128-gcm"
case GCM_AES256 = "aes-256-gcm"
case CHACHA20_IETF_POLY1305 = "chacha20-ietf-poly1305"
case XCHACHA20_IETF_POLY1305 = "xchacha20-ietf-poly1305"
case PMAC_SIV_AES128 = "aes-128-pmac-siv"
case GPMAC_SIV_AES256 = "aes-256-pmac-siv"

var description: String {
rawValue
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class ListAccessMethodViewController: UIViewController, UITableViewDelegate {
addChild(contentController)
contentController.didMove(toParent: self)

interactor.publisher.sink { newElements in
interactor.publisher.sink { _ in
self.updateDataSource(animated: true)
}
.store(in: &cancellables)
Expand Down Expand Up @@ -104,7 +104,7 @@ class ListAccessMethodViewController: UIViewController, UITableViewDelegate {
private func configureDataSource() {
dataSource = UITableViewDiffableDataSource(
tableView: tableView,
cellProvider: { [weak self] tableView, indexPath, itemIdentifier in
cellProvider: { [weak self] _, indexPath, itemIdentifier in
self?.dequeueCell(at: indexPath, itemIdentifier: itemIdentifier)
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct AccessMethodViewModel: Identifiable {
/// Server password.
var password = ""
/// Shadowsocks cipher.
var cipher = ShadowsocksCipher.default
var cipher = ShadowsocksCipherOptions.default
}

/// Access method testing status view model.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct ShadowsocksCipherPicker {
/// - Parameters:
/// - currentValue: current selection.
/// - completion: a completion handler.
func present(currentValue: ShadowsocksCipher, completion: @escaping (ShadowsocksCipher) -> Void) {
func present(currentValue: ShadowsocksCipherOptions, completion: @escaping (ShadowsocksCipherOptions) -> Void) {
let navigationController = navigationController

let dataSource = ShadowsocksCipherPickerDataSource()
Expand All @@ -42,13 +42,13 @@ struct ShadowsocksCipherPicker {
/// Type implementing the data source for the shadowsocks cipher picker.
struct ShadowsocksCipherPickerDataSource: ListItemDataSourceProtocol {
struct Item: ListItemDataSourceItem {
let cipher: ShadowsocksCipher
let cipher: ShadowsocksCipherOptions

var id: ShadowsocksCipher { cipher }
var id: ShadowsocksCipherOptions { cipher }
var text: String { "\(cipher)" }
}

let items = ShadowsocksCipher.supportedCiphers.map { Item(cipher: $0) }
let items = ShadowsocksCipherOptions.all.map { Item(cipher: $0) }

var itemCount: Int {
items.count
Expand All @@ -58,7 +58,7 @@ struct ShadowsocksCipherPickerDataSource: ListItemDataSourceProtocol {
items[indexPath.row]
}

func indexPath(for itemID: ShadowsocksCipher) -> IndexPath? {
func indexPath(for itemID: ShadowsocksCipherOptions) -> IndexPath? {
guard let index = items.firstIndex(where: { $0.id == itemID }) else { return nil }

return IndexPath(row: index, section: 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ final class SettingsCoordinator: Coordinator, Presentable, Presenting, SettingsV
self.interactorFactory = interactorFactory
}

/// Start the coordinator fllow.
/// Start the coordinator flow.
/// - Parameter initialRoute: the initial route to display.
func start(initialRoute: SettingsNavigationRoute? = nil) {
navigationController.navigationBar.prefersLargeTitles = true
Expand Down

0 comments on commit 8c5fa53

Please sign in to comment.