Add some missing documentation

This commit is contained in:
Davide De Rosa 2022-09-23 21:45:04 +02:00
parent 000fde0aa2
commit 64b3fa47af
12 changed files with 48 additions and 34 deletions

View File

@ -36,9 +36,13 @@
import Foundation import Foundation
/// Global library settings.
public class CoreConfiguration { public class CoreConfiguration {
/// Unique identifier of the library.
public static let identifier = "com.algoritmico.TunnelKit" public static let identifier = "com.algoritmico.TunnelKit"
/// Library version as seen in `Info.plist`.
public static let version: String = { public static let version: String = {
let bundle = Bundle(for: CoreConfiguration.self) let bundle = Bundle(for: CoreConfiguration.self)
guard let info = bundle.infoDictionary else { guard let info = bundle.infoDictionary else {
@ -54,15 +58,19 @@ public class CoreConfiguration {
return info["CFBundleShortVersionString"] as? String ?? "" return info["CFBundleShortVersionString"] as? String ?? ""
}() }()
// configurable /// Masks private data in logs.
public static var masksPrivateData = true public static var masksPrivateData = true
/// String representing library version.
public static var versionIdentifier: String? public static var versionIdentifier: String?
/// Enables logging of sensitive data (hardcoded to false).
public static let logsSensitiveData = false public static let logsSensitiveData = false
} }
extension CustomStringConvertible { extension CustomStringConvertible {
/// Returns a masked version of `description` in case `CoreConfiguration.masksPrivateData` is `true`.
public var maskedDescription: String { public var maskedDescription: String {
guard CoreConfiguration.masksPrivateData else { guard CoreConfiguration.masksPrivateData else {
return description return description

View File

@ -25,10 +25,13 @@
import Foundation import Foundation
/// :nodoc: /// A pair of received/sent bytes count.
public struct DataCount: Equatable { public struct DataCount: Equatable {
/// Received bytes count.
public let received: UInt public let received: UInt
/// Sent bytes count.
public let sent: UInt public let sent: UInt
public init(_ received: UInt, _ sent: UInt) { public init(_ received: UInt, _ sent: UInt) {

View File

@ -25,7 +25,7 @@
import Foundation import Foundation
/// :nodoc: /// Helps expressing integers in bytes, kB, MB, GB.
public enum DataUnit: UInt, CustomStringConvertible { public enum DataUnit: UInt, CustomStringConvertible {
case byte = 1 case byte = 1
@ -68,8 +68,14 @@ public enum DataUnit: UInt, CustomStringConvertible {
} }
} }
/// :nodoc: /// Supports being represented in data unit.
extension UInt { public protocol DataUnitRepresentable {
/// Returns self expressed in bytes, kB, MB, GB.
var descriptionAsDataUnit: String { get }
}
extension UInt: DataUnitRepresentable {
private static let allUnits: [DataUnit] = [ private static let allUnits: [DataUnit] = [
.gigabyte, .gigabyte,
.megabyte, .megabyte,
@ -94,8 +100,7 @@ extension UInt {
} }
} }
/// :nodoc: extension Int: DataUnitRepresentable {
extension Int {
public var descriptionAsDataUnit: String { public var descriptionAsDataUnit: String {
return UInt(self).descriptionAsDataUnit return UInt(self).descriptionAsDataUnit
} }

View File

@ -31,7 +31,6 @@ public struct Endpoint: RawRepresentable, Codable, Equatable, CustomStringConver
public let proto: EndpointProtocol public let proto: EndpointProtocol
/// :nodoc:
public init(_ address: String, _ proto: EndpointProtocol) { public init(_ address: String, _ proto: EndpointProtocol) {
self.address = address self.address = address
self.proto = proto self.proto = proto
@ -74,7 +73,6 @@ public struct EndpointProtocol: RawRepresentable, Equatable, CustomStringConvert
/// The remote port. /// The remote port.
public let port: UInt16 public let port: UInt16
/// :nodoc:
public init(_ socketType: SocketType, _ port: UInt16) { public init(_ socketType: SocketType, _ port: UInt16) {
self.socketType = socketType self.socketType = socketType
self.port = port self.port = port

View File

@ -39,11 +39,16 @@ import Security.SecRandom
import CTunnelKitCore import CTunnelKitCore
import __TunnelKitUtils import __TunnelKitUtils
/// Errors returned by `SecureRandom`.
public enum SecureRandomError: Error { public enum SecureRandomError: Error {
/// RNG could not be initialized.
case randomGenerator case randomGenerator
} }
/// Generates random data in a secure fashion.
public class SecureRandom { public class SecureRandom {
@available(*, deprecated) @available(*, deprecated)
static func uint32FromBuffer() throws -> UInt32 { static func uint32FromBuffer() throws -> UInt32 {
var randomBuffer = [UInt8](repeating: 0, count: 4) var randomBuffer = [UInt8](repeating: 0, count: 4)

View File

@ -328,7 +328,6 @@ public class Keychain {
// MARK: Helpers // MARK: Helpers
/// :nodoc:
public func setScope(query: inout [String: Any], context: String, userDefined: String?) { public func setScope(query: inout [String: Any], context: String, userDefined: String?) {
if let accessGroup = accessGroup { if let accessGroup = accessGroup {
query[kSecAttrAccessGroup as String] = accessGroup query[kSecAttrAccessGroup as String] = accessGroup

View File

@ -26,12 +26,16 @@
import Foundation import Foundation
import NetworkExtension import NetworkExtension
/// :nodoc: /// Extra configuration parameters to attach optionally to a `NetworkExtensionConfiguration`.
public struct NetworkExtensionExtra { public struct NetworkExtensionExtra {
/// A password reference to the keychain.
public var passwordReference: Data? public var passwordReference: Data?
/// A set of on-demand rules.
public var onDemandRules: [NEOnDemandRule] = [] public var onDemandRules: [NEOnDemandRule] = []
/// Disconnects on sleep if `true`.
public var disconnectsOnSleep = false public var disconnectsOnSleep = false
public init() { public init() {

View File

@ -85,6 +85,8 @@ public protocol VPN {
} }
extension DispatchTimeInterval { extension DispatchTimeInterval {
/// Returns self in nanoseconds.
public var nanoseconds: UInt64 { public var nanoseconds: UInt64 {
switch self { switch self {
case .seconds(let sec): case .seconds(let sec):

View File

@ -51,7 +51,6 @@ extension OpenVPN {
/// The password. /// The password.
public let password: String public let password: String
/// :nodoc
public init(_ username: String, _ password: String) { public init(_ username: String, _ password: String) {
self.username = username self.username = username
self.password = password self.password = password
@ -355,16 +354,14 @@ extension OpenVPN {
/// The immutable configuration for `OpenVPNSession`. /// The immutable configuration for `OpenVPNSession`.
public struct Configuration: Codable, Equatable { public struct Configuration: Codable, Equatable {
struct Fallback {
static let cipher: Cipher = .aes128cbc
/// :nodoc: static let digest: Digest = .sha1
public struct Fallback {
public static let cipher: Cipher = .aes128cbc
public static let digest: Digest = .sha1 static let compressionFraming: CompressionFraming = .disabled
public static let compressionFraming: CompressionFraming = .disabled static let compressionAlgorithm: CompressionAlgorithm = .disabled
public static let compressionAlgorithm: CompressionAlgorithm = .disabled
} }
/// - Seealso: `ConfigurationBuilder.cipher` /// - Seealso: `ConfigurationBuilder.cipher`

View File

@ -38,6 +38,7 @@ extension OpenVPN {
// XXX: parsing is very optimistic // XXX: parsing is very optimistic
/// Regexes used to parse OpenVPN options.
public struct Regex { public struct Regex {
// MARK: General // MARK: General

View File

@ -74,14 +74,12 @@ extension OpenVPN {
/// Mask private data in debug log (default is `true`). /// Mask private data in debug log (default is `true`).
public var masksPrivateData = true public var masksPrivateData = true
/// :nodoc:
public init(_ title: String, appGroup: String, configuration: OpenVPN.Configuration) { public init(_ title: String, appGroup: String, configuration: OpenVPN.Configuration) {
self.title = title self.title = title
self.appGroup = appGroup self.appGroup = appGroup
self.configuration = configuration self.configuration = configuration
} }
/// :nodoc:
public func print() { public func print() {
if let versionIdentifier = versionIdentifier { if let versionIdentifier = versionIdentifier {
log.info("Tunnel version: \(versionIdentifier)") log.info("Tunnel version: \(versionIdentifier)")
@ -97,7 +95,6 @@ extension OpenVPN {
extension OpenVPN.ProviderConfiguration: NetworkExtensionConfiguration { extension OpenVPN.ProviderConfiguration: NetworkExtensionConfiguration {
/// :nodoc:
public func asTunnelProtocol( public func asTunnelProtocol(
withBundleIdentifier tunnelBundleIdentifier: String, withBundleIdentifier tunnelBundleIdentifier: String,
extra: NetworkExtensionExtra? extra: NetworkExtensionExtra?
@ -156,7 +153,6 @@ extension OpenVPN.ProviderConfiguration {
} }
} }
/// :nodoc:
extension OpenVPN.ProviderConfiguration { extension OpenVPN.ProviderConfiguration {
public func _appexSetDataCount(_ newValue: DataCount?) { public func _appexSetDataCount(_ newValue: DataCount?) {
defaults?.openVPNDataCount = newValue defaults?.openVPNDataCount = newValue
@ -183,7 +179,6 @@ extension OpenVPN.ProviderConfiguration {
} }
} }
/// :nodoc:
extension UserDefaults { extension UserDefaults {
public func openVPNURLForDebugLog(appGroup: String) -> URL? { public func openVPNURLForDebugLog(appGroup: String) -> URL? {
guard let path = string(forKey: OpenVPN.ProviderConfiguration.Keys.logPath.rawValue) else { guard let path = string(forKey: OpenVPN.ProviderConfiguration.Keys.logPath.rawValue) else {

View File

@ -73,7 +73,6 @@ extension WireGuard {
extension WireGuard.ProviderConfiguration: NetworkExtensionConfiguration { extension WireGuard.ProviderConfiguration: NetworkExtensionConfiguration {
/// :nodoc:
public func asTunnelProtocol( public func asTunnelProtocol(
withBundleIdentifier tunnelBundleIdentifier: String, withBundleIdentifier tunnelBundleIdentifier: String,
extra: NetworkExtensionExtra? extra: NetworkExtensionExtra?
@ -105,7 +104,6 @@ extension WireGuard.ProviderConfiguration {
} }
} }
/// :nodoc:
extension WireGuard.ProviderConfiguration { extension WireGuard.ProviderConfiguration {
public func _appexSetLastError(_ newValue: WireGuardProviderError?) { public func _appexSetLastError(_ newValue: WireGuardProviderError?) {
defaults?.wireGuardLastError = newValue defaults?.wireGuardLastError = newValue
@ -124,7 +122,6 @@ extension WireGuard.ProviderConfiguration {
} }
} }
/// :nodoc:
extension UserDefaults { extension UserDefaults {
public func wireGuardURLForDebugLog(appGroup: String) -> URL? { public func wireGuardURLForDebugLog(appGroup: String) -> URL? {
guard let path = string(forKey: WireGuard.ProviderConfiguration.Keys.logPath.rawValue) else { guard let path = string(forKey: WireGuard.ProviderConfiguration.Keys.logPath.rawValue) else {