tunnelkit/Sources/TunnelKitOpenVPNCore/XORMethod.swift

78 lines
2.1 KiB
Swift
Raw Normal View History

//
// XORMethod.swift
// TunnelKit
//
// Created by Davide De Rosa on 11/4/22.
2023-03-17 15:58:36 +00:00
// Copyright (c) 2023 Davide De Rosa. All rights reserved.
//
// https://github.com/passepartoutvpn
//
// This file is part of TunnelKit.
//
// TunnelKit is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// TunnelKit is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with TunnelKit. If not, see <http://www.gnu.org/licenses/>.
//
import Foundation
import CTunnelKitOpenVPNCore
extension OpenVPN {
2023-04-20 19:52:45 +00:00
/// The obfuscation method.
public enum XORMethod: Codable, Equatable {
2023-04-20 19:52:45 +00:00
/// XORs the bytes in each buffer with the given mask.
case xormask(mask: Data)
2023-04-20 19:52:45 +00:00
/// XORs each byte with its position in the packet.
case xorptrpos
2023-04-20 19:52:45 +00:00
/// Reverses the order of bytes in each buffer except for the first (abcde becomes aedcb).
case reverse
2023-04-20 19:52:45 +00:00
/// Performs several of the above steps (xormask -> xorptrpos -> reverse -> xorptrpos).
case obfuscate(mask: Data)
/// This method mapped to native enumeration.
public var native: XORMethodNative {
switch self {
case .xormask:
return .mask
2023-04-20 19:52:45 +00:00
case .xorptrpos:
return .ptrPos
2023-04-20 19:52:45 +00:00
case .reverse:
return .reverse
2023-04-20 19:52:45 +00:00
case .obfuscate:
return .obfuscate
}
}
/// The optionally associated mask.
public var mask: Data? {
switch self {
case .xormask(let mask):
return mask
2023-04-20 19:52:45 +00:00
case .obfuscate(let mask):
return mask
2023-04-20 19:52:45 +00:00
default:
return nil
}
}
}
}