diff options
Diffstat (limited to 'ios/MullvadRustRuntime')
| -rw-r--r-- | ios/MullvadRustRuntime/MullvadApiContext.swift | 9 | ||||
| -rw-r--r-- | ios/MullvadRustRuntime/include/mullvad_rust_runtime.h | 66 |
2 files changed, 73 insertions, 2 deletions
diff --git a/ios/MullvadRustRuntime/MullvadApiContext.swift b/ios/MullvadRustRuntime/MullvadApiContext.swift index f637590612..2cdcb7b728 100644 --- a/ios/MullvadRustRuntime/MullvadApiContext.swift +++ b/ios/MullvadRustRuntime/MullvadApiContext.swift @@ -15,8 +15,13 @@ public struct MullvadApiContext: Sendable { public let context: SwiftApiContext - public init(host: String, address: AnyIPEndpoint) throws { - context = mullvad_api_init_new(host, address.description) + public init(host: String, address: AnyIPEndpoint, disable_tls: Bool = false) throws { + context = switch disable_tls { + case true: + mullvad_api_init_new_tls_disabled(host, address.description) + case false: + mullvad_api_init_new(host, address.description) + } if context._0 == nil { throw MullvadApiContextError.failedToConstructApiClient diff --git a/ios/MullvadRustRuntime/include/mullvad_rust_runtime.h b/ios/MullvadRustRuntime/include/mullvad_rust_runtime.h index 36774f2d4e..4de4a02b37 100644 --- a/ios/MullvadRustRuntime/include/mullvad_rust_runtime.h +++ b/ios/MullvadRustRuntime/include/mullvad_rust_runtime.h @@ -56,6 +56,12 @@ typedef struct CompletionCookie { void *inner; } CompletionCookie; +typedef struct SwiftServerMock { + const void *server_ptr; + const void *mock_ptr; + uint16_t port; +} SwiftServerMock; + typedef struct ProblemReportMetadata { struct Map *inner; } ProblemReportMetadata; @@ -108,6 +114,23 @@ extern const uint16_t CONFIG_SERVICE_PORT; * * This function is safe. */ +struct SwiftApiContext mullvad_api_init_new_tls_disabled(const uint8_t *host, + const uint8_t *address); + +/** + * # Safety + * + * `host` must be a pointer to a null terminated string representing a hostname for Mullvad API host. + * This hostname will be used for TLS validation but not used for domain name resolution. + * + * `address` must be a pointer to a null terminated string representing a socket address through which + * the Mullvad API can be reached directly. + * + * If a context cannot be constructed this function will panic since the call site would not be able + * to proceed in a meaningful way anyway. + * + * This function is safe. + */ struct SwiftApiContext mullvad_api_init_new(const uint8_t *host, const uint8_t *address); @@ -238,6 +261,49 @@ extern void mullvad_api_completion_finish(struct SwiftMullvadApiResponse respons struct CompletionCookie completion_cookie); /** + * # Safety + * + * `method` must be a pointer to a null terminated string representing the http method. + * + * `path` must be a pointer to a null terminated string representing the url path. + * + * `response_code` must be a usize representing the http response code. + * + * `response_body` must be a pointer to a null terminated string representing the body. + * + * This function is safe. + */ +struct SwiftServerMock mullvad_api_mock_get(const char *path, + uintptr_t response_code, + const uint8_t *response_body); + +/** + * # Safety + * + * `path` must be a pointer to a null terminated string representing the url path. + * + * `response_code` must be a usize representing the http response code. + * + * `match_body` must be a pointer to a null terminated json string representing the body the server expects. + * + * This function is safe. + */ +struct SwiftServerMock mullvad_api_mock_post(const char *path, + uintptr_t response_code, + const char *match_body); + +/** + * Called by the Swift side to signal that the Rust `SwiftServerMock` can be safely + * dropped from memory. + * + * # Safety + * + * `mock_ptr` must be pointing to a valid instance of `SwiftServerMock`. This function + * is not safe to call multiple times with the same `SwiftServerMock`. + */ +void mullvad_api_mock_drop(struct SwiftServerMock mock_ptr); + +/** * Send a problem report via the Mullvad API client. * * # Safety |
