diff options
| author | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2022-09-20 15:07:40 +0200 |
|---|---|---|
| committer | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2022-09-20 15:07:40 +0200 |
| commit | 2a619ceba75a4c16b25de12d59a87eac795a4468 (patch) | |
| tree | 1d63a35217011fa761b703633b3f91fd839ec71e /wrappers/swift | |
| parent | 7e309b67de74fe5bd5a1c70c1880c2a381c4f78b (diff) | |
Remove: unused wrappers
Diffstat (limited to 'wrappers/swift')
| -rw-r--r-- | wrappers/swift/.gitignore | 8 | ||||
| -rw-r--r-- | wrappers/swift/CEduVpnCommon/Package.swift | 13 | ||||
| -rw-r--r-- | wrappers/swift/CEduVpnCommon/Sources/CEduVpnCommon/module.modulemap | 5 | ||||
| -rw-r--r-- | wrappers/swift/Makefile | 23 | ||||
| -rw-r--r-- | wrappers/swift/Package.swift | 23 | ||||
| -rw-r--r-- | wrappers/swift/README.md | 47 | ||||
| -rw-r--r-- | wrappers/swift/Sources/EduVpnCommon/EduVpnCommon.swift | 77 | ||||
| -rw-r--r-- | wrappers/swift/Tests/EduVpnCommonTests/EduVpnCommonTests.swift | 60 | ||||
| -rwxr-xr-x | wrappers/swift/swift.cmd | 9 |
9 files changed, 0 insertions, 265 deletions
diff --git a/wrappers/swift/.gitignore b/wrappers/swift/.gitignore deleted file mode 100644 index 32d8b26..0000000 --- a/wrappers/swift/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -.DS_Store -.build/ -Packages/ -*.xcodeproj -xcuserdata/ -DerivedData/ -*.xcworkspacedata -*.h diff --git a/wrappers/swift/CEduVpnCommon/Package.swift b/wrappers/swift/CEduVpnCommon/Package.swift deleted file mode 100644 index 884f042..0000000 --- a/wrappers/swift/CEduVpnCommon/Package.swift +++ /dev/null @@ -1,13 +0,0 @@ -// swift-tools-version:5.1 - -import PackageDescription - -let package = Package( - name: "CEduVpnCommon", - products: [ - .library(name: "CEduVpnCommon", targets: ["CEduVpnCommon"]), - ], - targets: [ - .systemLibrary(name: "CEduVpnCommon"), - ] -) diff --git a/wrappers/swift/CEduVpnCommon/Sources/CEduVpnCommon/module.modulemap b/wrappers/swift/CEduVpnCommon/Sources/CEduVpnCommon/module.modulemap deleted file mode 100644 index 2c50cfd..0000000 --- a/wrappers/swift/CEduVpnCommon/Sources/CEduVpnCommon/module.modulemap +++ /dev/null @@ -1,5 +0,0 @@ -module CEduVpnCommon { - header "Headers/eduvpn_common.h" - link "eduvpn_common" - export * -} diff --git a/wrappers/swift/Makefile b/wrappers/swift/Makefile deleted file mode 100644 index 659b51f..0000000 --- a/wrappers/swift/Makefile +++ /dev/null @@ -1,23 +0,0 @@ -.PHONY: build test install-header clean - -EXPORTS_PATH ?= ../../exports -include $(EXPORTS_PATH)/common.mk - -ifeq ($(OS),Windows_NT) -SWIFT = ./swift.cmd -else -SWIFT = swift -endif - -build: install-header - $(SWIFT) build --configuration release -Xlinker -L"$(EXPORTS_LIB_SUBFOLDER_PATH)" - -test: install-header - $(SWIFT) test --parallel -Xlinker -L"$(EXPORTS_LIB_SUBFOLDER_PATH)" - -install-header: .try-build-lib - mkdir -p CEduVpnCommon/Sources/CEduVpnCommon/Headers - cp "$(EXPORTS_LIB_SUBFOLDER_PATH)/$(LIB_NAME).h" CEduVpnCommon/Sources/CEduVpnCommon/Headers/ # Copy header for modulemap - -clean: - rm -rf .build/ CEduVpnCommon/Sources/CEduVpnCommon/Headers/*.h diff --git a/wrappers/swift/Package.swift b/wrappers/swift/Package.swift deleted file mode 100644 index 5b675ac..0000000 --- a/wrappers/swift/Package.swift +++ /dev/null @@ -1,23 +0,0 @@ -// swift-tools-version:5.0 - -import PackageDescription - -let package = Package( - name: "EduVpnCommon", - products: [ - .library( - name: "EduVpnCommon", - targets: ["EduVpnCommon"]), - ], - dependencies: [ - .package(path: "CEduVpnCommon"), - ], - targets: [ - .target( - name: "EduVpnCommon", - dependencies: ["CEduVpnCommon"]), - .testTarget( - name: "EduVpnCommonTests", - dependencies: ["EduVpnCommon"]), - ] -) diff --git a/wrappers/swift/README.md b/wrappers/swift/README.md deleted file mode 100644 index 30642c4..0000000 --- a/wrappers/swift/README.md +++ /dev/null @@ -1,47 +0,0 @@ -# Swift wrapper - -## Requirements - -You will need to install the [Swift SDK](https://www.swift.org/getting-started), which includes the `swift` tool. This -project does not require Xcode as it uses the Swift Package Manager. - -## Build & test - -Build `EduVpnCommon` using shared Go library for current platform: - -```shell -make -``` - -Build `EduVpnCommon` using shared Go library for specified platform, e.g.: - -```shell -make GOOS=linux GOARCH=amd64 -``` - -When using this library, you will need to make sure that the dynamic linker can find the shared Go library. - -Currently, `.dylib`s for multiple architectures generated by cgo are not merged into one. For a pointer on how to do -this, see [this](https://stackoverflow.com/q/22783453). - -<details><summary>Windows</summary><small> -On Windows, you will also need to generate a .lib import library for the .dll. You can -use `exports/generate_lib.ps1` -for this, passing in the path to the DLL file. Execute this from a Visual Studio Developer shell before building the -Swift project. Alternatively, you could use `objdump` and `llvm-dlltool`. You only need to update this if the list of -exported symbols changes.</small></details> - -If you just want to copy over the C header file to the right directory for the modulemap in `CEduVpnCommon`, run: - -```shell -make install-header -``` - -If you do not build this as part of the full repository, specify `EXPORTS_PATH="path/to/exports-folder"` when calling -make. This folder must contain `common.mk` and the `lib/` folder with built libraries and headers. - -Test: - -```shell -make test -``` diff --git a/wrappers/swift/Sources/EduVpnCommon/EduVpnCommon.swift b/wrappers/swift/Sources/EduVpnCommon/EduVpnCommon.swift deleted file mode 100644 index b849626..0000000 --- a/wrappers/swift/Sources/EduVpnCommon/EduVpnCommon.swift +++ /dev/null @@ -1,77 +0,0 @@ -import Foundation -import CEduVpnCommon - -private extension Data { - /// Execute `body` with `GoSlice` pointing to `self` - /// - Important: `GoSlice` pointer must not be written to - func withSlice<ResultType>(_ body: (GoSlice) throws -> ResultType) rethrows -> ResultType { - // Could also use raw NSData.bytes, but then you have to be careful that the NSData must remain valid during the call - // This closure method guarantees this - try withUnsafeBytes { (pointer: UnsafeRawBufferPointer) -> ResultType in - // Note: UnsafeRawBufferPointer.startIndex will always be 0, see docs - // Cast to UnsafeMutableRawPointer, assumes it will not actually be written to - try body(GoSlice(data: UnsafeMutableRawPointer(mutating: pointer.baseAddress), - len: GoInt(pointer.count), cap: GoInt(pointer.count))) - } - } -} - -private extension String { - /// Execute `body` with `GoSlice` pointing to UTF-8 bytes copied from `self` - func withSlice<ResultType>(_ body: (GoSlice) throws -> ResultType) rethrows -> ResultType { - try data(using: .utf8)!.withSlice(body) - } -} - -public enum VerifyErr: Error, Equatable { - /// Expected file name is not one of the recognized values. - case ErrUnknownExpectedFileName - /// Signature is invalid (for the expected file type). - case ErrInvalidSignature - /// Signature was created with an unknown key and has not been verified. - case ErrInvalidSignatureUnknownKey - /// Signature has a timestamp lower than the specified minimum signing time. - case ErrTooOld - /// Other unknown error - case Unknown(code: GoInt8) - - static func fromCode(_ code: GoInt8) -> VerifyErr { - precondition(code != 0) - switch code { - case 1: return ErrUnknownExpectedFileName - case 2: return ErrInvalidSignature - case 3: return ErrInvalidSignatureUnknownKey - case 4: return ErrTooOld - default: return Unknown(code: code) - } - } -} - -/// Verifies the signature on the JSON server_list.json/organization_list.json file. -/// If the function returns, the signature is valid for the given file type. -/// -/// - Parameters: -/// - signature: .minisig signature file contents. -/// - signedJson: Signed .json file contents. -/// - expectedFileName: The file type to be verified, one of "server_list.json" or "organization_list.json". -/// - minSignTime: Minimum time for signature. Should be set to at least the time of the previous signature. -/// - Throws: VerifyErr: If signature verification fails or `expectedFileName` is not one of the allowed values. -public func Verify(signature: Data, signedJson: Data, expectedFileName: String, minSignTime: Date) throws { - let result = signature.withSlice { signatureData in - signedJson.withSlice { jsonData in - expectedFileName.withSlice { expectedNameData in - CEduVpnCommon.Verify(signatureData, jsonData, expectedNameData, GoUint64(minSignTime.timeIntervalSince1970)) - } - } - } - if result != 0 { - throw VerifyErr.fromCode(result) - } -} - -/// Use for testing only, see Go documentation. -internal func InsecureTestingSetExtraKey(keyString: String) { - keyString.withSlice { keyData in - CEduVpnCommon.InsecureTestingSetExtraKey(keyData); - } -} diff --git a/wrappers/swift/Tests/EduVpnCommonTests/EduVpnCommonTests.swift b/wrappers/swift/Tests/EduVpnCommonTests/EduVpnCommonTests.swift deleted file mode 100644 index bd2eabd..0000000 --- a/wrappers/swift/Tests/EduVpnCommonTests/EduVpnCommonTests.swift +++ /dev/null @@ -1,60 +0,0 @@ -import XCTest -@testable import EduVpnCommon - -final class EduVpnCommonTests: XCTestCase { - private static let testDataDir = "../../src/test_data" - - override class func setUp() { - // Swift is confused by CRLF, so on some systems we cannot just take the second-to-last element - InsecureTestingSetExtraKey(keyString: try! String(contentsOfFile: "\(testDataDir)/public.key") - .components(separatedBy: .newlines).last(where: { !$0.isEmpty })!) - } - - func testValid() throws { - try Verify( - signature: try! Data(contentsOf: URL(fileURLWithPath: "\(EduVpnCommonTests.testDataDir)/server_list.json.minisig")), - signedJson: try! Data(contentsOf: URL(fileURLWithPath: "\(EduVpnCommonTests.testDataDir)/server_list.json")), - expectedFileName: "server_list.json", - minSignTime: Date(timeIntervalSince1970: 10)) - } - - func testInvalidSignature() throws { - XCTAssertThrowsError( - try Verify( - signature: try! Data(contentsOf: URL(fileURLWithPath: "\(EduVpnCommonTests.testDataDir)/random.txt")), - signedJson: try! Data(contentsOf: URL(fileURLWithPath: "\(EduVpnCommonTests.testDataDir)/server_list.json")), - expectedFileName: "server_list.json", - minSignTime: Date(timeIntervalSince1970: 0)), - "", {err in XCTAssertEqual(err as? VerifyErr, VerifyErr.ErrInvalidSignature)}); - } - - func testWrongKey() throws { - XCTAssertThrowsError( - try Verify( - signature: try! Data(contentsOf: URL(fileURLWithPath: "\(EduVpnCommonTests.testDataDir)/server_list.json.wrong_key.minisig")), - signedJson: try! Data(contentsOf: URL(fileURLWithPath: "\(EduVpnCommonTests.testDataDir)/server_list.json")), - expectedFileName: "server_list.json", - minSignTime: Date(timeIntervalSince1970: 0)), - "", {err in XCTAssertEqual(err as? VerifyErr, VerifyErr.ErrInvalidSignatureUnknownKey)}); - } - - func testOldSignature() throws { - XCTAssertThrowsError( - try Verify( - signature: try! Data(contentsOf: URL(fileURLWithPath: "\(EduVpnCommonTests.testDataDir)/server_list.json.minisig")), - signedJson: try! Data(contentsOf: URL(fileURLWithPath: "\(EduVpnCommonTests.testDataDir)/server_list.json")), - expectedFileName: "server_list.json", - minSignTime: Date(timeIntervalSince1970: 11)), - "", {err in XCTAssertEqual(err as? VerifyErr, VerifyErr.ErrTooOld)}); - } - - func testUnknownExpectedFile() throws { - XCTAssertThrowsError( - try Verify( - signature: try! Data(contentsOf: URL(fileURLWithPath: "\(EduVpnCommonTests.testDataDir)/other_list.json.minisig")), - signedJson: try! Data(contentsOf: URL(fileURLWithPath: "\(EduVpnCommonTests.testDataDir)/other_list.json")), - expectedFileName: "other_list.json", - minSignTime: Date(timeIntervalSince1970: 0)), - "", {err in XCTAssertEqual(err as? VerifyErr, VerifyErr.ErrUnknownExpectedFileName)}); - } -} diff --git a/wrappers/swift/swift.cmd b/wrappers/swift/swift.cmd deleted file mode 100755 index 57040bd..0000000 --- a/wrappers/swift/swift.cmd +++ /dev/null @@ -1,9 +0,0 @@ -@echo off - -:: Rename PATH -> Path because of swift issue https://github.com/compnerd/swift-build/issues/413 -set _p=%PATH% -set PATH= -set Path=%_p% -set _p= - -swift.exe %* |
