CryptomatorCloudAccess 0.11.1

CryptomatorCloudAccess 0.11.1

Sebastian StenzelTobias HagemannCryptobotPhilipp Schmid 维护。



  • Philipp Schmid、Sebastian Stenzel 和 Tobias Hagemann 编写

Swift Compatibility Platform Compatibility Version Codacy Code Quality Codacy Coverage

Cloud Access Swift

该库定义了 Cryptomator 在 iOS 上使用的云访问 API。

每个云实现一次 API。它还构成了适用于各种保险库格式的装饰层的基石,从而可以在云存储的保险库上获得明文视图。

要求

  • iOS 9.0 或更高版本
  • macOS 10.12 或更高版本

安装

Swift 包管理器

您可以使用 Swift 包管理器

.package(url: "https://github.com/cryptomator/cloud-access-swift.git", .upToNextMinor(from: "1.0.0"))

CocoaPods

您可以使用 CocoaPods

pod 'CryptomatorCloudAccess', '~> 1.0.0'

使用方法

核心库

核心库包含几个协议、结构和枚举,构建了这个库的基础。异步调用使用了Promises库。 CloudProvider是定义云访问的主要协议。

func fetchItemMetadata(at cloudPath: CloudPath) -> Promise<CloudItemMetadata>
func fetchItemList(forFolderAt cloudPath: CloudPath, withPageToken pageToken: String?) -> Promise<CloudItemList>
func downloadFile(from cloudPath: CloudPath, to localURL: URL) -> Promise<Void>
func uploadFile(from localURL: URL, to cloudPath: CloudPath, replaceExisting: Bool) -> Promise<CloudItemMetadata>
func createFolder(at cloudPath: CloudPath) -> Promise<Void>
func deleteFile(at cloudPath: CloudPath) -> Promise<Void>
func deleteFolder(at cloudPath: CloudPath) -> Promise<Void>
func moveFile(from sourceCloudPath: CloudPath, to targetCloudPath: CloudPath) -> Promise<Void>
func moveFolder(from sourceCloudPath: CloudPath, to targetCloudPath: CloudPath) -> Promise<Void>

加密

加密和缩短装饰器允许基于Cryptomator加密方案的透明访问。它依赖于cryptolib-swift进行加密功能和GRDB进行线程安全的缓存。有关Cryptomator加密方案的信息,请访问docs.cryptomator.org的安全性架构页面。

为了创建加密装饰器提供者,您需要从cryptolib-swift中获得一个Cryptor实例。查看如何创建解密器的文档。并且为了完全兼容,您需要将缩短装饰器放在其中。

let provider = ... // any other cloud provider
let vaultPath = ...
...
let cryptor = ...
let shorteningDecorator = try VaultFormat7ShorteningProviderDecorator(delegate: provider, vaultPath: vaultPath)
let cryptoDecorator = try VaultFormat7ProviderDecorator(delegate: shorteningDecorator, vaultPath: vaultPath, cryptor: cryptor)

⚠️您必须检查您的MasterkeyFile实例的版本,以便创建正确的装饰器。此库支持版本6及以上的保险箱。

本地文件系统

由于本地文件系统实际上不是云,因此命名可能有些混淆。尽管此库致力于提供对许多云存储服务的访问,但访问本地文件系统仍然可能很有用。

使用根URL创建本地文件系统提供者

let rootURL = ... // rootURL.isFileURL must be `true`
let provider = LocalFileSystemProvider(rootURL: rootURL)

当调用此提供者的函数时,应提供相对于根URL的云路径。

此提供者使用NSFileCoordinator进行其操作并支持异步访问。

WebDAV

使用WebDAV客户端创建WebDAV提供程序

let baseURL = ...
let username = ...
let password = ...
let allowedCertificate = ... // optional: you might want to allowlist a TLS certificate
let identifier = ... // optional: you might want to give this credential an identifier, defaults to a random UUID
let credential = WebDAVCredential(baseURL: baseURL, username: username, password: password, allowedCertificate: allowedCertificate, identifier: identifier)
let sharedContainerIdentifier = ... // if `useBackgroundSession` is `true`, this will be set internally for the `URLSessionConfiguration`
let useBackgroundSession = ... // if `true`, the internal `URLSessionConfiguration` will be based on a background configuration
let client = WebDAVClient(credential: credential, sharedContainerIdentifier: sharedContainerIdentifier, useBackgroundSession: useBackgroundSession)
let provider = WebDAVProvider(with: client)

从理论上讲,您可以无需进一步检查就使用提供程序。然而,您应该使用WebDAV认证器验证WebDAV客户端及其凭据。

let client = ...
WebDAVAuthenticator.verifyClient(client: client).then {
  // client validation successful
}.catch { error in
  // error handling
}

此外,要允许证书,您可以使用TLS证书验证器。

let baseURL = ...
let validator = TLSCertificateValidator(baseURL: baseURL)
validator.validate().then { certificate in
  // certificate of type `TLSCertificate` contains several properties for further handling
}.catch { error in
  // error handling
}

为Cloud Access Swift做出贡献

如果您想报告错误、提问或有编码方面的帮助,请阅读我们的贡献指南

行为准则

帮助我们保持Cryptomator的开源和包容性。请阅读并遵循我们的行为准则

许可

根据AGPLv3分发。有关更多信息,请参阅LICENSE文件。