Skip to content

Commit 1582889

Browse files
Merge remote-tracking branch 'origin/master' into release
2 parents 5b05602 + 7c38df2 commit 1582889

File tree

681 files changed

+3137
-4041
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

681 files changed

+3137
-4041
lines changed

AsposeWordsCloud.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'AsposeWordsCloud'
3-
s.version = '21.9'
3+
s.version = '21.10'
44
s.summary = 'Aspose Words for Cloud.'
55
s.homepage = 'https://github.com/aspose-words-cloud/aspose-words-cloud-swift.git'
66
s.license = { :type => 'MIT', :file => 'LICENSE' }

Examples/AcceptAllRevisions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import AsposeWordsCloud
22

33
let config = Configuration(clientId: "####-####-####-####-####", clientSecret: "##################");
4-
let api = WordsAPI(configuration: config);
4+
let api = try WordsAPI(configuration: config);
55
let fileName = "test_doc.docx";
66

77
// Upload original document to cloud storage.

Examples/AcceptAllRevisionsOnline.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
let config = Configuration(clientId: "####-####-####-####-####", clientSecret: "##################");
2-
let api = WordsAPI(configuration: config);
2+
let api = try WordsAPI(configuration: config);
33
let fileName = "test_doc.docx";
44

55
// Calls AcceptAllRevisionsOnline method for document in cloud.

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ let package = Package(
1313
],
1414
dependencies: [
1515
// Dependencies declare other packages that this package depends on.
16-
.package(url: "https://github.com/allegro/swift-junit.git", from: "1.0.0"),
16+
.package(url: "https://github.com/allegro/swift-junit.git", from: "1.0.0")
1717
],
1818
targets: [
1919
// Targets are the basic building blocks of a package. A target can define a module or a test suite.

README.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ This repository contains Aspose.Words Cloud SDK for Swift source code. This SDK
1313
* Watermarks and protection
1414
* Full read & write access to Document Object Model, including sections, paragraphs, text, images, tables, headers/footers and many others
1515

16+
## Enhancements in Version 21.10
17+
18+
- Removed 'GraphicsQualityOptions' image save option as it no longer supported.
19+
- Added query parameter 'displayIntermediateResults' for batch requests. If 'false', the last response in batch will be returned only. Default is 'true'
20+
- Added 'JsonDataLoadOptions' and 'XmlDataLoadOptions' to 'ReportEngineSettings'
21+
22+
1623
## Enhancements in Version 21.8
1724

1825
- Added new api methods to get, insert, update or delete custom xml parts from documents.
@@ -158,7 +165,7 @@ Add link to this repository as dependency to your Package.swift:
158165

159166
dependencies: [
160167
// Dependencies declare other packages that this package depends on.
161-
.package(url: "https://github.com/aspose-words-cloud/aspose-words-cloud-swift", from: "21.9"),
168+
.package(url: "https://github.com/aspose-words-cloud/aspose-words-cloud-swift", from: "21.10"),
162169
],
163170
targets: [
164171
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
@@ -176,7 +183,7 @@ targets: [
176183
Add link to git repository as dependency to your Podfile:
177184

178185
```ruby
179-
pod 'AsposeWordsCloud', :git => 'https://github.com/aspose-words-cloud/aspose-words-cloud-swift.git', :tag => '21.9'
186+
pod 'AsposeWordsCloud', :git => 'https://github.com/aspose-words-cloud/aspose-words-cloud-swift.git', :tag => '21.10'
180187
```
181188

182189
## Getting Started
@@ -186,7 +193,7 @@ pod 'AsposeWordsCloud', :git => 'https://github.com/aspose-words-cloud/aspose-wo
186193
import Foundation;
187194
import AsposeWordsCloud;
188195

189-
let wordsApi = WordsAPI(clientId: "YOUR_APP_SID", clientSecret: "YOUR_APP_KEY");
196+
let wordsApi = try WordsAPI(clientId: "YOUR_APP_SID", clientSecret: "YOUR_APP_KEY");
190197
let fileName = "TestCreateDocument.doc";
191198
let request = CreateDocumentRequest(fileName: fileName);
192199
let response = try wordsApi.createDocument(request: request);

Sources/AsposeWordsCloud/Api/ApiInvoker.swift

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,18 @@
2828
import Foundation
2929

3030
// Utility class for executing and processing requests to Cloud API
31+
@available(macOS 10.12, iOS 10.3, watchOS 3.3, tvOS 12.0, *)
3132
public class ApiInvoker {
3233
// An object containing the configuration for executing API requests
3334
private let configuration : Configuration;
3435

36+
// RSA key for password encryption
37+
#if os(Linux)
38+
// Encryption of passwords in query params not supported on linux
39+
#else
40+
private var encryptionKey : SecKey?;
41+
#endif
42+
3543
// Cached value of oauth2 authorization tokeт.
3644
// It is filled after the first call to the API.
3745
// Mutex is used to synchronize updates in a multi-threaded environment.
@@ -52,6 +60,12 @@ public class ApiInvoker {
5260
self.configuration = configuration;
5361
self.mutex = NSLock();
5462
self.accessTokenCache = nil;
63+
64+
#if os(Linux)
65+
// Encryption of passwords in query params not supported on linux
66+
#else
67+
self.encryptionKey = nil;
68+
#endif
5569
}
5670

5771
// Internal class for represent API response
@@ -250,4 +264,95 @@ public class ApiInvoker {
250264
callback(accessToken, self.httpStatusCodeOK);
251265
}
252266
}
267+
268+
private func lengthField(of valueField: [UInt8]) -> [UInt8] {
269+
var count = valueField.count;
270+
271+
if (count < 128) {
272+
return [ UInt8(count) ];
273+
}
274+
275+
// The number of bytes needed to encode count.
276+
let lengthBytesCount = Int((log2(Double(count)) / 8) + 1);
277+
278+
// The first byte in the length field encoding the number of remaining bytes.
279+
let firstLengthFieldByte = UInt8(128 + lengthBytesCount);
280+
281+
var lengthField: [UInt8] = []
282+
for _ in 0..<lengthBytesCount {
283+
// Take the last 8 bits of count.
284+
let lengthByte = UInt8(count & 0xff);
285+
// Add them to the length field.
286+
lengthField.insert(lengthByte, at: 0);
287+
// Delete the last 8 bits of count.
288+
count = count >> 8;
289+
}
290+
291+
// Include the first byte.
292+
lengthField.insert(firstLengthFieldByte, at: 0);
293+
294+
return lengthField;
295+
}
296+
297+
public func setEncryptionData(data : PublicKeyResponse) throws {
298+
#if os(Linux)
299+
// Encryption of passwords in query params not supported on linux
300+
#else
301+
let exponent = Data(base64Encoded: data.getExponent()!)!;
302+
let modulus = Data(base64Encoded: data.getModulus()!)!;
303+
let exponentBytes = [UInt8](exponent);
304+
var modulusBytes = [UInt8](modulus);
305+
modulusBytes.insert(0x00, at: 0);
306+
307+
var modulusEncoded: [UInt8] = [];
308+
modulusEncoded.append(0x02);
309+
modulusEncoded.append(contentsOf: lengthField(of: modulusBytes));
310+
modulusEncoded.append(contentsOf: modulusBytes);
311+
312+
var exponentEncoded: [UInt8] = [];
313+
exponentEncoded.append(0x02);
314+
exponentEncoded.append(contentsOf: lengthField(of: exponentBytes));
315+
exponentEncoded.append(contentsOf: exponentBytes);
316+
317+
var sequenceEncoded: [UInt8] = [];
318+
sequenceEncoded.append(0x30);
319+
sequenceEncoded.append(contentsOf: lengthField(of: (modulusEncoded + exponentEncoded)));
320+
sequenceEncoded.append(contentsOf: (modulusEncoded + exponentEncoded));
321+
322+
let keyData = Data(bytes: sequenceEncoded);
323+
let keySize = (modulusBytes.count * 8);
324+
325+
let attributes: [String: Any] = [
326+
kSecAttrKeyType as String: kSecAttrKeyTypeRSA,
327+
kSecAttrKeyClass as String: kSecAttrKeyClassPublic,
328+
kSecAttrKeySizeInBits as String: keySize
329+
];
330+
331+
encryptionKey = SecKeyCreateWithData(keyData as CFData, attributes as CFDictionary, nil);
332+
#endif
333+
}
334+
335+
public func encryptString(value : String) throws -> String {
336+
#if os(Linux)
337+
// Encryption of passwords in query params not supported on linux
338+
return value;
339+
#else
340+
let buffer = value.data(using: .utf8)!;
341+
var error: Unmanaged<CFError>? = nil;
342+
343+
// Encrypto should less than key length
344+
let secData = SecKeyCreateEncryptedData(encryptionKey!, .rsaEncryptionPKCS1, buffer as CFData, &error)!;
345+
var secBuffer = [UInt8](repeating: 0, count: CFDataGetLength(secData));
346+
CFDataGetBytes(secData, CFRangeMake(0, CFDataGetLength(secData)), &secBuffer);
347+
return Data(bytes: secBuffer).base64EncodedString().replacingOccurrences(of: "+", with: "%2B").replacingOccurrences(of: "/", with: "%2F");
348+
#endif
349+
}
350+
351+
public func isEncryptionAllowed() -> Bool {
352+
#if os(Linux)
353+
return false;
354+
#else
355+
return true;
356+
#endif
357+
}
253358
}

Sources/AsposeWordsCloud/Api/BatchRequest.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import Foundation
2929

3030
// General protocol for all models.
31+
@available(macOS 10.12, iOS 10.3, watchOS 3.3, tvOS 12.0, *)
3132
public struct BatchRequest {
3233
private var requestId : String;
3334
private var dependsOn : String;
@@ -55,8 +56,8 @@ public struct BatchRequest {
5556
return InputStream(data: ("ResultOf(" + self.requestId + ")").data(using: .utf8)!);
5657
}
5758

58-
public func createApiRequestData(configuration : Configuration) throws -> WordsApiRequestData {
59-
var result = try request.createApiRequestData(configuration: configuration);
59+
public func createApiRequestData(apiInvoker : ApiInvoker, configuration : Configuration) throws -> WordsApiRequestData {
60+
var result = try request.createApiRequestData(apiInvoker: apiInvoker, configuration: configuration);
6061
result.addHeader(key: "RequestId", value: self.requestId);
6162
if (!self.dependsOn.isEmpty) {
6263
result.addHeader(key: "DependsOn", value: self.dependsOn);

Sources/AsposeWordsCloud/Api/Configuration.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import Foundation
2929

3030
// Represents a set of configuration settings
31+
@available(macOS 10.12, iOS 10.3, watchOS 3.3, tvOS 12.0, *)
3132
public class Configuration : Codable {
3233
// Aspose.Words for Cloud base URL
3334
private var baseUrl : String;
@@ -117,6 +118,6 @@ public class Configuration : Codable {
117118

118119
// Returns SDK version for using in statistics headers
119120
public func getSdkVersion() -> String {
120-
return "21.9";
121+
return "21.10";
121122
}
122123
}

Sources/AsposeWordsCloud/Api/ObjectSerializer.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import Foundation
2929

3030
// Helper class for serialize or deserialize swift objects to string or binary format.
31+
@available(macOS 10.12, iOS 10.3, watchOS 3.3, tvOS 12.0, *)
3132
class ObjectSerializer {
3233
private init() { }
3334

Sources/AsposeWordsCloud/Api/RequestFormParam.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import Foundation
2929

3030
// Represent struct for using as form param in request
31+
@available(macOS 10.12, iOS 10.3, watchOS 3.3, tvOS 12.0, *)
3132
public struct RequestFormParam {
3233
private let name : String?;
3334
private let body : Data;

0 commit comments

Comments
 (0)