Initial commit
Seto Elkahfi committed
May 16, 2026 at 15:39 UTC
2bf0d6ad0058a99811539f38d75339100f8b07a8
6 files changed
+2554
.gitignore
new
+3
@@ -0,0 +1,3 @@
1
+SmbCloudAuthFramework.xcframework/
2
+.local/
3
+.build/
LICENSE
new
+190
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship made available under
36
+ the License, as indicated by a copyright notice that is included in
37
+ or attached to the work (an example is provided in the Appendix below).
38
+
39
+ "Derivative Works" shall mean any work, whether in Source or Object
40
+ form, that is based on (or derived from) the Work and for which the
41
+ editorial revisions, annotations, elaborations, or other modifications
42
+ represent, as a whole, an original work of authorship. For the purposes
43
+ of this License, Derivative Works shall not include works that remain
44
+ separable from, or merely link (or bind by name) to the interfaces of,
45
+ the Work and Derivative Works thereof.
46
+
47
+ "Contribution" shall mean, as defined by the copyright owner or by the
48
+ Legal Entity authorized to submit on behalf of the copyright owner, any
49
+ work of authorship, including the original version of the Work and any
50
+ modifications or additions to that Work or Derivative Works of the Work.
51
+
52
+ "Contributor" shall mean Licensor and any Legal Entity on behalf of
53
+ whom a Contribution has been received by the Licensor and subsequently
54
+ incorporated within the Work.
55
+
56
+ 2. Grant of Copyright License. Subject to the terms and conditions of
57
+ this License, each Contributor hereby grants to You a perpetual,
58
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
59
+ copyright license to reproduce, prepare Derivative Works of,
60
+ publicly display, publicly perform, sublicense, and distribute the
61
+ Work and such Derivative Works in Source or Object form.
62
+
63
+ 3. Grant of Patent License. Subject to the terms and conditions of
64
+ this License, each Contributor hereby grants to You a perpetual,
65
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
66
+ (except as stated in this section) patent license to make, have made,
67
+ use, offer to sell, sell, import, and otherwise transfer the Work,
68
+ where such license applies only to those patent claims licensable
69
+ by such Contributor that are necessarily infringed by their
70
+ Contribution(s) alone or by combination of their Contribution(s)
71
+ with the Work to which such Contribution(s) was submitted. If You
72
+ institute patent litigation against any entity (including a
73
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
74
+ or a Contribution incorporated within the Work constitutes direct
75
+ or contributory patent infringement, then any and all patent licenses
76
+ granted to You under this License for that Work shall terminate
77
+ as of the date such litigation is filed.
78
+
79
+ 4. Redistribution. You may reproduce and distribute copies of the
80
+ Work or Derivative Works thereof in any medium, with or without
81
+ modifications, and in Source or Object form, provided that You
82
+ meet the following conditions:
83
+
84
+ (a) You must give any other recipients of the Work or
85
+ Derivative Works a copy of this License; and
86
+
87
+ (b) You must cause any modified files to carry prominent notices
88
+ stating that You changed the files; and
89
+
90
+ (c) You must retain, in the Source form of any Derivative Works
91
+ that You distribute, all copyright, patent, trademark, and
92
+ attribution notices from the Source form of the Work,
93
+ excluding those notices that do not pertain to any part of
94
+ the Derivative Works; and
95
+
96
+ (d) If the Work includes a "NOTICE" text file as part of its
97
+ distribution, You must include a readable copy of the
98
+ attribution notices contained within such NOTICE file, in
99
+ at least one of the following places: within a NOTICE text
100
+ file distributed as part of the Derivative Works; within
101
+ the Source form or documentation, if provided along with the
102
+ Derivative Works; or, within a display generated by the
103
+ Derivative Works, if and wherever such third-party notices
104
+ normally appear. The contents of the NOTICE file are for
105
+ informational purposes only and do not modify the License.
106
+ You may add Your own attribution notices within Derivative
107
+ Works that You distribute, alongside or as an addendum to
108
+ the NOTICE text from the Work, provided that such additional
109
+ attribution notices cannot be construed as modifying the License.
110
+
111
+ You may add Your own license statement for Your modifications and
112
+ may provide additional grant of rights to use, copy, modify, merge,
113
+ publish, distribute, sublicense, and/or sell copies of the Work,
114
+ and to permit persons to whom the Work is furnished to do so,
115
+ subject to the following conditions:
116
+
117
+ The above copyright notice and this permission notice shall be
118
+ included in all copies or substantial portions of the Work.
119
+
120
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
121
+ any Contribution intentionally submitted for inclusion in the Work
122
+ by You to the Licensor shall be under the terms and conditions of
123
+ this License, without any additional terms or conditions.
124
+ Notwithstanding the above, nothing herein shall supersede or modify
125
+ the terms of any separate license agreement you may have executed
126
+ with Licensor regarding such Contributions.
127
+
128
+ 6. Trademarks. This License does not grant permission to use the trade
129
+ names, trademarks, service marks, or product names of the Licensor,
130
+ except as required for reasonable and customary use in describing the
131
+ origin of the Work and reproducing the content of the NOTICE file.
132
+
133
+ 7. Disclaimer of Warranty. Unless required by applicable law or
134
+ agreed to in writing, Licensor provides the Work (and each
135
+ Contributor provides its Contributions) on an "AS IS" BASIS,
136
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
137
+ implied, including, without limitation, any warranties or conditions
138
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
139
+ PARTICULAR PURPOSE. You are solely responsible for determining the
140
+ appropriateness of using or redistributing the Work and assume any
141
+ risks associated with Your exercise of permissions under this License.
142
+
143
+ 8. Limitation of Liability. In no event and under no legal theory,
144
+ whether in tort (including negligence), contract, or otherwise,
145
+ unless required by applicable law (such as deliberate and grossly
146
+ negligent acts) or agreed to in writing, shall any Contributor be
147
+ liable to You for damages, including any direct, indirect, special,
148
+ incidental, or exemplary damages of any character arising as a
149
+ result of this License or out of the use or inability to use the
150
+ Work (including but not limited to damages for loss of goodwill,
151
+ work stoppage, computer failure or malfunction, or all other
152
+ commercial damages or losses), even if such Contributor has been
153
+ advised of the possibility of such damages.
154
+
155
+ 9. Accepting Warranty or Additional Liability. While redistributing
156
+ the Work or Derivative Works thereof, You may choose to offer,
157
+ and charge a fee for, acceptance of support, warranty, indemnity,
158
+ or other liability obligations and/or rights consistent with this
159
+ License. However, in accepting such obligations, You may act only
160
+ on Your own behalf and on Your sole responsibility, not on behalf
161
+ of any other Contributor, and only if You agree to indemnify,
162
+ defend, and hold each Contributor harmless for any liability
163
+ incurred by, or claims asserted against, such Contributor by reason
164
+ of your accepting any such warranty or additional liability.
165
+
166
+ END OF TERMS AND CONDITIONS
167
+
168
+ APPENDIX: How to apply the Apache License to your work.
169
+
170
+ To apply the Apache License to your work, attach the following
171
+ boilerplate notice, with the fields enclosed by brackets "[]"
172
+ replaced with your own identifying information. (Don't include
173
+ the brackets!) The text should be enclosed in the appropriate
174
+ comment syntax for the file format in use. Also, it is recommended
175
+ that a file or directory name be given on the same line as the
176
+ copyright notice for easier identification within third-party archives.
177
+
178
+ Copyright 2026 smbCloud (Splitfire AB)
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
Makefile
new
+113
@@ -0,0 +1,113 @@
1
+SHELL := /bin/sh
2
+
3
+SWIFT_REPO := $(CURDIR)
4
+CLI_REPO ?= $(abspath ../smbcloud-cli)
5
+CARGO_MANIFEST := $(CLI_REPO)/Cargo.toml
6
+APPLE_CRATE_MANIFEST := $(CLI_REPO)/crates/smbcloud-auth-sdk-apple/Cargo.toml
7
+BINDGEN := $(CLI_REPO)/target/release/uniffi-bindgen
8
+
9
+RUST_STABLE ?= +1.92.0
10
+RUST_NIGHTLY ?= +nightly
11
+
12
+IOS_DEPLOYMENT_TARGET ?= 16.0
13
+MACOS_DEPLOYMENT_TARGET ?= 14.0
14
+TVOS_DEPLOYMENT_TARGET ?= 16.0
15
+VISIONOS_DEPLOYMENT_TARGET ?= 1.0
16
+
17
+LOCAL_DIR := $(SWIFT_REPO)/.local
18
+GENERATED_DIR := $(LOCAL_DIR)/generated/SmbCloudAuth
19
+HEADERS_DIR := $(LOCAL_DIR)/Headers
20
+FRAMEWORK_DIR := $(SWIFT_REPO)/SmbCloudAuthFramework.xcframework
21
+SWIFT_GLUE := $(SWIFT_REPO)/Sources/SmbCloudAuth/smbcloud_auth.swift
22
+
23
+LIB_NAME := libsmbcloud_auth.a
24
+
25
+SUPPORTED_PLATFORMS := ios macos tvos visionos
26
+
27
+.PHONY: help platform ios macos tvos visionos validate build-bindgen prepare generate-swift clean
28
+
29
+help:
30
+ @printf '%s\n' \
31
+ 'SmbCloudAuth Swift — local Apple-platform builds' \
32
+ '' \
33
+ 'Usage:' \
34
+ ' make ios Build SmbCloudAuthFramework.xcframework for iOS device + simulator' \
35
+ ' make macos Build SmbCloudAuthFramework.xcframework for macOS (Apple silicon)' \
36
+ ' make tvos Build SmbCloudAuthFramework.xcframework for tvOS device + simulator' \
37
+ ' make visionos Build SmbCloudAuthFramework.xcframework for visionOS device + simulator' \
38
+ '' \
39
+ 'Artifacts:' \
40
+ ' SmbCloudAuthFramework.xcframework/' \
41
+ ' Sources/SmbCloudAuth/smbcloud_auth.swift (regenerated from the local Rust build)' \
42
+ '' \
43
+ 'Optional overrides:' \
44
+ ' CLI_REPO=/absolute/path/to/smbcloud-cli'
45
+
46
+platform:
47
+ @test -n "$(PLATFORM)" || { echo "Set PLATFORM=$(SUPPORTED_PLATFORMS)"; exit 1; }
48
+ @case "$(PLATFORM)" in \
49
+ ios|macos|tvos|visionos) $(MAKE) "$(PLATFORM)" ;; \
50
+ *) echo "Unsupported PLATFORM='$(PLATFORM)'. Expected one of: $(SUPPORTED_PLATFORMS)"; exit 1 ;; \
51
+ esac
52
+
53
+validate:
54
+ @test -f "$(CARGO_MANIFEST)" || { echo "Could not find workspace Cargo.toml at $(CARGO_MANIFEST). Set CLI_REPO."; exit 1; }
55
+ @test -f "$(APPLE_CRATE_MANIFEST)" || { echo "Could not find smbcloud-auth-sdk-apple crate at $(APPLE_CRATE_MANIFEST)"; exit 1; }
56
+ @test -d "$(SWIFT_REPO)/Sources/SmbCloudAuth" || { echo "Run make from the smbcloud-auth Swift package root."; exit 1; }
57
+
58
+build-bindgen: validate
59
+ cargo $(RUST_STABLE) build --manifest-path "$(APPLE_CRATE_MANIFEST)" --features bindgen --bin uniffi-bindgen --release
60
+
61
+prepare:
62
+ @rm -rf "$(FRAMEWORK_DIR)" "$(GENERATED_DIR)" "$(HEADERS_DIR)"
63
+ @mkdir -p "$(GENERATED_DIR)" "$(HEADERS_DIR)"
64
+
65
+generate-swift:
66
+ @test -n "$(BINDGEN_INPUT)" || { echo "BINDGEN_INPUT is required"; exit 1; }
67
+ cd "$(CLI_REPO)" && "$(BINDGEN)" generate --library "$(BINDGEN_INPUT)" --language swift --out-dir "$(GENERATED_DIR)"
68
+ cp "$(GENERATED_DIR)/smbcloud_auth.swift" "$(SWIFT_GLUE)"
69
+ cp "$(GENERATED_DIR)/smbcloud_authFFI.h" "$(HEADERS_DIR)/smbcloud_authFFI.h"
70
+ cp "$(GENERATED_DIR)/smbcloud_authFFI.modulemap" "$(HEADERS_DIR)/module.modulemap"
71
+ @echo "Updated $(SWIFT_GLUE)"
72
+
73
+ios: build-bindgen prepare
74
+ IPHONEOS_DEPLOYMENT_TARGET=$(IOS_DEPLOYMENT_TARGET) cargo $(RUST_STABLE) rustc --manifest-path "$(CARGO_MANIFEST)" --package smbcloud-auth-sdk-apple --target aarch64-apple-ios --release --lib --crate-type staticlib
75
+ IPHONEOS_DEPLOYMENT_TARGET=$(IOS_DEPLOYMENT_TARGET) cargo $(RUST_STABLE) rustc --manifest-path "$(CARGO_MANIFEST)" --package smbcloud-auth-sdk-apple --target aarch64-apple-ios-sim --release --lib --crate-type staticlib
76
+ $(MAKE) generate-swift BINDGEN_INPUT="$(CLI_REPO)/target/aarch64-apple-ios/release/$(LIB_NAME)"
77
+ xcodebuild -create-xcframework \
78
+ -library "$(CLI_REPO)/target/aarch64-apple-ios/release/$(LIB_NAME)" -headers "$(HEADERS_DIR)" \
79
+ -library "$(CLI_REPO)/target/aarch64-apple-ios-sim/release/$(LIB_NAME)" -headers "$(HEADERS_DIR)" \
80
+ -output "$(FRAMEWORK_DIR)"
81
+ @echo "Built $(FRAMEWORK_DIR) for iOS"
82
+
83
+macos: build-bindgen prepare
84
+ MACOSX_DEPLOYMENT_TARGET=$(MACOS_DEPLOYMENT_TARGET) cargo $(RUST_STABLE) rustc --manifest-path "$(CARGO_MANIFEST)" --package smbcloud-auth-sdk-apple --target aarch64-apple-darwin --release --lib --crate-type staticlib
85
+ $(MAKE) generate-swift BINDGEN_INPUT="$(CLI_REPO)/target/aarch64-apple-darwin/release/$(LIB_NAME)"
86
+ xcodebuild -create-xcframework \
87
+ -library "$(CLI_REPO)/target/aarch64-apple-darwin/release/$(LIB_NAME)" -headers "$(HEADERS_DIR)" \
88
+ -output "$(FRAMEWORK_DIR)"
89
+ @echo "Built $(FRAMEWORK_DIR) for macOS"
90
+
91
+tvos: build-bindgen prepare
92
+ TVOS_DEPLOYMENT_TARGET=$(TVOS_DEPLOYMENT_TARGET) cargo $(RUST_NIGHTLY) rustc -Z build-std --manifest-path "$(CARGO_MANIFEST)" --package smbcloud-auth-sdk-apple --target aarch64-apple-tvos --release --lib --crate-type staticlib
93
+ TVOS_DEPLOYMENT_TARGET=$(TVOS_DEPLOYMENT_TARGET) cargo $(RUST_NIGHTLY) rustc -Z build-std --manifest-path "$(CARGO_MANIFEST)" --package smbcloud-auth-sdk-apple --target aarch64-apple-tvos-sim --release --lib --crate-type staticlib
94
+ $(MAKE) generate-swift BINDGEN_INPUT="$(CLI_REPO)/target/aarch64-apple-tvos/release/$(LIB_NAME)"
95
+ xcodebuild -create-xcframework \
96
+ -library "$(CLI_REPO)/target/aarch64-apple-tvos/release/$(LIB_NAME)" -headers "$(HEADERS_DIR)" \
97
+ -library "$(CLI_REPO)/target/aarch64-apple-tvos-sim/release/$(LIB_NAME)" -headers "$(HEADERS_DIR)" \
98
+ -output "$(FRAMEWORK_DIR)"
99
+ @echo "Built $(FRAMEWORK_DIR) for tvOS"
100
+
101
+visionos: build-bindgen prepare
102
+ XROS_DEPLOYMENT_TARGET=$(VISIONOS_DEPLOYMENT_TARGET) cargo $(RUST_NIGHTLY) rustc -Z build-std --manifest-path "$(CARGO_MANIFEST)" --package smbcloud-auth-sdk-apple --target aarch64-apple-visionos --release --lib --crate-type staticlib
103
+ XROS_DEPLOYMENT_TARGET=$(VISIONOS_DEPLOYMENT_TARGET) cargo $(RUST_NIGHTLY) rustc -Z build-std --manifest-path "$(CARGO_MANIFEST)" --package smbcloud-auth-sdk-apple --target aarch64-apple-visionos-sim --release --lib --crate-type staticlib
104
+ $(MAKE) generate-swift BINDGEN_INPUT="$(CLI_REPO)/target/aarch64-apple-visionos/release/$(LIB_NAME)"
105
+ xcodebuild -create-xcframework \
106
+ -library "$(CLI_REPO)/target/aarch64-apple-visionos/release/$(LIB_NAME)" -headers "$(HEADERS_DIR)" \
107
+ -library "$(CLI_REPO)/target/aarch64-apple-visionos-sim/release/$(LIB_NAME)" -headers "$(HEADERS_DIR)" \
108
+ -output "$(FRAMEWORK_DIR)"
109
+ @echo "Built $(FRAMEWORK_DIR) for visionOS"
110
+
111
+clean:
112
+ rm -rf "$(FRAMEWORK_DIR)" "$(LOCAL_DIR)"
113
+ @echo "Removed local SmbCloudAuth Swift build artifacts"
Package.swift
new
+56
@@ -0,0 +1,56 @@
1
+// swift-tools-version:6.2
2
+import Foundation
3
+import PackageDescription
4
+
5
+// ─────────────────────────────────────────────────────────────────────────────
6
+// SmbCloudAuth Swift SDK
7
+//
8
+// Local development: run `make ios` (or another platform target) to build
9
+// SmbCloudAuthFramework.xcframework from the Rust source. When the local
10
+// framework directory exists, SwiftPM links it directly.
11
+//
12
+// Distribution: consumers add this package via its Git URL. Without the local
13
+// framework on disk, SwiftPM downloads the pre-built zip from GitHub Releases.
14
+// ─────────────────────────────────────────────────────────────────────────────
15
+
16
+let packageRoot = URL(fileURLWithPath: #filePath).deletingLastPathComponent()
17
+let localFrameworkPath = "SmbCloudAuthFramework.xcframework"
18
+let localFrameworkAbsolutePath = packageRoot.appendingPathComponent(localFrameworkPath).path
19
+
20
+// Update these two values when cutting a new release.
21
+let releaseFrameworkURL =
22
+ "https://github.com/smbcloudXYZ/smbcloud-auth-swift/releases/download/0.4.1/SmbCloudAuthFramework.xcframework.zip"
23
+let releaseFrameworkChecksum =
24
+ "0000000000000000000000000000000000000000000000000000000000000000"
25
+
26
+let smbCloudAuthFrameworkTarget: Target
27
+if FileManager.default.fileExists(atPath: localFrameworkAbsolutePath) {
28
+ smbCloudAuthFrameworkTarget = .binaryTarget(
29
+ name: "SmbCloudAuthFramework",
30
+ path: localFrameworkPath
31
+ )
32
+} else {
33
+ smbCloudAuthFrameworkTarget = .binaryTarget(
34
+ name: "SmbCloudAuthFramework",
35
+ url: releaseFrameworkURL,
36
+ checksum: releaseFrameworkChecksum
37
+ )
38
+}
39
+
40
+let package = Package(
41
+ name: "SmbCloudAuth",
42
+ platforms: [
43
+ .iOS(.v16), .macOS(.v14), .tvOS(.v16), .visionOS(.v1),
44
+ ],
45
+ products: [
46
+ .library(name: "SmbCloudAuth", targets: ["SmbCloudAuth"])
47
+ ],
48
+ targets: [
49
+ smbCloudAuthFrameworkTarget,
50
+ .target(
51
+ name: "SmbCloudAuth",
52
+ dependencies: [.target(name: "SmbCloudAuthFramework")],
53
+ path: "Sources/SmbCloudAuth"
54
+ ),
55
+ ]
56
+)
README.md
new
+219
@@ -0,0 +1,219 @@
1
+<h1 align="center">smbCloud Auth for Swift</h1>
2
+
3
+<p align="center">
4
+ <strong>Authenticate users on Apple platforms with <a href="https://smbcloud.xyz">smbCloud</a>.</strong>
5
+</p>
6
+
7
+<p align="center">
8
+ <a href="https://smbcloud.xyz"><img src="https://img.shields.io/badge/smbcloud.xyz-0969DA?style=flat-square&labelColor=1A1A1A" alt="Website"></a>
9
+ <a href="https://github.com/smbcloudXYZ/smbcloud-auth-swift/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-Apache--2.0-0969DA?style=flat-square&labelColor=1A1A1A" alt="License"></a>
10
+</p>
11
+
12
+<p align="center">
13
+ <a href="https://github.com/smbcloudXYZ/smbcloud-cli">CLI</a> ·
14
+ <a href="https://www.npmjs.com/package/@smbcloud/sdk-auth">npm</a> ·
15
+ <a href="https://pypi.org/project/smbcloud-sdk-auth/">PyPI</a> ·
16
+ <a href="https://rubygems.org/gems/smbcloud-auth">RubyGems</a> ·
17
+ <a href="https://smbcloud.xyz">Website</a>
18
+</p>
19
+
20
+---
21
+
22
+## Platforms
23
+
24
+| Platform | Minimum |
25
+|----------|---------|
26
+| iOS | 16.0 |
27
+| macOS | 14.0 |
28
+| tvOS | 16.0 |
29
+| visionOS | 1.0 |
30
+
31
+## Installation
32
+
33
+### Xcode
34
+
35
+**File → Add Package Dependencies**, then enter:
36
+
37
+```
38
+https://github.com/smbcloudXYZ/smbcloud-auth-swift
39
+```
40
+
41
+### Swift Package Manager
42
+
43
+```swift
44
+dependencies: [
45
+ .package(url: "https://github.com/smbcloudXYZ/smbcloud-auth-swift", from: "0.4.1")
46
+],
47
+targets: [
48
+ .target(name: "MyApp", dependencies: [
49
+ .product(name: "SmbCloudAuth", package: "smbcloud-auth-swift")
50
+ ])
51
+]
52
+```
53
+
54
+### XcodeGen
55
+
56
+```yaml
57
+packages:
58
+ SmbCloudAuth:
59
+ url: https://github.com/smbcloudXYZ/smbcloud-auth-swift
60
+ from: 0.4.1
61
+targets:
62
+ MyApp:
63
+ dependencies:
64
+ - package: SmbCloudAuth
65
+ product: SmbCloudAuth
66
+```
67
+
68
+## Quick Start
69
+
70
+```swift
71
+import SmbCloudAuth
72
+
73
+let auth = SmbCloudAuth(
74
+ environment: .production,
75
+ appId: "your-app-id",
76
+ appSecret: "your-app-secret"
77
+)
78
+
79
+// Sign up
80
+let result = try await auth.signup(email: "user@example.com", password: "s3cret")
81
+
82
+// Log in
83
+let status = try await auth.login(email: "user@example.com", password: "s3cret")
84
+switch status {
85
+case .ready(let accessToken):
86
+ print("Authenticated: \(accessToken)")
87
+case .incomplete(let errorCode):
88
+ print("Account incomplete: \(errorCode)")
89
+case .notFound:
90
+ print("Account not found")
91
+}
92
+
93
+// Get current user
94
+let user = try await auth.me(accessToken: "Bearer ...")
95
+print(user.email)
96
+
97
+// Log out
98
+try await auth.logout(accessToken: "Bearer ...")
99
+```
100
+
101
+## Apple Sign-In
102
+
103
+```swift
104
+// Build the authorization URL
105
+let request = try auth.buildAppleAuthorizationRequest(
106
+ redirectUri: "myapp://auth/callback",
107
+ state: nil // auto-generated if nil
108
+)
109
+
110
+// Open request.authorizeUrl in a browser or ASWebAuthenticationSession,
111
+// then parse the callback:
112
+let session = try auth.parseAppleCallbackUrl(
113
+ callbackUrl: callbackUrl,
114
+ expectedState: request.state
115
+)
116
+print(session.accessToken)
117
+```
118
+
119
+## OIDC (Authorization Code + PKCE)
120
+
121
+```swift
122
+// 1. Build authorization request
123
+let request = try auth.buildOidcAuthorizationRequest(
124
+ oidcClientId: "your-oidc-client-id",
125
+ redirectUri: "myapp://auth/callback"
126
+)
127
+// Open request.authorizeUrl in a browser...
128
+
129
+// 2. Parse the callback
130
+let callback = try auth.parseOidcCallbackUrl(callbackUrl: callbackUrl)
131
+
132
+// 3. Exchange the code for tokens
133
+let tokens = try await auth.exchangeOidcCode(
134
+ oidcClientId: "your-oidc-client-id",
135
+ redirectUri: "myapp://auth/callback",
136
+ code: callback.code,
137
+ codeVerifier: request.codeVerifier
138
+)
139
+print(tokens.accessToken)
140
+
141
+// 4. Fetch user info
142
+let userInfo = try await auth.getOidcUserinfo(
143
+ accessToken: tokens.accessToken,
144
+ tenantId: nil
145
+)
146
+print(userInfo.email ?? "no email")
147
+```
148
+
149
+## Error Handling
150
+
151
+All methods throw `SmbCloudAuthError` on failure:
152
+
153
+```swift
154
+do {
155
+ let status = try await auth.login(email: email, password: password)
156
+} catch let error as SmbCloudAuthError {
157
+ switch error {
158
+ case .api(let errorCode, let message):
159
+ print("API error \(errorCode): \(message)")
160
+ }
161
+}
162
+```
163
+
164
+## API Reference
165
+
166
+### `SmbCloudAuth`
167
+
168
+| Method | Description |
169
+|--------|-------------|
170
+| `login(email:password:)` | Authenticate with email and password |
171
+| `signup(email:password:)` | Create a new account |
172
+| `logout(accessToken:)` | Invalidate an access token |
173
+| `me(accessToken:)` | Fetch the authenticated user profile |
174
+| `removeAccount(accessToken:)` | Permanently delete the authenticated account |
175
+| `buildAppleAuthorizationRequest(redirectUri:state:)` | Build an Apple Sign-In authorization URL |
176
+| `parseAppleCallbackUrl(callbackUrl:expectedState:)` | Parse the Apple Sign-In callback |
177
+| `buildOidcAuthorizationRequest(oidcClientId:redirectUri:)` | Build an OIDC authorization URL with PKCE |
178
+| `parseOidcCallbackUrl(callbackUrl:)` | Parse the OIDC callback for code and state |
179
+| `exchangeOidcCode(oidcClientId:redirectUri:code:codeVerifier:)` | Exchange an authorization code for tokens |
180
+| `getOidcUserinfo(accessToken:tenantId:)` | Fetch OIDC user info |
181
+
182
+## Local Development
183
+
184
+Clone this repo alongside [smbcloud-cli](https://github.com/smbcloudXYZ/smbcloud-cli):
185
+
186
+```
187
+Repositories/
188
+├── smbcloud-cli/
189
+└── smbcloud-auth-swift/
190
+```
191
+
192
+Build the XCFramework from the Rust source:
193
+
194
+```bash
195
+make ios # iOS device + simulator
196
+make macos # macOS (Apple silicon)
197
+make tvos # tvOS device + simulator
198
+make visionos # visionOS device + simulator
199
+```
200
+
201
+This cross-compiles the Rust `smbcloud-auth-sdk-apple` crate, generates Swift bindings via [UniFFI](https://mozilla.github.io/uniffi-rs/), and packages everything into `SmbCloudAuthFramework.xcframework`.
202
+
203
+To point at a different checkout of the Rust repo:
204
+
205
+```bash
206
+make ios CLI_REPO=/path/to/smbcloud-cli
207
+```
208
+
209
+## How It Works
210
+
211
+This package wraps the [smbcloud-auth-sdk](https://github.com/smbcloudXYZ/smbcloud-cli/tree/development/crates/smbcloud-auth-sdk) Rust crate, compiled to a static library for each Apple platform and bridged to Swift via [UniFFI](https://mozilla.github.io/uniffi-rs/) proc-macros. The result is a native Swift API with full async/await support — no Objective-C bridging headers, no C interop in your app code.
212
+
213
+## License
214
+
215
+Apache 2.0. See [LICENSE](LICENSE).
216
+
217
+---
218
+
219
+© 2025 [smbCloud](https://smbcloud.xyz).
Sources/SmbCloudAuth/smbcloud_auth.swift
new
+1973
@@ -0,0 +1,1973 @@
1
+// This file was autogenerated by some hot garbage in the `uniffi` crate.
2
+// Trust me, you don't want to mess with it!
3
+
4
+// swiftlint:disable all
5
+import Foundation
6
+
7
+// Depending on the consumer's build setup, the low-level FFI code
8
+// might be in a separate module, or it might be compiled inline into
9
+// this module. This is a bit of light hackery to work with both.
10
+#if canImport(smbcloud_authFFI)
11
+import smbcloud_authFFI
12
+#endif
13
+
14
+fileprivate extension RustBuffer {
15
+ // Allocate a new buffer, copying the contents of a `UInt8` array.
16
+ init(bytes: [UInt8]) {
17
+ let rbuf = bytes.withUnsafeBufferPointer { ptr in
18
+ RustBuffer.from(ptr)
19
+ }
20
+ self.init(capacity: rbuf.capacity, len: rbuf.len, data: rbuf.data)
21
+ }
22
+
23
+ static func empty() -> RustBuffer {
24
+ RustBuffer(capacity: 0, len:0, data: nil)
25
+ }
26
+
27
+ static func from(_ ptr: UnsafeBufferPointer<UInt8>) -> RustBuffer {
28
+ try! rustCall { ffi_smbcloud_auth_rustbuffer_from_bytes(ForeignBytes(bufferPointer: ptr), $0) }
29
+ }
30
+
31
+ // Frees the buffer in place.
32
+ // The buffer must not be used after this is called.
33
+ func deallocate() {
34
+ try! rustCall { ffi_smbcloud_auth_rustbuffer_free(self, $0) }
35
+ }
36
+}
37
+
38
+fileprivate extension ForeignBytes {
39
+ init(bufferPointer: UnsafeBufferPointer<UInt8>) {
40
+ self.init(len: Int32(bufferPointer.count), data: bufferPointer.baseAddress)
41
+ }
42
+}
43
+
44
+// For every type used in the interface, we provide helper methods for conveniently
45
+// lifting and lowering that type from C-compatible data, and for reading and writing
46
+// values of that type in a buffer.
47
+
48
+// Helper classes/extensions that don't change.
49
+// Someday, this will be in a library of its own.
50
+
51
+fileprivate extension Data {
52
+ init(rustBuffer: RustBuffer) {
53
+ self.init(
54
+ bytesNoCopy: rustBuffer.data!,
55
+ count: Int(rustBuffer.len),
56
+ deallocator: .none
57
+ )
58
+ }
59
+}
60
+
61
+// Define reader functionality. Normally this would be defined in a class or
62
+// struct, but we use standalone functions instead in order to make external
63
+// types work.
64
+//
65
+// With external types, one swift source file needs to be able to call the read
66
+// method on another source file's FfiConverter, but then what visibility
67
+// should Reader have?
68
+// - If Reader is fileprivate, then this means the read() must also
69
+// be fileprivate, which doesn't work with external types.
70
+// - If Reader is internal/public, we'll get compile errors since both source
71
+// files will try define the same type.
72
+//
73
+// Instead, the read() method and these helper functions input a tuple of data
74
+
75
+fileprivate func createReader(data: Data) -> (data: Data, offset: Data.Index) {
76
+ (data: data, offset: 0)
77
+}
78
+
79
+// Reads an integer at the current offset, in big-endian order, and advances
80
+// the offset on success. Throws if reading the integer would move the
81
+// offset past the end of the buffer.
82
+fileprivate func readInt<T: FixedWidthInteger>(_ reader: inout (data: Data, offset: Data.Index)) throws -> T {
83
+ let range = reader.offset..<reader.offset + MemoryLayout<T>.size
84
+ guard reader.data.count >= range.upperBound else {
85
+ throw UniffiInternalError.bufferOverflow
86
+ }
87
+ if T.self == UInt8.self {
88
+ let value = reader.data[reader.offset]
89
+ reader.offset += 1
90
+ return value as! T
91
+ }
92
+ var value: T = 0
93
+ let _ = withUnsafeMutableBytes(of: &value, { reader.data.copyBytes(to: $0, from: range)})
94
+ reader.offset = range.upperBound
95
+ return value.bigEndian
96
+}
97
+
98
+// Reads an arbitrary number of bytes, to be used to read
99
+// raw bytes, this is useful when lifting strings
100
+fileprivate func readBytes(_ reader: inout (data: Data, offset: Data.Index), count: Int) throws -> Array<UInt8> {
101
+ let range = reader.offset..<(reader.offset+count)
102
+ guard reader.data.count >= range.upperBound else {
103
+ throw UniffiInternalError.bufferOverflow
104
+ }
105
+ var value = [UInt8](repeating: 0, count: count)
106
+ value.withUnsafeMutableBufferPointer({ buffer in
107
+ reader.data.copyBytes(to: buffer, from: range)
108
+ })
109
+ reader.offset = range.upperBound
110
+ return value
111
+}
112
+
113
+// Reads a float at the current offset.
114
+fileprivate func readFloat(_ reader: inout (data: Data, offset: Data.Index)) throws -> Float {
115
+ return Float(bitPattern: try readInt(&reader))
116
+}
117
+
118
+// Reads a float at the current offset.
119
+fileprivate func readDouble(_ reader: inout (data: Data, offset: Data.Index)) throws -> Double {
120
+ return Double(bitPattern: try readInt(&reader))
121
+}
122
+
123
+// Indicates if the offset has reached the end of the buffer.
124
+fileprivate func hasRemaining(_ reader: (data: Data, offset: Data.Index)) -> Bool {
125
+ return reader.offset < reader.data.count
126
+}
127
+
128
+// Define writer functionality. Normally this would be defined in a class or
129
+// struct, but we use standalone functions instead in order to make external
130
+// types work. See the above discussion on Readers for details.
131
+
132
+fileprivate func createWriter() -> [UInt8] {
133
+ return []
134
+}
135
+
136
+fileprivate func writeBytes<S>(_ writer: inout [UInt8], _ byteArr: S) where S: Sequence, S.Element == UInt8 {
137
+ writer.append(contentsOf: byteArr)
138
+}
139
+
140
+// Writes an integer in big-endian order.
141
+//
142
+// Warning: make sure what you are trying to write
143
+// is in the correct type!
144
+fileprivate func writeInt<T: FixedWidthInteger>(_ writer: inout [UInt8], _ value: T) {
145
+ var value = value.bigEndian
146
+ withUnsafeBytes(of: &value) { writer.append(contentsOf: $0) }
147
+}
148
+
149
+fileprivate func writeFloat(_ writer: inout [UInt8], _ value: Float) {
150
+ writeInt(&writer, value.bitPattern)
151
+}
152
+
153
+fileprivate func writeDouble(_ writer: inout [UInt8], _ value: Double) {
154
+ writeInt(&writer, value.bitPattern)
155
+}
156
+
157
+// Protocol for types that transfer other types across the FFI. This is
158
+// analogous to the Rust trait of the same name.
159
+fileprivate protocol FfiConverter {
160
+ associatedtype FfiType
161
+ associatedtype SwiftType
162
+
163
+ static func lift(_ value: FfiType) throws -> SwiftType
164
+ static func lower(_ value: SwiftType) -> FfiType
165
+ static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType
166
+ static func write(_ value: SwiftType, into buf: inout [UInt8])
167
+}
168
+
169
+// Types conforming to `Primitive` pass themselves directly over the FFI.
170
+fileprivate protocol FfiConverterPrimitive: FfiConverter where FfiType == SwiftType { }
171
+
172
+extension FfiConverterPrimitive {
173
+#if swift(>=5.8)
174
+ @_documentation(visibility: private)
175
+#endif
176
+ public static func lift(_ value: FfiType) throws -> SwiftType {
177
+ return value
178
+ }
179
+
180
+#if swift(>=5.8)
181
+ @_documentation(visibility: private)
182
+#endif
183
+ public static func lower(_ value: SwiftType) -> FfiType {
184
+ return value
185
+ }
186
+}
187
+
188
+// Types conforming to `FfiConverterRustBuffer` lift and lower into a `RustBuffer`.
189
+// Used for complex types where it's hard to write a custom lift/lower.
190
+fileprivate protocol FfiConverterRustBuffer: FfiConverter where FfiType == RustBuffer {}
191
+
192
+extension FfiConverterRustBuffer {
193
+#if swift(>=5.8)
194
+ @_documentation(visibility: private)
195
+#endif
196
+ public static func lift(_ buf: RustBuffer) throws -> SwiftType {
197
+ var reader = createReader(data: Data(rustBuffer: buf))
198
+ let value = try read(from: &reader)
199
+ if hasRemaining(reader) {
200
+ throw UniffiInternalError.incompleteData
201
+ }
202
+ buf.deallocate()
203
+ return value
204
+ }
205
+
206
+#if swift(>=5.8)
207
+ @_documentation(visibility: private)
208
+#endif
209
+ public static func lower(_ value: SwiftType) -> RustBuffer {
210
+ var writer = createWriter()
211
+ write(value, into: &writer)
212
+ return RustBuffer(bytes: writer)
213
+ }
214
+}
215
+// An error type for FFI errors. These errors occur at the UniFFI level, not
216
+// the library level.
217
+fileprivate enum UniffiInternalError: LocalizedError {
218
+ case bufferOverflow
219
+ case incompleteData
220
+ case unexpectedOptionalTag
221
+ case unexpectedEnumCase
222
+ case unexpectedNullPointer
223
+ case unexpectedRustCallStatusCode
224
+ case unexpectedRustCallError
225
+ case unexpectedStaleHandle
226
+ case rustPanic(_ message: String)
227
+
228
+ public var errorDescription: String? {
229
+ switch self {
230
+ case .bufferOverflow: return "Reading the requested value would read past the end of the buffer"
231
+ case .incompleteData: return "The buffer still has data after lifting its containing value"
232
+ case .unexpectedOptionalTag: return "Unexpected optional tag; should be 0 or 1"
233
+ case .unexpectedEnumCase: return "Raw enum value doesn't match any cases"
234
+ case .unexpectedNullPointer: return "Raw pointer value was null"
235
+ case .unexpectedRustCallStatusCode: return "Unexpected RustCallStatus code"
236
+ case .unexpectedRustCallError: return "CALL_ERROR but no errorClass specified"
237
+ case .unexpectedStaleHandle: return "The object in the handle map has been dropped already"
238
+ case let .rustPanic(message): return message
239
+ }
240
+ }
241
+}
242
+
243
+fileprivate extension NSLock {
244
+ func withLock<T>(f: () throws -> T) rethrows -> T {
245
+ self.lock()
246
+ defer { self.unlock() }
247
+ return try f()
248
+ }
249
+}
250
+
251
+fileprivate let CALL_SUCCESS: Int8 = 0
252
+fileprivate let CALL_ERROR: Int8 = 1
253
+fileprivate let CALL_UNEXPECTED_ERROR: Int8 = 2
254
+fileprivate let CALL_CANCELLED: Int8 = 3
255
+
256
+fileprivate extension RustCallStatus {
257
+ init() {
258
+ self.init(
259
+ code: CALL_SUCCESS,
260
+ errorBuf: RustBuffer.init(
261
+ capacity: 0,
262
+ len: 0,
263
+ data: nil
264
+ )
265
+ )
266
+ }
267
+}
268
+
269
+private func rustCall<T>(_ callback: (UnsafeMutablePointer<RustCallStatus>) -> T) throws -> T {
270
+ let neverThrow: ((RustBuffer) throws -> Never)? = nil
271
+ return try makeRustCall(callback, errorHandler: neverThrow)
272
+}
273
+
274
+private func rustCallWithError<T, E: Swift.Error>(
275
+ _ errorHandler: @escaping (RustBuffer) throws -> E,
276
+ _ callback: (UnsafeMutablePointer<RustCallStatus>) -> T) throws -> T {
277
+ try makeRustCall(callback, errorHandler: errorHandler)
278
+}
279
+
280
+private func makeRustCall<T, E: Swift.Error>(
281
+ _ callback: (UnsafeMutablePointer<RustCallStatus>) -> T,
282
+ errorHandler: ((RustBuffer) throws -> E)?
283
+) throws -> T {
284
+ uniffiEnsureSmbcloudAuthInitialized()
285
+ var callStatus = RustCallStatus.init()
286
+ let returnedVal = callback(&callStatus)
287
+ try uniffiCheckCallStatus(callStatus: callStatus, errorHandler: errorHandler)
288
+ return returnedVal
289
+}
290
+
291
+private func uniffiCheckCallStatus<E: Swift.Error>(
292
+ callStatus: RustCallStatus,
293
+ errorHandler: ((RustBuffer) throws -> E)?
294
+) throws {
295
+ switch callStatus.code {
296
+ case CALL_SUCCESS:
297
+ return
298
+
299
+ case CALL_ERROR:
300
+ if let errorHandler = errorHandler {
301
+ throw try errorHandler(callStatus.errorBuf)
302
+ } else {
303
+ callStatus.errorBuf.deallocate()
304
+ throw UniffiInternalError.unexpectedRustCallError
305
+ }
306
+
307
+ case CALL_UNEXPECTED_ERROR:
308
+ // When the rust code sees a panic, it tries to construct a RustBuffer
309
+ // with the message. But if that code panics, then it just sends back
310
+ // an empty buffer.
311
+ if callStatus.errorBuf.len > 0 {
312
+ throw UniffiInternalError.rustPanic(try FfiConverterString.lift(callStatus.errorBuf))
313
+ } else {
314
+ callStatus.errorBuf.deallocate()
315
+ throw UniffiInternalError.rustPanic("Rust panic")
316
+ }
317
+
318
+ case CALL_CANCELLED:
319
+ fatalError("Cancellation not supported yet")
320
+
321
+ default:
322
+ throw UniffiInternalError.unexpectedRustCallStatusCode
323
+ }
324
+}
325
+
326
+private func uniffiTraitInterfaceCall<T>(
327
+ callStatus: UnsafeMutablePointer<RustCallStatus>,
328
+ makeCall: () throws -> T,
329
+ writeReturn: (T) -> ()
330
+) {
331
+ do {
332
+ try writeReturn(makeCall())
333
+ } catch let error {
334
+ callStatus.pointee.code = CALL_UNEXPECTED_ERROR
335
+ callStatus.pointee.errorBuf = FfiConverterString.lower(String(describing: error))
336
+ }
337
+}
338
+
339
+private func uniffiTraitInterfaceCallWithError<T, E>(
340
+ callStatus: UnsafeMutablePointer<RustCallStatus>,
341
+ makeCall: () throws -> T,
342
+ writeReturn: (T) -> (),
343
+ lowerError: (E) -> RustBuffer
344
+) {
345
+ do {
346
+ try writeReturn(makeCall())
347
+ } catch let error as E {
348
+ callStatus.pointee.code = CALL_ERROR
349
+ callStatus.pointee.errorBuf = lowerError(error)
350
+ } catch {
351
+ callStatus.pointee.code = CALL_UNEXPECTED_ERROR
352
+ callStatus.pointee.errorBuf = FfiConverterString.lower(String(describing: error))
353
+ }
354
+}
355
+fileprivate final class UniffiHandleMap<T>: @unchecked Sendable {
356
+ // All mutation happens with this lock held, which is why we implement @unchecked Sendable.
357
+ private let lock = NSLock()
358
+ private var map: [UInt64: T] = [:]
359
+ private var currentHandle: UInt64 = 1
360
+
361
+ func insert(obj: T) -> UInt64 {
362
+ lock.withLock {
363
+ let handle = currentHandle
364
+ currentHandle += 1
365
+ map[handle] = obj
366
+ return handle
367
+ }
368
+ }
369
+
370
+ func get(handle: UInt64) throws -> T {
371
+ try lock.withLock {
372
+ guard let obj = map[handle] else {
373
+ throw UniffiInternalError.unexpectedStaleHandle
374
+ }
375
+ return obj
376
+ }
377
+ }
378
+
379
+ @discardableResult
380
+ func remove(handle: UInt64) throws -> T {
381
+ try lock.withLock {
382
+ guard let obj = map.removeValue(forKey: handle) else {
383
+ throw UniffiInternalError.unexpectedStaleHandle
384
+ }
385
+ return obj
386
+ }
387
+ }
388
+
389
+ var count: Int {
390
+ get {
391
+ map.count
392
+ }
393
+ }
394
+}
395
+
396
+
397
+// Public interface members begin here.
398
+
399
+
400
+#if swift(>=5.8)
401
+@_documentation(visibility: private)
402
+#endif
403
+fileprivate struct FfiConverterUInt32: FfiConverterPrimitive {
404
+ typealias FfiType = UInt32
405
+ typealias SwiftType = UInt32
406
+
407
+ public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> UInt32 {
408
+ return try lift(readInt(&buf))
409
+ }
410
+
411
+ public static func write(_ value: SwiftType, into buf: inout [UInt8]) {
412
+ writeInt(&buf, lower(value))
413
+ }
414
+}
415
+
416
+#if swift(>=5.8)
417
+@_documentation(visibility: private)
418
+#endif
419
+fileprivate struct FfiConverterInt32: FfiConverterPrimitive {
420
+ typealias FfiType = Int32
421
+ typealias SwiftType = Int32
422
+
423
+ public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Int32 {
424
+ return try lift(readInt(&buf))
425
+ }
426
+
427
+ public static func write(_ value: Int32, into buf: inout [UInt8]) {
428
+ writeInt(&buf, lower(value))
429
+ }
430
+}
431
+
432
+#if swift(>=5.8)
433
+@_documentation(visibility: private)
434
+#endif
435
+fileprivate struct FfiConverterUInt64: FfiConverterPrimitive {
436
+ typealias FfiType = UInt64
437
+ typealias SwiftType = UInt64
438
+
439
+ public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> UInt64 {
440
+ return try lift(readInt(&buf))
441
+ }
442
+
443
+ public static func write(_ value: SwiftType, into buf: inout [UInt8]) {
444
+ writeInt(&buf, lower(value))
445
+ }
446
+}
447
+
448
+#if swift(>=5.8)
449
+@_documentation(visibility: private)
450
+#endif
451
+fileprivate struct FfiConverterBool : FfiConverter {
452
+ typealias FfiType = Int8
453
+ typealias SwiftType = Bool
454
+
455
+ public static func lift(_ value: Int8) throws -> Bool {
456
+ return value != 0
457
+ }
458
+
459
+ public static func lower(_ value: Bool) -> Int8 {
460
+ return value ? 1 : 0
461
+ }
462
+
463
+ public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> Bool {
464
+ return try lift(readInt(&buf))
465
+ }
466
+
467
+ public static func write(_ value: Bool, into buf: inout [UInt8]) {
468
+ writeInt(&buf, lower(value))
469
+ }
470
+}
471
+
472
+#if swift(>=5.8)
473
+@_documentation(visibility: private)
474
+#endif
475
+fileprivate struct FfiConverterString: FfiConverter {
476
+ typealias SwiftType = String
477
+ typealias FfiType = RustBuffer
478
+
479
+ public static func lift(_ value: RustBuffer) throws -> String {
480
+ defer {
481
+ value.deallocate()
482
+ }
483
+ if value.data == nil {
484
+ return String()
485
+ }
486
+ let bytes = UnsafeBufferPointer<UInt8>(start: value.data!, count: Int(value.len))
487
+ return String(bytes: bytes, encoding: String.Encoding.utf8)!
488
+ }
489
+
490
+ public static func lower(_ value: String) -> RustBuffer {
491
+ return value.utf8CString.withUnsafeBufferPointer { ptr in
492
+ // The swift string gives us int8_t, we want uint8_t.
493
+ ptr.withMemoryRebound(to: UInt8.self) { ptr in
494
+ // The swift string gives us a trailing null byte, we don't want it.
495
+ let buf = UnsafeBufferPointer(rebasing: ptr.prefix(upTo: ptr.count - 1))
496
+ return RustBuffer.from(buf)
497
+ }
498
+ }
499
+ }
500
+
501
+ public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> String {
502
+ let len: Int32 = try readInt(&buf)
503
+ return String(bytes: try readBytes(&buf, count: Int(len)), encoding: String.Encoding.utf8)!
504
+ }
505
+
506
+ public static func write(_ value: String, into buf: inout [UInt8]) {
507
+ let len = Int32(value.utf8.count)
508
+ writeInt(&buf, len)
509
+ writeBytes(&buf, value.utf8)
510
+ }
511
+}
512
+
513
+
514
+
515
+
516
+public protocol SmbCloudAuthProtocol: AnyObject, Sendable {
517
+
518
+ func buildAppleAuthorizationRequest(redirectUri: String, state: String?) throws -> SmbCloudAppleAuthorizationRequest
519
+
520
+ func buildOidcAuthorizationRequest(oidcClientId: String, redirectUri: String) throws -> SmbCloudAuthorizationRequest
521
+
522
+ func exchangeOidcCode(oidcClientId: String, redirectUri: String, code: String, codeVerifier: String) async throws -> SmbCloudTokenResponse
523
+
524
+ func getOidcUserinfo(accessToken: String, tenantId: String?) async throws -> SmbCloudUserInfo
525
+
526
+ func login(email: String, password: String) async throws -> SmbCloudAccountStatus
527
+
528
+ func logout(accessToken: String) async throws
529
+
530
+ func me(accessToken: String) async throws -> SmbCloudUser
531
+
532
+ func parseAppleCallbackUrl(callbackUrl: String, expectedState: String?) throws -> SmbCloudAppleAuthSession
533
+
534
+ func parseOidcCallbackUrl(callbackUrl: String) throws -> SmbCloudCallbackPayload
535
+
536
+ func removeAccount(accessToken: String) async throws
537
+
538
+ func signup(email: String, password: String) async throws -> SmbCloudSignupResult
539
+
540
+}
541
+open class SmbCloudAuth: SmbCloudAuthProtocol, @unchecked Sendable {
542
+ fileprivate let pointer: UnsafeMutableRawPointer!
543
+
544
+ /// Used to instantiate a [FFIObject] without an actual pointer, for fakes in tests, mostly.
545
+#if swift(>=5.8)
546
+ @_documentation(visibility: private)
547
+#endif
548
+ public struct NoPointer {
549
+ public init() {}
550
+ }
551
+
552
+ // TODO: We'd like this to be `private` but for Swifty reasons,
553
+ // we can't implement `FfiConverter` without making this `required` and we can't
554
+ // make it `required` without making it `public`.
555
+#if swift(>=5.8)
556
+ @_documentation(visibility: private)
557
+#endif
558
+ required public init(unsafeFromRawPointer pointer: UnsafeMutableRawPointer) {
559
+ self.pointer = pointer
560
+ }
561
+
562
+ // This constructor can be used to instantiate a fake object.
563
+ // - Parameter noPointer: Placeholder value so we can have a constructor separate from the default empty one that may be implemented for classes extending [FFIObject].
564
+ //
565
+ // - Warning:
566
+ // Any object instantiated with this constructor cannot be passed to an actual Rust-backed object. Since there isn't a backing [Pointer] the FFI lower functions will crash.
567
+#if swift(>=5.8)
568
+ @_documentation(visibility: private)
569
+#endif
570
+ public init(noPointer: NoPointer) {
571
+ self.pointer = nil
572
+ }
573
+
574
+#if swift(>=5.8)
575
+ @_documentation(visibility: private)
576
+#endif
577
+ public func uniffiClonePointer() -> UnsafeMutableRawPointer {
578
+ return try! rustCall { uniffi_smbcloud_auth_fn_clone_smbcloudauth(self.pointer, $0) }
579
+ }
580
+public convenience init(environment: SmbCloudEnvironment, appId: String, appSecret: String) {
581
+ let pointer =
582
+ try! rustCall() {
583
+ uniffi_smbcloud_auth_fn_constructor_smbcloudauth_new(
584
+ FfiConverterTypeSmbCloudEnvironment_lower(environment),
585
+ FfiConverterString.lower(appId),
586
+ FfiConverterString.lower(appSecret),$0
587
+ )
588
+}
589
+ self.init(unsafeFromRawPointer: pointer)
590
+}
591
+
592
+ deinit {
593
+ guard let pointer = pointer else {
594
+ return
595
+ }
596
+
597
+ try! rustCall { uniffi_smbcloud_auth_fn_free_smbcloudauth(pointer, $0) }
598
+ }
599
+
600
+
601
+
602
+
603
+open func buildAppleAuthorizationRequest(redirectUri: String, state: String?)throws -> SmbCloudAppleAuthorizationRequest {
604
+ return try FfiConverterTypeSmbCloudAppleAuthorizationRequest_lift(try rustCallWithError(FfiConverterTypeSmbCloudAuthError_lift) {
605
+ uniffi_smbcloud_auth_fn_method_smbcloudauth_build_apple_authorization_request(self.uniffiClonePointer(),
606
+ FfiConverterString.lower(redirectUri),
607
+ FfiConverterOptionString.lower(state),$0
608
+ )
609
+})
610
+}
611
+
612
+open func buildOidcAuthorizationRequest(oidcClientId: String, redirectUri: String)throws -> SmbCloudAuthorizationRequest {
613
+ return try FfiConverterTypeSmbCloudAuthorizationRequest_lift(try rustCallWithError(FfiConverterTypeSmbCloudAuthError_lift) {
614
+ uniffi_smbcloud_auth_fn_method_smbcloudauth_build_oidc_authorization_request(self.uniffiClonePointer(),
615
+ FfiConverterString.lower(oidcClientId),
616
+ FfiConverterString.lower(redirectUri),$0
617
+ )
618
+})
619
+}
620
+
621
+open func exchangeOidcCode(oidcClientId: String, redirectUri: String, code: String, codeVerifier: String)async throws -> SmbCloudTokenResponse {
622
+ return
623
+ try await uniffiRustCallAsync(
624
+ rustFutureFunc: {
625
+ uniffi_smbcloud_auth_fn_method_smbcloudauth_exchange_oidc_code(
626
+ self.uniffiClonePointer(),
627
+ FfiConverterString.lower(oidcClientId),FfiConverterString.lower(redirectUri),FfiConverterString.lower(code),FfiConverterString.lower(codeVerifier)
628
+ )
629
+ },
630
+ pollFunc: ffi_smbcloud_auth_rust_future_poll_rust_buffer,
631
+ completeFunc: ffi_smbcloud_auth_rust_future_complete_rust_buffer,
632
+ freeFunc: ffi_smbcloud_auth_rust_future_free_rust_buffer,
633
+ liftFunc: FfiConverterTypeSmbCloudTokenResponse_lift,
634
+ errorHandler: FfiConverterTypeSmbCloudAuthError_lift
635
+ )
636
+}
637
+
638
+open func getOidcUserinfo(accessToken: String, tenantId: String?)async throws -> SmbCloudUserInfo {
639
+ return
640
+ try await uniffiRustCallAsync(
641
+ rustFutureFunc: {
642
+ uniffi_smbcloud_auth_fn_method_smbcloudauth_get_oidc_userinfo(
643
+ self.uniffiClonePointer(),
644
+ FfiConverterString.lower(accessToken),FfiConverterOptionString.lower(tenantId)
645
+ )
646
+ },
647
+ pollFunc: ffi_smbcloud_auth_rust_future_poll_rust_buffer,
648
+ completeFunc: ffi_smbcloud_auth_rust_future_complete_rust_buffer,
649
+ freeFunc: ffi_smbcloud_auth_rust_future_free_rust_buffer,
650
+ liftFunc: FfiConverterTypeSmbCloudUserInfo_lift,
651
+ errorHandler: FfiConverterTypeSmbCloudAuthError_lift
652
+ )
653
+}
654
+
655
+open func login(email: String, password: String)async throws -> SmbCloudAccountStatus {
656
+ return
657
+ try await uniffiRustCallAsync(
658
+ rustFutureFunc: {
659
+ uniffi_smbcloud_auth_fn_method_smbcloudauth_login(
660
+ self.uniffiClonePointer(),
661
+ FfiConverterString.lower(email),FfiConverterString.lower(password)
662
+ )
663
+ },
664
+ pollFunc: ffi_smbcloud_auth_rust_future_poll_rust_buffer,
665
+ completeFunc: ffi_smbcloud_auth_rust_future_complete_rust_buffer,
666
+ freeFunc: ffi_smbcloud_auth_rust_future_free_rust_buffer,
667
+ liftFunc: FfiConverterTypeSmbCloudAccountStatus_lift,
668
+ errorHandler: FfiConverterTypeSmbCloudAuthError_lift
669
+ )
670
+}
671
+
672
+open func logout(accessToken: String)async throws {
673
+ return
674
+ try await uniffiRustCallAsync(
675
+ rustFutureFunc: {
676
+ uniffi_smbcloud_auth_fn_method_smbcloudauth_logout(
677
+ self.uniffiClonePointer(),
678
+ FfiConverterString.lower(accessToken)
679
+ )
680
+ },
681
+ pollFunc: ffi_smbcloud_auth_rust_future_poll_void,
682
+ completeFunc: ffi_smbcloud_auth_rust_future_complete_void,
683
+ freeFunc: ffi_smbcloud_auth_rust_future_free_void,
684
+ liftFunc: { $0 },
685
+ errorHandler: FfiConverterTypeSmbCloudAuthError_lift
686
+ )
687
+}
688
+
689
+open func me(accessToken: String)async throws -> SmbCloudUser {
690
+ return
691
+ try await uniffiRustCallAsync(
692
+ rustFutureFunc: {
693
+ uniffi_smbcloud_auth_fn_method_smbcloudauth_me(
694
+ self.uniffiClonePointer(),
695
+ FfiConverterString.lower(accessToken)
696
+ )
697
+ },
698
+ pollFunc: ffi_smbcloud_auth_rust_future_poll_rust_buffer,
699
+ completeFunc: ffi_smbcloud_auth_rust_future_complete_rust_buffer,
700
+ freeFunc: ffi_smbcloud_auth_rust_future_free_rust_buffer,
701
+ liftFunc: FfiConverterTypeSmbCloudUser_lift,
702
+ errorHandler: FfiConverterTypeSmbCloudAuthError_lift
703
+ )
704
+}
705
+
706
+open func parseAppleCallbackUrl(callbackUrl: String, expectedState: String?)throws -> SmbCloudAppleAuthSession {
707
+ return try FfiConverterTypeSmbCloudAppleAuthSession_lift(try rustCallWithError(FfiConverterTypeSmbCloudAuthError_lift) {
708
+ uniffi_smbcloud_auth_fn_method_smbcloudauth_parse_apple_callback_url(self.uniffiClonePointer(),
709
+ FfiConverterString.lower(callbackUrl),
710
+ FfiConverterOptionString.lower(expectedState),$0
711
+ )
712
+})
713
+}
714
+
715
+open func parseOidcCallbackUrl(callbackUrl: String)throws -> SmbCloudCallbackPayload {
716
+ return try FfiConverterTypeSmbCloudCallbackPayload_lift(try rustCallWithError(FfiConverterTypeSmbCloudAuthError_lift) {
717
+ uniffi_smbcloud_auth_fn_method_smbcloudauth_parse_oidc_callback_url(self.uniffiClonePointer(),
718
+ FfiConverterString.lower(callbackUrl),$0
719
+ )
720
+})
721
+}
722
+
723
+open func removeAccount(accessToken: String)async throws {
724
+ return
725
+ try await uniffiRustCallAsync(
726
+ rustFutureFunc: {
727
+ uniffi_smbcloud_auth_fn_method_smbcloudauth_remove_account(
728
+ self.uniffiClonePointer(),
729
+ FfiConverterString.lower(accessToken)
730
+ )
731
+ },
732
+ pollFunc: ffi_smbcloud_auth_rust_future_poll_void,
733
+ completeFunc: ffi_smbcloud_auth_rust_future_complete_void,
734
+ freeFunc: ffi_smbcloud_auth_rust_future_free_void,
735
+ liftFunc: { $0 },
736
+ errorHandler: FfiConverterTypeSmbCloudAuthError_lift
737
+ )
738
+}
739
+
740
+open func signup(email: String, password: String)async throws -> SmbCloudSignupResult {
741
+ return
742
+ try await uniffiRustCallAsync(
743
+ rustFutureFunc: {
744
+ uniffi_smbcloud_auth_fn_method_smbcloudauth_signup(
745
+ self.uniffiClonePointer(),
746
+ FfiConverterString.lower(email),FfiConverterString.lower(password)
747
+ )
748
+ },
749
+ pollFunc: ffi_smbcloud_auth_rust_future_poll_rust_buffer,
750
+ completeFunc: ffi_smbcloud_auth_rust_future_complete_rust_buffer,
751
+ freeFunc: ffi_smbcloud_auth_rust_future_free_rust_buffer,
752
+ liftFunc: FfiConverterTypeSmbCloudSignupResult_lift,
753
+ errorHandler: FfiConverterTypeSmbCloudAuthError_lift
754
+ )
755
+}
756
+
757
+
758
+}
759
+
760
+
761
+#if swift(>=5.8)
762
+@_documentation(visibility: private)
763
+#endif
764
+public struct FfiConverterTypeSmbCloudAuth: FfiConverter {
765
+
766
+ typealias FfiType = UnsafeMutableRawPointer
767
+ typealias SwiftType = SmbCloudAuth
768
+
769
+ public static func lift(_ pointer: UnsafeMutableRawPointer) throws -> SmbCloudAuth {
770
+ return SmbCloudAuth(unsafeFromRawPointer: pointer)
771
+ }
772
+
773
+ public static func lower(_ value: SmbCloudAuth) -> UnsafeMutableRawPointer {
774
+ return value.uniffiClonePointer()
775
+ }
776
+
777
+ public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SmbCloudAuth {
778
+ let v: UInt64 = try readInt(&buf)
779
+ // The Rust code won't compile if a pointer won't fit in a UInt64.
780
+ // We have to go via `UInt` because that's the thing that's the size of a pointer.
781
+ let ptr = UnsafeMutableRawPointer(bitPattern: UInt(truncatingIfNeeded: v))
782
+ if (ptr == nil) {
783
+ throw UniffiInternalError.unexpectedNullPointer
784
+ }
785
+ return try lift(ptr!)
786
+ }
787
+
788
+ public static func write(_ value: SmbCloudAuth, into buf: inout [UInt8]) {
789
+ // This fiddling is because `Int` is the thing that's the same size as a pointer.
790
+ // The Rust code won't compile if a pointer won't fit in a `UInt64`.
791
+ writeInt(&buf, UInt64(bitPattern: Int64(Int(bitPattern: lower(value)))))
792
+ }
793
+}
794
+
795
+
796
+#if swift(>=5.8)
797
+@_documentation(visibility: private)
798
+#endif
799
+public func FfiConverterTypeSmbCloudAuth_lift(_ pointer: UnsafeMutableRawPointer) throws -> SmbCloudAuth {
800
+ return try FfiConverterTypeSmbCloudAuth.lift(pointer)
801
+}
802
+
803
+#if swift(>=5.8)
804
+@_documentation(visibility: private)
805
+#endif
806
+public func FfiConverterTypeSmbCloudAuth_lower(_ value: SmbCloudAuth) -> UnsafeMutableRawPointer {
807
+ return FfiConverterTypeSmbCloudAuth.lower(value)
808
+}
809
+
810
+
811
+
812
+
813
+public struct SmbCloudAppleAuthSession {
814
+ public var accessToken: String
815
+ public var refreshToken: String?
816
+ public var email: String?
817
+ public var name: String?
818
+ public var provider: String
819
+ public var providerAccountId: String
820
+ public var state: String?
821
+
822
+ // Default memberwise initializers are never public by default, so we
823
+ // declare one manually.
824
+ public init(accessToken: String, refreshToken: String?, email: String?, name: String?, provider: String, providerAccountId: String, state: String?) {
825
+ self.accessToken = accessToken
826
+ self.refreshToken = refreshToken
827
+ self.email = email
828
+ self.name = name
829
+ self.provider = provider
830
+ self.providerAccountId = providerAccountId
831
+ self.state = state
832
+ }
833
+}
834
+
835
+#if compiler(>=6)
836
+extension SmbCloudAppleAuthSession: Sendable {}
837
+#endif
838
+
839
+
840
+extension SmbCloudAppleAuthSession: Equatable, Hashable {
841
+ public static func ==(lhs: SmbCloudAppleAuthSession, rhs: SmbCloudAppleAuthSession) -> Bool {
842
+ if lhs.accessToken != rhs.accessToken {
843
+ return false
844
+ }
845
+ if lhs.refreshToken != rhs.refreshToken {
846
+ return false
847
+ }
848
+ if lhs.email != rhs.email {
849
+ return false
850
+ }
851
+ if lhs.name != rhs.name {
852
+ return false
853
+ }
854
+ if lhs.provider != rhs.provider {
855
+ return false
856
+ }
857
+ if lhs.providerAccountId != rhs.providerAccountId {
858
+ return false
859
+ }
860
+ if lhs.state != rhs.state {
861
+ return false
862
+ }
863
+ return true
864
+ }
865
+
866
+ public func hash(into hasher: inout Hasher) {
867
+ hasher.combine(accessToken)
868
+ hasher.combine(refreshToken)
869
+ hasher.combine(email)
870
+ hasher.combine(name)
871
+ hasher.combine(provider)
872
+ hasher.combine(providerAccountId)
873
+ hasher.combine(state)
874
+ }
875
+}
876
+
877
+
878
+
879
+#if swift(>=5.8)
880
+@_documentation(visibility: private)
881
+#endif
882
+public struct FfiConverterTypeSmbCloudAppleAuthSession: FfiConverterRustBuffer {
883
+ public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SmbCloudAppleAuthSession {
884
+ return
885
+ try SmbCloudAppleAuthSession(
886
+ accessToken: FfiConverterString.read(from: &buf),
887
+ refreshToken: FfiConverterOptionString.read(from: &buf),
888
+ email: FfiConverterOptionString.read(from: &buf),
889
+ name: FfiConverterOptionString.read(from: &buf),
890
+ provider: FfiConverterString.read(from: &buf),
891
+ providerAccountId: FfiConverterString.read(from: &buf),
892
+ state: FfiConverterOptionString.read(from: &buf)
893
+ )
894
+ }
895
+
896
+ public static func write(_ value: SmbCloudAppleAuthSession, into buf: inout [UInt8]) {
897
+ FfiConverterString.write(value.accessToken, into: &buf)
898
+ FfiConverterOptionString.write(value.refreshToken, into: &buf)
899
+ FfiConverterOptionString.write(value.email, into: &buf)
900
+ FfiConverterOptionString.write(value.name, into: &buf)
901
+ FfiConverterString.write(value.provider, into: &buf)
902
+ FfiConverterString.write(value.providerAccountId, into: &buf)
903
+ FfiConverterOptionString.write(value.state, into: &buf)
904
+ }
905
+}
906
+
907
+
908
+#if swift(>=5.8)
909
+@_documentation(visibility: private)
910
+#endif
911
+public func FfiConverterTypeSmbCloudAppleAuthSession_lift(_ buf: RustBuffer) throws -> SmbCloudAppleAuthSession {
912
+ return try FfiConverterTypeSmbCloudAppleAuthSession.lift(buf)
913
+}
914
+
915
+#if swift(>=5.8)
916
+@_documentation(visibility: private)
917
+#endif
918
+public func FfiConverterTypeSmbCloudAppleAuthSession_lower(_ value: SmbCloudAppleAuthSession) -> RustBuffer {
919
+ return FfiConverterTypeSmbCloudAppleAuthSession.lower(value)
920
+}
921
+
922
+
923
+public struct SmbCloudAppleAuthorizationRequest {
924
+ public var authorizeUrl: String
925
+ public var redirectUri: String
926
+ public var state: String
927
+
928
+ // Default memberwise initializers are never public by default, so we
929
+ // declare one manually.
930
+ public init(authorizeUrl: String, redirectUri: String, state: String) {
931
+ self.authorizeUrl = authorizeUrl
932
+ self.redirectUri = redirectUri
933
+ self.state = state
934
+ }
935
+}
936
+
937
+#if compiler(>=6)
938
+extension SmbCloudAppleAuthorizationRequest: Sendable {}
939
+#endif
940
+
941
+
942
+extension SmbCloudAppleAuthorizationRequest: Equatable, Hashable {
943
+ public static func ==(lhs: SmbCloudAppleAuthorizationRequest, rhs: SmbCloudAppleAuthorizationRequest) -> Bool {
944
+ if lhs.authorizeUrl != rhs.authorizeUrl {
945
+ return false
946
+ }
947
+ if lhs.redirectUri != rhs.redirectUri {
948
+ return false
949
+ }
950
+ if lhs.state != rhs.state {
951
+ return false
952
+ }
953
+ return true
954
+ }
955
+
956
+ public func hash(into hasher: inout Hasher) {
957
+ hasher.combine(authorizeUrl)
958
+ hasher.combine(redirectUri)
959
+ hasher.combine(state)
960
+ }
961
+}
962
+
963
+
964
+
965
+#if swift(>=5.8)
966
+@_documentation(visibility: private)
967
+#endif
968
+public struct FfiConverterTypeSmbCloudAppleAuthorizationRequest: FfiConverterRustBuffer {
969
+ public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SmbCloudAppleAuthorizationRequest {
970
+ return
971
+ try SmbCloudAppleAuthorizationRequest(
972
+ authorizeUrl: FfiConverterString.read(from: &buf),
973
+ redirectUri: FfiConverterString.read(from: &buf),
974
+ state: FfiConverterString.read(from: &buf)
975
+ )
976
+ }
977
+
978
+ public static func write(_ value: SmbCloudAppleAuthorizationRequest, into buf: inout [UInt8]) {
979
+ FfiConverterString.write(value.authorizeUrl, into: &buf)
980
+ FfiConverterString.write(value.redirectUri, into: &buf)
981
+ FfiConverterString.write(value.state, into: &buf)
982
+ }
983
+}
984
+
985
+
986
+#if swift(>=5.8)
987
+@_documentation(visibility: private)
988
+#endif
989
+public func FfiConverterTypeSmbCloudAppleAuthorizationRequest_lift(_ buf: RustBuffer) throws -> SmbCloudAppleAuthorizationRequest {
990
+ return try FfiConverterTypeSmbCloudAppleAuthorizationRequest.lift(buf)
991
+}
992
+
993
+#if swift(>=5.8)
994
+@_documentation(visibility: private)
995
+#endif
996
+public func FfiConverterTypeSmbCloudAppleAuthorizationRequest_lower(_ value: SmbCloudAppleAuthorizationRequest) -> RustBuffer {
997
+ return FfiConverterTypeSmbCloudAppleAuthorizationRequest.lower(value)
998
+}
999
+
1000
+
1001
+public struct SmbCloudAuthorizationRequest {
1002
+ public var authorizeUrl: String
1003
+ public var redirectUri: String
1004
+ public var state: String
1005
+ public var codeVerifier: String
1006
+
1007
+ // Default memberwise initializers are never public by default, so we
1008
+ // declare one manually.
1009
+ public init(authorizeUrl: String, redirectUri: String, state: String, codeVerifier: String) {
1010
+ self.authorizeUrl = authorizeUrl
1011
+ self.redirectUri = redirectUri
1012
+ self.state = state
1013
+ self.codeVerifier = codeVerifier
1014
+ }
1015
+}
1016
+
1017
+#if compiler(>=6)
1018
+extension SmbCloudAuthorizationRequest: Sendable {}
1019
+#endif
1020
+
1021
+
1022
+extension SmbCloudAuthorizationRequest: Equatable, Hashable {
1023
+ public static func ==(lhs: SmbCloudAuthorizationRequest, rhs: SmbCloudAuthorizationRequest) -> Bool {
1024
+ if lhs.authorizeUrl != rhs.authorizeUrl {
1025
+ return false
1026
+ }
1027
+ if lhs.redirectUri != rhs.redirectUri {
1028
+ return false
1029
+ }
1030
+ if lhs.state != rhs.state {
1031
+ return false
1032
+ }
1033
+ if lhs.codeVerifier != rhs.codeVerifier {
1034
+ return false
1035
+ }
1036
+ return true
1037
+ }
1038
+
1039
+ public func hash(into hasher: inout Hasher) {
1040
+ hasher.combine(authorizeUrl)
1041
+ hasher.combine(redirectUri)
1042
+ hasher.combine(state)
1043
+ hasher.combine(codeVerifier)
1044
+ }
1045
+}
1046
+
1047
+
1048
+
1049
+#if swift(>=5.8)
1050
+@_documentation(visibility: private)
1051
+#endif
1052
+public struct FfiConverterTypeSmbCloudAuthorizationRequest: FfiConverterRustBuffer {
1053
+ public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SmbCloudAuthorizationRequest {
1054
+ return
1055
+ try SmbCloudAuthorizationRequest(
1056
+ authorizeUrl: FfiConverterString.read(from: &buf),
1057
+ redirectUri: FfiConverterString.read(from: &buf),
1058
+ state: FfiConverterString.read(from: &buf),
1059
+ codeVerifier: FfiConverterString.read(from: &buf)
1060
+ )
1061
+ }
1062
+
1063
+ public static func write(_ value: SmbCloudAuthorizationRequest, into buf: inout [UInt8]) {
1064
+ FfiConverterString.write(value.authorizeUrl, into: &buf)
1065
+ FfiConverterString.write(value.redirectUri, into: &buf)
1066
+ FfiConverterString.write(value.state, into: &buf)
1067
+ FfiConverterString.write(value.codeVerifier, into: &buf)
1068
+ }
1069
+}
1070
+
1071
+
1072
+#if swift(>=5.8)
1073
+@_documentation(visibility: private)
1074
+#endif
1075
+public func FfiConverterTypeSmbCloudAuthorizationRequest_lift(_ buf: RustBuffer) throws -> SmbCloudAuthorizationRequest {
1076
+ return try FfiConverterTypeSmbCloudAuthorizationRequest.lift(buf)
1077
+}
1078
+
1079
+#if swift(>=5.8)
1080
+@_documentation(visibility: private)
1081
+#endif
1082
+public func FfiConverterTypeSmbCloudAuthorizationRequest_lower(_ value: SmbCloudAuthorizationRequest) -> RustBuffer {
1083
+ return FfiConverterTypeSmbCloudAuthorizationRequest.lower(value)
1084
+}
1085
+
1086
+
1087
+public struct SmbCloudCallbackPayload {
1088
+ public var code: String
1089
+ public var state: String
1090
+
1091
+ // Default memberwise initializers are never public by default, so we
1092
+ // declare one manually.
1093
+ public init(code: String, state: String) {
1094
+ self.code = code
1095
+ self.state = state
1096
+ }
1097
+}
1098
+
1099
+#if compiler(>=6)
1100
+extension SmbCloudCallbackPayload: Sendable {}
1101
+#endif
1102
+
1103
+
1104
+extension SmbCloudCallbackPayload: Equatable, Hashable {
1105
+ public static func ==(lhs: SmbCloudCallbackPayload, rhs: SmbCloudCallbackPayload) -> Bool {
1106
+ if lhs.code != rhs.code {
1107
+ return false
1108
+ }
1109
+ if lhs.state != rhs.state {
1110
+ return false
1111
+ }
1112
+ return true
1113
+ }
1114
+
1115
+ public func hash(into hasher: inout Hasher) {
1116
+ hasher.combine(code)
1117
+ hasher.combine(state)
1118
+ }
1119
+}
1120
+
1121
+
1122
+
1123
+#if swift(>=5.8)
1124
+@_documentation(visibility: private)
1125
+#endif
1126
+public struct FfiConverterTypeSmbCloudCallbackPayload: FfiConverterRustBuffer {
1127
+ public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SmbCloudCallbackPayload {
1128
+ return
1129
+ try SmbCloudCallbackPayload(
1130
+ code: FfiConverterString.read(from: &buf),
1131
+ state: FfiConverterString.read(from: &buf)
1132
+ )
1133
+ }
1134
+
1135
+ public static func write(_ value: SmbCloudCallbackPayload, into buf: inout [UInt8]) {
1136
+ FfiConverterString.write(value.code, into: &buf)
1137
+ FfiConverterString.write(value.state, into: &buf)
1138
+ }
1139
+}
1140
+
1141
+
1142
+#if swift(>=5.8)
1143
+@_documentation(visibility: private)
1144
+#endif
1145
+public func FfiConverterTypeSmbCloudCallbackPayload_lift(_ buf: RustBuffer) throws -> SmbCloudCallbackPayload {
1146
+ return try FfiConverterTypeSmbCloudCallbackPayload.lift(buf)
1147
+}
1148
+
1149
+#if swift(>=5.8)
1150
+@_documentation(visibility: private)
1151
+#endif
1152
+public func FfiConverterTypeSmbCloudCallbackPayload_lower(_ value: SmbCloudCallbackPayload) -> RustBuffer {
1153
+ return FfiConverterTypeSmbCloudCallbackPayload.lower(value)
1154
+}
1155
+
1156
+
1157
+public struct SmbCloudSignupResult {
1158
+ public var code: Int32?
1159
+ public var message: String
1160
+ public var userId: Int32?
1161
+ public var userEmail: String?
1162
+ public var userCreatedAt: String?
1163
+
1164
+ // Default memberwise initializers are never public by default, so we
1165
+ // declare one manually.
1166
+ public init(code: Int32?, message: String, userId: Int32?, userEmail: String?, userCreatedAt: String?) {
1167
+ self.code = code
1168
+ self.message = message
1169
+ self.userId = userId
1170
+ self.userEmail = userEmail
1171
+ self.userCreatedAt = userCreatedAt
1172
+ }
1173
+}
1174
+
1175
+#if compiler(>=6)
1176
+extension SmbCloudSignupResult: Sendable {}
1177
+#endif
1178
+
1179
+
1180
+extension SmbCloudSignupResult: Equatable, Hashable {
1181
+ public static func ==(lhs: SmbCloudSignupResult, rhs: SmbCloudSignupResult) -> Bool {
1182
+ if lhs.code != rhs.code {
1183
+ return false
1184
+ }
1185
+ if lhs.message != rhs.message {
1186
+ return false
1187
+ }
1188
+ if lhs.userId != rhs.userId {
1189
+ return false
1190
+ }
1191
+ if lhs.userEmail != rhs.userEmail {
1192
+ return false
1193
+ }
1194
+ if lhs.userCreatedAt != rhs.userCreatedAt {
1195
+ return false
1196
+ }
1197
+ return true
1198
+ }
1199
+
1200
+ public func hash(into hasher: inout Hasher) {
1201
+ hasher.combine(code)
1202
+ hasher.combine(message)
1203
+ hasher.combine(userId)
1204
+ hasher.combine(userEmail)
1205
+ hasher.combine(userCreatedAt)
1206
+ }
1207
+}
1208
+
1209
+
1210
+
1211
+#if swift(>=5.8)
1212
+@_documentation(visibility: private)
1213
+#endif
1214
+public struct FfiConverterTypeSmbCloudSignupResult: FfiConverterRustBuffer {
1215
+ public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SmbCloudSignupResult {
1216
+ return
1217
+ try SmbCloudSignupResult(
1218
+ code: FfiConverterOptionInt32.read(from: &buf),
1219
+ message: FfiConverterString.read(from: &buf),
1220
+ userId: FfiConverterOptionInt32.read(from: &buf),
1221
+ userEmail: FfiConverterOptionString.read(from: &buf),
1222
+ userCreatedAt: FfiConverterOptionString.read(from: &buf)
1223
+ )
1224
+ }
1225
+
1226
+ public static func write(_ value: SmbCloudSignupResult, into buf: inout [UInt8]) {
1227
+ FfiConverterOptionInt32.write(value.code, into: &buf)
1228
+ FfiConverterString.write(value.message, into: &buf)
1229
+ FfiConverterOptionInt32.write(value.userId, into: &buf)
1230
+ FfiConverterOptionString.write(value.userEmail, into: &buf)
1231
+ FfiConverterOptionString.write(value.userCreatedAt, into: &buf)
1232
+ }
1233
+}
1234
+
1235
+
1236
+#if swift(>=5.8)
1237
+@_documentation(visibility: private)
1238
+#endif
1239
+public func FfiConverterTypeSmbCloudSignupResult_lift(_ buf: RustBuffer) throws -> SmbCloudSignupResult {
1240
+ return try FfiConverterTypeSmbCloudSignupResult.lift(buf)
1241
+}
1242
+
1243
+#if swift(>=5.8)
1244
+@_documentation(visibility: private)
1245
+#endif
1246
+public func FfiConverterTypeSmbCloudSignupResult_lower(_ value: SmbCloudSignupResult) -> RustBuffer {
1247
+ return FfiConverterTypeSmbCloudSignupResult.lower(value)
1248
+}
1249
+
1250
+
1251
+public struct SmbCloudTokenResponse {
1252
+ public var accessToken: String
1253
+ public var tokenType: String
1254
+ public var expiresIn: Int32?
1255
+ public var refreshToken: String?
1256
+ public var scope: String?
1257
+ public var idToken: String?
1258
+
1259
+ // Default memberwise initializers are never public by default, so we
1260
+ // declare one manually.
1261
+ public init(accessToken: String, tokenType: String, expiresIn: Int32?, refreshToken: String?, scope: String?, idToken: String?) {
1262
+ self.accessToken = accessToken
1263
+ self.tokenType = tokenType
1264
+ self.expiresIn = expiresIn
1265
+ self.refreshToken = refreshToken
1266
+ self.scope = scope
1267
+ self.idToken = idToken
1268
+ }
1269
+}
1270
+
1271
+#if compiler(>=6)
1272
+extension SmbCloudTokenResponse: Sendable {}
1273
+#endif
1274
+
1275
+
1276
+extension SmbCloudTokenResponse: Equatable, Hashable {
1277
+ public static func ==(lhs: SmbCloudTokenResponse, rhs: SmbCloudTokenResponse) -> Bool {
1278
+ if lhs.accessToken != rhs.accessToken {
1279
+ return false
1280
+ }
1281
+ if lhs.tokenType != rhs.tokenType {
1282
+ return false
1283
+ }
1284
+ if lhs.expiresIn != rhs.expiresIn {
1285
+ return false
1286
+ }
1287
+ if lhs.refreshToken != rhs.refreshToken {
1288
+ return false
1289
+ }
1290
+ if lhs.scope != rhs.scope {
1291
+ return false
1292
+ }
1293
+ if lhs.idToken != rhs.idToken {
1294
+ return false
1295
+ }
1296
+ return true
1297
+ }
1298
+
1299
+ public func hash(into hasher: inout Hasher) {
1300
+ hasher.combine(accessToken)
1301
+ hasher.combine(tokenType)
1302
+ hasher.combine(expiresIn)
1303
+ hasher.combine(refreshToken)
1304
+ hasher.combine(scope)
1305
+ hasher.combine(idToken)
1306
+ }
1307
+}
1308
+
1309
+
1310
+
1311
+#if swift(>=5.8)
1312
+@_documentation(visibility: private)
1313
+#endif
1314
+public struct FfiConverterTypeSmbCloudTokenResponse: FfiConverterRustBuffer {
1315
+ public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SmbCloudTokenResponse {
1316
+ return
1317
+ try SmbCloudTokenResponse(
1318
+ accessToken: FfiConverterString.read(from: &buf),
1319
+ tokenType: FfiConverterString.read(from: &buf),
1320
+ expiresIn: FfiConverterOptionInt32.read(from: &buf),
1321
+ refreshToken: FfiConverterOptionString.read(from: &buf),
1322
+ scope: FfiConverterOptionString.read(from: &buf),
1323
+ idToken: FfiConverterOptionString.read(from: &buf)
1324
+ )
1325
+ }
1326
+
1327
+ public static func write(_ value: SmbCloudTokenResponse, into buf: inout [UInt8]) {
1328
+ FfiConverterString.write(value.accessToken, into: &buf)
1329
+ FfiConverterString.write(value.tokenType, into: &buf)
1330
+ FfiConverterOptionInt32.write(value.expiresIn, into: &buf)
1331
+ FfiConverterOptionString.write(value.refreshToken, into: &buf)
1332
+ FfiConverterOptionString.write(value.scope, into: &buf)
1333
+ FfiConverterOptionString.write(value.idToken, into: &buf)
1334
+ }
1335
+}
1336
+
1337
+
1338
+#if swift(>=5.8)
1339
+@_documentation(visibility: private)
1340
+#endif
1341
+public func FfiConverterTypeSmbCloudTokenResponse_lift(_ buf: RustBuffer) throws -> SmbCloudTokenResponse {
1342
+ return try FfiConverterTypeSmbCloudTokenResponse.lift(buf)
1343
+}
1344
+
1345
+#if swift(>=5.8)
1346
+@_documentation(visibility: private)
1347
+#endif
1348
+public func FfiConverterTypeSmbCloudTokenResponse_lower(_ value: SmbCloudTokenResponse) -> RustBuffer {
1349
+ return FfiConverterTypeSmbCloudTokenResponse.lower(value)
1350
+}
1351
+
1352
+
1353
+public struct SmbCloudUser {
1354
+ public var id: Int32
1355
+ public var email: String
1356
+ public var createdAt: String
1357
+ public var updatedAt: String
1358
+
1359
+ // Default memberwise initializers are never public by default, so we
1360
+ // declare one manually.
1361
+ public init(id: Int32, email: String, createdAt: String, updatedAt: String) {
1362
+ self.id = id
1363
+ self.email = email
1364
+ self.createdAt = createdAt
1365
+ self.updatedAt = updatedAt
1366
+ }
1367
+}
1368
+
1369
+#if compiler(>=6)
1370
+extension SmbCloudUser: Sendable {}
1371
+#endif
1372
+
1373
+
1374
+extension SmbCloudUser: Equatable, Hashable {
1375
+ public static func ==(lhs: SmbCloudUser, rhs: SmbCloudUser) -> Bool {
1376
+ if lhs.id != rhs.id {
1377
+ return false
1378
+ }
1379
+ if lhs.email != rhs.email {
1380
+ return false
1381
+ }
1382
+ if lhs.createdAt != rhs.createdAt {
1383
+ return false
1384
+ }
1385
+ if lhs.updatedAt != rhs.updatedAt {
1386
+ return false
1387
+ }
1388
+ return true
1389
+ }
1390
+
1391
+ public func hash(into hasher: inout Hasher) {
1392
+ hasher.combine(id)
1393
+ hasher.combine(email)
1394
+ hasher.combine(createdAt)
1395
+ hasher.combine(updatedAt)
1396
+ }
1397
+}
1398
+
1399
+
1400
+
1401
+#if swift(>=5.8)
1402
+@_documentation(visibility: private)
1403
+#endif
1404
+public struct FfiConverterTypeSmbCloudUser: FfiConverterRustBuffer {
1405
+ public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SmbCloudUser {
1406
+ return
1407
+ try SmbCloudUser(
1408
+ id: FfiConverterInt32.read(from: &buf),
1409
+ email: FfiConverterString.read(from: &buf),
1410
+ createdAt: FfiConverterString.read(from: &buf),
1411
+ updatedAt: FfiConverterString.read(from: &buf)
1412
+ )
1413
+ }
1414
+
1415
+ public static func write(_ value: SmbCloudUser, into buf: inout [UInt8]) {
1416
+ FfiConverterInt32.write(value.id, into: &buf)
1417
+ FfiConverterString.write(value.email, into: &buf)
1418
+ FfiConverterString.write(value.createdAt, into: &buf)
1419
+ FfiConverterString.write(value.updatedAt, into: &buf)
1420
+ }
1421
+}
1422
+
1423
+
1424
+#if swift(>=5.8)
1425
+@_documentation(visibility: private)
1426
+#endif
1427
+public func FfiConverterTypeSmbCloudUser_lift(_ buf: RustBuffer) throws -> SmbCloudUser {
1428
+ return try FfiConverterTypeSmbCloudUser.lift(buf)
1429
+}
1430
+
1431
+#if swift(>=5.8)
1432
+@_documentation(visibility: private)
1433
+#endif
1434
+public func FfiConverterTypeSmbCloudUser_lower(_ value: SmbCloudUser) -> RustBuffer {
1435
+ return FfiConverterTypeSmbCloudUser.lower(value)
1436
+}
1437
+
1438
+
1439
+public struct SmbCloudUserInfo {
1440
+ public var sub: String
1441
+ public var email: String?
1442
+ public var emailVerified: Bool?
1443
+ public var tenantId: UInt64?
1444
+ public var tenantSlug: String?
1445
+
1446
+ // Default memberwise initializers are never public by default, so we
1447
+ // declare one manually.
1448
+ public init(sub: String, email: String?, emailVerified: Bool?, tenantId: UInt64?, tenantSlug: String?) {
1449
+ self.sub = sub
1450
+ self.email = email
1451
+ self.emailVerified = emailVerified
1452
+ self.tenantId = tenantId
1453
+ self.tenantSlug = tenantSlug
1454
+ }
1455
+}
1456
+
1457
+#if compiler(>=6)
1458
+extension SmbCloudUserInfo: Sendable {}
1459
+#endif
1460
+
1461
+
1462
+extension SmbCloudUserInfo: Equatable, Hashable {
1463
+ public static func ==(lhs: SmbCloudUserInfo, rhs: SmbCloudUserInfo) -> Bool {
1464
+ if lhs.sub != rhs.sub {
1465
+ return false
1466
+ }
1467
+ if lhs.email != rhs.email {
1468
+ return false
1469
+ }
1470
+ if lhs.emailVerified != rhs.emailVerified {
1471
+ return false
1472
+ }
1473
+ if lhs.tenantId != rhs.tenantId {
1474
+ return false
1475
+ }
1476
+ if lhs.tenantSlug != rhs.tenantSlug {
1477
+ return false
1478
+ }
1479
+ return true
1480
+ }
1481
+
1482
+ public func hash(into hasher: inout Hasher) {
1483
+ hasher.combine(sub)
1484
+ hasher.combine(email)
1485
+ hasher.combine(emailVerified)
1486
+ hasher.combine(tenantId)
1487
+ hasher.combine(tenantSlug)
1488
+ }
1489
+}
1490
+
1491
+
1492
+
1493
+#if swift(>=5.8)
1494
+@_documentation(visibility: private)
1495
+#endif
1496
+public struct FfiConverterTypeSmbCloudUserInfo: FfiConverterRustBuffer {
1497
+ public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SmbCloudUserInfo {
1498
+ return
1499
+ try SmbCloudUserInfo(
1500
+ sub: FfiConverterString.read(from: &buf),
1501
+ email: FfiConverterOptionString.read(from: &buf),
1502
+ emailVerified: FfiConverterOptionBool.read(from: &buf),
1503
+ tenantId: FfiConverterOptionUInt64.read(from: &buf),
1504
+ tenantSlug: FfiConverterOptionString.read(from: &buf)
1505
+ )
1506
+ }
1507
+
1508
+ public static func write(_ value: SmbCloudUserInfo, into buf: inout [UInt8]) {
1509
+ FfiConverterString.write(value.sub, into: &buf)
1510
+ FfiConverterOptionString.write(value.email, into: &buf)
1511
+ FfiConverterOptionBool.write(value.emailVerified, into: &buf)
1512
+ FfiConverterOptionUInt64.write(value.tenantId, into: &buf)
1513
+ FfiConverterOptionString.write(value.tenantSlug, into: &buf)
1514
+ }
1515
+}
1516
+
1517
+
1518
+#if swift(>=5.8)
1519
+@_documentation(visibility: private)
1520
+#endif
1521
+public func FfiConverterTypeSmbCloudUserInfo_lift(_ buf: RustBuffer) throws -> SmbCloudUserInfo {
1522
+ return try FfiConverterTypeSmbCloudUserInfo.lift(buf)
1523
+}
1524
+
1525
+#if swift(>=5.8)
1526
+@_documentation(visibility: private)
1527
+#endif
1528
+public func FfiConverterTypeSmbCloudUserInfo_lower(_ value: SmbCloudUserInfo) -> RustBuffer {
1529
+ return FfiConverterTypeSmbCloudUserInfo.lower(value)
1530
+}
1531
+
1532
+// Note that we don't yet support `indirect` for enums.
1533
+// See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion.
1534
+
1535
+public enum SmbCloudAccountStatus {
1536
+
1537
+ case notFound
1538
+ case ready(accessToken: String
1539
+ )
1540
+ case incomplete(errorCode: UInt32
1541
+ )
1542
+}
1543
+
1544
+
1545
+#if compiler(>=6)
1546
+extension SmbCloudAccountStatus: Sendable {}
1547
+#endif
1548
+
1549
+#if swift(>=5.8)
1550
+@_documentation(visibility: private)
1551
+#endif
1552
+public struct FfiConverterTypeSmbCloudAccountStatus: FfiConverterRustBuffer {
1553
+ typealias SwiftType = SmbCloudAccountStatus
1554
+
1555
+ public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SmbCloudAccountStatus {
1556
+ let variant: Int32 = try readInt(&buf)
1557
+ switch variant {
1558
+
1559
+ case 1: return .notFound
1560
+
1561
+ case 2: return .ready(accessToken: try FfiConverterString.read(from: &buf)
1562
+ )
1563
+
1564
+ case 3: return .incomplete(errorCode: try FfiConverterUInt32.read(from: &buf)
1565
+ )
1566
+
1567
+ default: throw UniffiInternalError.unexpectedEnumCase
1568
+ }
1569
+ }
1570
+
1571
+ public static func write(_ value: SmbCloudAccountStatus, into buf: inout [UInt8]) {
1572
+ switch value {
1573
+
1574
+
1575
+ case .notFound:
1576
+ writeInt(&buf, Int32(1))
1577
+
1578
+
1579
+ case let .ready(accessToken):
1580
+ writeInt(&buf, Int32(2))
1581
+ FfiConverterString.write(accessToken, into: &buf)
1582
+
1583
+
1584
+ case let .incomplete(errorCode):
1585
+ writeInt(&buf, Int32(3))
1586
+ FfiConverterUInt32.write(errorCode, into: &buf)
1587
+
1588
+ }
1589
+ }
1590
+}
1591
+
1592
+
1593
+#if swift(>=5.8)
1594
+@_documentation(visibility: private)
1595
+#endif
1596
+public func FfiConverterTypeSmbCloudAccountStatus_lift(_ buf: RustBuffer) throws -> SmbCloudAccountStatus {
1597
+ return try FfiConverterTypeSmbCloudAccountStatus.lift(buf)
1598
+}
1599
+
1600
+#if swift(>=5.8)
1601
+@_documentation(visibility: private)
1602
+#endif
1603
+public func FfiConverterTypeSmbCloudAccountStatus_lower(_ value: SmbCloudAccountStatus) -> RustBuffer {
1604
+ return FfiConverterTypeSmbCloudAccountStatus.lower(value)
1605
+}
1606
+
1607
+
1608
+extension SmbCloudAccountStatus: Equatable, Hashable {}
1609
+
1610
+
1611
+
1612
+
1613
+
1614
+
1615
+
1616
+public enum SmbCloudAuthError: Swift.Error {
1617
+
1618
+
1619
+
1620
+ case Api(errorCode: Int32, message: String
1621
+ )
1622
+}
1623
+
1624
+
1625
+#if swift(>=5.8)
1626
+@_documentation(visibility: private)
1627
+#endif
1628
+public struct FfiConverterTypeSmbCloudAuthError: FfiConverterRustBuffer {
1629
+ typealias SwiftType = SmbCloudAuthError
1630
+
1631
+ public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SmbCloudAuthError {
1632
+ let variant: Int32 = try readInt(&buf)
1633
+ switch variant {
1634
+
1635
+
1636
+
1637
+
1638
+ case 1: return .Api(
1639
+ errorCode: try FfiConverterInt32.read(from: &buf),
1640
+ message: try FfiConverterString.read(from: &buf)
1641
+ )
1642
+
1643
+ default: throw UniffiInternalError.unexpectedEnumCase
1644
+ }
1645
+ }
1646
+
1647
+ public static func write(_ value: SmbCloudAuthError, into buf: inout [UInt8]) {
1648
+ switch value {
1649
+
1650
+
1651
+
1652
+
1653
+
1654
+ case let .Api(errorCode,message):
1655
+ writeInt(&buf, Int32(1))
1656
+ FfiConverterInt32.write(errorCode, into: &buf)
1657
+ FfiConverterString.write(message, into: &buf)
1658
+
1659
+ }
1660
+ }
1661
+}
1662
+
1663
+
1664
+#if swift(>=5.8)
1665
+@_documentation(visibility: private)
1666
+#endif
1667
+public func FfiConverterTypeSmbCloudAuthError_lift(_ buf: RustBuffer) throws -> SmbCloudAuthError {
1668
+ return try FfiConverterTypeSmbCloudAuthError.lift(buf)
1669
+}
1670
+
1671
+#if swift(>=5.8)
1672
+@_documentation(visibility: private)
1673
+#endif
1674
+public func FfiConverterTypeSmbCloudAuthError_lower(_ value: SmbCloudAuthError) -> RustBuffer {
1675
+ return FfiConverterTypeSmbCloudAuthError.lower(value)
1676
+}
1677
+
1678
+
1679
+extension SmbCloudAuthError: Equatable, Hashable {}
1680
+
1681
+
1682
+
1683
+
1684
+extension SmbCloudAuthError: Foundation.LocalizedError {
1685
+ public var errorDescription: String? {
1686
+ String(reflecting: self)
1687
+ }
1688
+}
1689
+
1690
+
1691
+
1692
+
1693
+// Note that we don't yet support `indirect` for enums.
1694
+// See https://github.com/mozilla/uniffi-rs/issues/396 for further discussion.
1695
+
1696
+public enum SmbCloudEnvironment {
1697
+
1698
+ case dev
1699
+ case production
1700
+}
1701
+
1702
+
1703
+#if compiler(>=6)
1704
+extension SmbCloudEnvironment: Sendable {}
1705
+#endif
1706
+
1707
+#if swift(>=5.8)
1708
+@_documentation(visibility: private)
1709
+#endif
1710
+public struct FfiConverterTypeSmbCloudEnvironment: FfiConverterRustBuffer {
1711
+ typealias SwiftType = SmbCloudEnvironment
1712
+
1713
+ public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SmbCloudEnvironment {
1714
+ let variant: Int32 = try readInt(&buf)
1715
+ switch variant {
1716
+
1717
+ case 1: return .dev
1718
+
1719
+ case 2: return .production
1720
+
1721
+ default: throw UniffiInternalError.unexpectedEnumCase
1722
+ }
1723
+ }
1724
+
1725
+ public static func write(_ value: SmbCloudEnvironment, into buf: inout [UInt8]) {
1726
+ switch value {
1727
+
1728
+
1729
+ case .dev:
1730
+ writeInt(&buf, Int32(1))
1731
+
1732
+
1733
+ case .production:
1734
+ writeInt(&buf, Int32(2))
1735
+
1736
+ }
1737
+ }
1738
+}
1739
+
1740
+
1741
+#if swift(>=5.8)
1742
+@_documentation(visibility: private)
1743
+#endif
1744
+public func FfiConverterTypeSmbCloudEnvironment_lift(_ buf: RustBuffer) throws -> SmbCloudEnvironment {
1745
+ return try FfiConverterTypeSmbCloudEnvironment.lift(buf)
1746
+}
1747
+
1748
+#if swift(>=5.8)
1749
+@_documentation(visibility: private)
1750
+#endif
1751
+public func FfiConverterTypeSmbCloudEnvironment_lower(_ value: SmbCloudEnvironment) -> RustBuffer {
1752
+ return FfiConverterTypeSmbCloudEnvironment.lower(value)
1753
+}
1754
+
1755
+
1756
+extension SmbCloudEnvironment: Equatable, Hashable {}
1757
+
1758
+
1759
+
1760
+
1761
+
1762
+
1763
+#if swift(>=5.8)
1764
+@_documentation(visibility: private)
1765
+#endif
1766
+fileprivate struct FfiConverterOptionInt32: FfiConverterRustBuffer {
1767
+ typealias SwiftType = Int32?
1768
+
1769
+ public static func write(_ value: SwiftType, into buf: inout [UInt8]) {
1770
+ guard let value = value else {
1771
+ writeInt(&buf, Int8(0))
1772
+ return
1773
+ }
1774
+ writeInt(&buf, Int8(1))
1775
+ FfiConverterInt32.write(value, into: &buf)
1776
+ }
1777
+
1778
+ public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType {
1779
+ switch try readInt(&buf) as Int8 {
1780
+ case 0: return nil
1781
+ case 1: return try FfiConverterInt32.read(from: &buf)
1782
+ default: throw UniffiInternalError.unexpectedOptionalTag
1783
+ }
1784
+ }
1785
+}
1786
+
1787
+#if swift(>=5.8)
1788
+@_documentation(visibility: private)
1789
+#endif
1790
+fileprivate struct FfiConverterOptionUInt64: FfiConverterRustBuffer {
1791
+ typealias SwiftType = UInt64?
1792
+
1793
+ public static func write(_ value: SwiftType, into buf: inout [UInt8]) {
1794
+ guard let value = value else {
1795
+ writeInt(&buf, Int8(0))
1796
+ return
1797
+ }
1798
+ writeInt(&buf, Int8(1))
1799
+ FfiConverterUInt64.write(value, into: &buf)
1800
+ }
1801
+
1802
+ public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType {
1803
+ switch try readInt(&buf) as Int8 {
1804
+ case 0: return nil
1805
+ case 1: return try FfiConverterUInt64.read(from: &buf)
1806
+ default: throw UniffiInternalError.unexpectedOptionalTag
1807
+ }
1808
+ }
1809
+}
1810
+
1811
+#if swift(>=5.8)
1812
+@_documentation(visibility: private)
1813
+#endif
1814
+fileprivate struct FfiConverterOptionBool: FfiConverterRustBuffer {
1815
+ typealias SwiftType = Bool?
1816
+
1817
+ public static func write(_ value: SwiftType, into buf: inout [UInt8]) {
1818
+ guard let value = value else {
1819
+ writeInt(&buf, Int8(0))
1820
+ return
1821
+ }
1822
+ writeInt(&buf, Int8(1))
1823
+ FfiConverterBool.write(value, into: &buf)
1824
+ }
1825
+
1826
+ public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType {
1827
+ switch try readInt(&buf) as Int8 {
1828
+ case 0: return nil
1829
+ case 1: return try FfiConverterBool.read(from: &buf)
1830
+ default: throw UniffiInternalError.unexpectedOptionalTag
1831
+ }
1832
+ }
1833
+}
1834
+
1835
+#if swift(>=5.8)
1836
+@_documentation(visibility: private)
1837
+#endif
1838
+fileprivate struct FfiConverterOptionString: FfiConverterRustBuffer {
1839
+ typealias SwiftType = String?
1840
+
1841
+ public static func write(_ value: SwiftType, into buf: inout [UInt8]) {
1842
+ guard let value = value else {
1843
+ writeInt(&buf, Int8(0))
1844
+ return
1845
+ }
1846
+ writeInt(&buf, Int8(1))
1847
+ FfiConverterString.write(value, into: &buf)
1848
+ }
1849
+
1850
+ public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> SwiftType {
1851
+ switch try readInt(&buf) as Int8 {
1852
+ case 0: return nil
1853
+ case 1: return try FfiConverterString.read(from: &buf)
1854
+ default: throw UniffiInternalError.unexpectedOptionalTag
1855
+ }
1856
+ }
1857
+}
1858
+private let UNIFFI_RUST_FUTURE_POLL_READY: Int8 = 0
1859
+private let UNIFFI_RUST_FUTURE_POLL_MAYBE_READY: Int8 = 1
1860
+
1861
+fileprivate let uniffiContinuationHandleMap = UniffiHandleMap<UnsafeContinuation<Int8, Never>>()
1862
+
1863
+fileprivate func uniffiRustCallAsync<F, T>(
1864
+ rustFutureFunc: () -> UInt64,
1865
+ pollFunc: (UInt64, @escaping UniffiRustFutureContinuationCallback, UInt64) -> (),
1866
+ completeFunc: (UInt64, UnsafeMutablePointer<RustCallStatus>) -> F,
1867
+ freeFunc: (UInt64) -> (),
1868
+ liftFunc: (F) throws -> T,
1869
+ errorHandler: ((RustBuffer) throws -> Swift.Error)?
1870
+) async throws -> T {
1871
+ // Make sure to call the ensure init function since future creation doesn't have a
1872
+ // RustCallStatus param, so doesn't use makeRustCall()
1873
+ uniffiEnsureSmbcloudAuthInitialized()
1874
+ let rustFuture = rustFutureFunc()
1875
+ defer {
1876
+ freeFunc(rustFuture)
1877
+ }
1878
+ var pollResult: Int8;
1879
+ repeat {
1880
+ pollResult = await withUnsafeContinuation {
1881
+ pollFunc(
1882
+ rustFuture,
1883
+ uniffiFutureContinuationCallback,
1884
+ uniffiContinuationHandleMap.insert(obj: $0)
1885
+ )
1886
+ }
1887
+ } while pollResult != UNIFFI_RUST_FUTURE_POLL_READY
1888
+
1889
+ return try liftFunc(makeRustCall(
1890
+ { completeFunc(rustFuture, $0) },
1891
+ errorHandler: errorHandler
1892
+ ))
1893
+}
1894
+
1895
+// Callback handlers for an async calls. These are invoked by Rust when the future is ready. They
1896
+// lift the return value or error and resume the suspended function.
1897
+fileprivate func uniffiFutureContinuationCallback(handle: UInt64, pollResult: Int8) {
1898
+ if let continuation = try? uniffiContinuationHandleMap.remove(handle: handle) {
1899
+ continuation.resume(returning: pollResult)
1900
+ } else {
1901
+ print("uniffiFutureContinuationCallback invalid handle")
1902
+ }
1903
+}
1904
+
1905
+private enum InitializationResult {
1906
+ case ok
1907
+ case contractVersionMismatch
1908
+ case apiChecksumMismatch
1909
+}
1910
+// Use a global variable to perform the versioning checks. Swift ensures that
1911
+// the code inside is only computed once.
1912
+private let initializationResult: InitializationResult = {
1913
+ // Get the bindings contract version from our ComponentInterface
1914
+ let bindings_contract_version = 29
1915
+ // Get the scaffolding contract version by calling the into the dylib
1916
+ let scaffolding_contract_version = ffi_smbcloud_auth_uniffi_contract_version()
1917
+ if bindings_contract_version != scaffolding_contract_version {
1918
+ return InitializationResult.contractVersionMismatch
1919
+ }
1920
+ if (uniffi_smbcloud_auth_checksum_method_smbcloudauth_build_apple_authorization_request() != 20401) {
1921
+ return InitializationResult.apiChecksumMismatch
1922
+ }
1923
+ if (uniffi_smbcloud_auth_checksum_method_smbcloudauth_build_oidc_authorization_request() != 27410) {
1924
+ return InitializationResult.apiChecksumMismatch
1925
+ }
1926
+ if (uniffi_smbcloud_auth_checksum_method_smbcloudauth_exchange_oidc_code() != 62992) {
1927
+ return InitializationResult.apiChecksumMismatch
1928
+ }
1929
+ if (uniffi_smbcloud_auth_checksum_method_smbcloudauth_get_oidc_userinfo() != 55608) {
1930
+ return InitializationResult.apiChecksumMismatch
1931
+ }
1932
+ if (uniffi_smbcloud_auth_checksum_method_smbcloudauth_login() != 22565) {
1933
+ return InitializationResult.apiChecksumMismatch
1934
+ }
1935
+ if (uniffi_smbcloud_auth_checksum_method_smbcloudauth_logout() != 50854) {
1936
+ return InitializationResult.apiChecksumMismatch
1937
+ }
1938
+ if (uniffi_smbcloud_auth_checksum_method_smbcloudauth_me() != 14252) {
1939
+ return InitializationResult.apiChecksumMismatch
1940
+ }
1941
+ if (uniffi_smbcloud_auth_checksum_method_smbcloudauth_parse_apple_callback_url() != 36073) {
1942
+ return InitializationResult.apiChecksumMismatch
1943
+ }
1944
+ if (uniffi_smbcloud_auth_checksum_method_smbcloudauth_parse_oidc_callback_url() != 50343) {
1945
+ return InitializationResult.apiChecksumMismatch
1946
+ }
1947
+ if (uniffi_smbcloud_auth_checksum_method_smbcloudauth_remove_account() != 59938) {
1948
+ return InitializationResult.apiChecksumMismatch
1949
+ }
1950
+ if (uniffi_smbcloud_auth_checksum_method_smbcloudauth_signup() != 1373) {
1951
+ return InitializationResult.apiChecksumMismatch
1952
+ }
1953
+ if (uniffi_smbcloud_auth_checksum_constructor_smbcloudauth_new() != 47975) {
1954
+ return InitializationResult.apiChecksumMismatch
1955
+ }
1956
+
1957
+ return InitializationResult.ok
1958
+}()
1959
+
1960
+// Make the ensure init function public so that other modules which have external type references to
1961
+// our types can call it.
1962
+public func uniffiEnsureSmbcloudAuthInitialized() {
1963
+ switch initializationResult {
1964
+ case .ok:
1965
+ break
1966
+ case .contractVersionMismatch:
1967
+ fatalError("UniFFI contract version mismatch: try cleaning and rebuilding your project")
1968
+ case .apiChecksumMismatch:
1969
+ fatalError("UniFFI API checksum mismatch: try cleaning and rebuilding your project")
1970
+ }
1971
+}
1972
+
1973
+// swiftlint:enable all
\ No newline at end of file