Skip to content

Commit b1b3d8e

Browse files
Merge remote-tracking branch 'origin/master' into release
2 parents 6872294 + 4dc7920 commit b1b3d8e

File tree

396 files changed

+22654
-6675
lines changed

Some content is hidden

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

396 files changed

+22654
-6675
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 = '22.2'
3+
s.version = '22.3'
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/AcceptAllRevisionsOnline.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ let fileName = "test_doc.docx";
66
let requestDocument = InputStream(url: URL(string: fileName))!;
77
let request = AcceptAllRevisionsOnlineRequest(document: requestDocument);
88
let acceptAllRevisionsOnlineResult = try api.acceptAllRevisionsOnline(request: request);
9-
try acceptAllRevisionsOnlineResult.getDocument()?.write(to: currentDir!.appendingPathComponent("test_result.docx", isDirectory: false));
9+
try acceptAllRevisionsOnlineResult.getDocument()?.first?.value.write(to: currentDir!.appendingPathComponent("test_result.docx", isDirectory: false));

README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ 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 22.3
17+
18+
- Online methods returns the dictionary of files with included original filename as key instead of single file content in responses.
19+
- Parameters contained sensitive data should be passed in encrypted form. Names of the parameters have 'encrypted' prefix.
20+
- Added Encrypt method to encrypt data on the API public key. Use it to prepare values for parameters required encrypted data.
21+
- GetPublicKey method is not billable.
22+
- Changed type of enumerations for members of SaveOptionsData and other inherited classes from string to enum.
23+
24+
1625
## Enhancements in Version 22.2
1726

1827
- Made 'SaveOprionsData.SaveFormat' property readonly with default value.
@@ -189,7 +198,7 @@ Add link to this repository as dependency to your Package.swift:
189198

190199
dependencies: [
191200
// Dependencies declare other packages that this package depends on.
192-
.package(url: "https://github.com/aspose-words-cloud/aspose-words-cloud-swift", from: "22.2"),
201+
.package(url: "https://github.com/aspose-words-cloud/aspose-words-cloud-swift", from: "22.3"),
193202
],
194203
targets: [
195204
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
@@ -207,7 +216,7 @@ targets: [
207216
Add link to git repository as dependency to your Podfile:
208217

209218
```ruby
210-
pod 'AsposeWordsCloud', :git => 'https://github.com/aspose-words-cloud/aspose-words-cloud-swift.git', :tag => '22.2'
219+
pod 'AsposeWordsCloud', :git => 'https://github.com/aspose-words-cloud/aspose-words-cloud-swift.git', :tag => '22.3'
211220
```
212221

213222
## Getting Started

Sources/AsposeWordsCloud/Api/ApiInvoker.swift

Lines changed: 24 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,10 @@ public class ApiInvoker {
3333
// An object containing the configuration for executing API requests
3434
private let configuration : Configuration;
3535

36-
// RSA key for password encryption
3736
#if os(Linux)
3837
// Encryption of passwords in query params not supported on linux
3938
#else
40-
private var encryptionKey : SecKey?;
39+
private let encryptor : Encryptor;
4140
#endif
4241

4342
// Cached value of oauth2 authorization tokeт.
@@ -56,26 +55,31 @@ public class ApiInvoker {
5655
private let httpStatusCodeTimeout = 408;
5756

5857
// Initialize ApiInvoker object with specific configuration
58+
#if os(Linux)
5959
public init(configuration : Configuration) {
6060
self.configuration = configuration;
6161
self.mutex = NSLock();
6262
self.accessTokenCache = nil;
63-
64-
#if os(Linux)
65-
// Encryption of passwords in query params not supported on linux
63+
}
6664
#else
67-
self.encryptionKey = nil;
68-
#endif
65+
public init(configuration : Configuration, encryptor: Encryptor) {
66+
self.configuration = configuration;
67+
self.mutex = NSLock();
68+
self.accessTokenCache = nil;
69+
this.encryptor = encryptor;
6970
}
71+
#endif
7072

7173
// Internal class for represent API response
7274
private class InvokeResponse {
7375
public var data : Data?;
76+
public var headers : [String : String];
7477
public var errorCode : Int;
7578
public var errorMessage : String?;
7679

7780
public init(errorCode : Int) {
7881
self.errorCode = errorCode;
82+
self.headers = [String : String]();
7983
}
8084
}
8185

@@ -85,7 +89,7 @@ public class ApiInvoker {
8589
}
8690

8791
// Invoke request to the API with the specified set of arguments and execute callback after the request is completed
88-
public func invoke(apiRequestData : WordsApiRequestData, callback: @escaping (_ response: Data?, _ error: Error?) -> ()
92+
public func invoke(apiRequestData : WordsApiRequestData, callback: @escaping (_ response: Data?, _ headers: [String: String], _ error: Error?) -> ()
8993
) {
9094
// Create URL request object
9195
var request = URLRequest(url: apiRequestData.getURL());
@@ -115,29 +119,29 @@ public class ApiInvoker {
115119
self.invokeRequest(urlRequest: &request, accessToken: accessToken, callback: { response in
116120
if (response.errorCode == self.httpStatusCodeOK) {
117121
// Api request success
118-
callback(response.data, nil);
122+
callback(response.data, response.headers, nil);
119123
}
120124
else {
121-
callback(nil, WordsApiError.requestError(errorCode: response.errorCode, message: response.errorMessage));
125+
callback(nil, [String : String](), WordsApiError.requestError(errorCode: response.errorCode, message: response.errorMessage));
122126
}
123127
});
124128
}
125129
else {
126-
callback(nil, WordsApiError.requestError(errorCode: statusCode, message: "Authorization failed."));
130+
callback(nil, [String : String](), WordsApiError.requestError(errorCode: statusCode, message: "Authorization failed."));
127131
}
128132
});
129133
}
130134
else if (response.errorCode == self.httpStatusCodeOK) {
131135
// Api request success
132-
callback(response.data, nil);
136+
callback(response.data, response.headers, nil);
133137
}
134138
else {
135-
callback(nil, WordsApiError.requestError(errorCode: response.errorCode, message: response.errorMessage));
139+
callback(nil, [String : String](), WordsApiError.requestError(errorCode: response.errorCode, message: response.errorMessage));
136140
}
137141
});
138142
}
139143
else {
140-
callback(nil, WordsApiError.requestError(errorCode: statusCode, message: "Authorization failed."));
144+
callback(nil, [String : String](), WordsApiError.requestError(errorCode: statusCode, message: "Authorization failed."));
141145
}
142146
});
143147
}
@@ -189,6 +193,9 @@ public class ApiInvoker {
189193
if (rawResponse != nil) {
190194
invokeResponse.errorCode = rawResponse!.statusCode;
191195
invokeResponse.errorMessage = rawResponse!.description;
196+
for header in rawResponse!.allHeaderFields {
197+
invokeResponse.headers[String(describing: header.key)] = String(describing: header.value);
198+
}
192199
}
193200
else {
194201
invokeResponse.errorCode = self.httpStatusCodeBadRequest;
@@ -296,65 +303,11 @@ public class ApiInvoker {
296303
return lengthField;
297304
}
298305

299-
public func setEncryptionData(data : PublicKeyResponse) throws {
300306
#if os(Linux)
301-
// Encryption of passwords in query params not supported on linux
302-
#else
303-
let exponent = Data(base64Encoded: data.getExponent()!)!;
304-
let modulus = Data(base64Encoded: data.getModulus()!)!;
305-
let exponentBytes = [UInt8](exponent);
306-
var modulusBytes = [UInt8](modulus);
307-
modulusBytes.insert(0x00, at: 0);
308-
309-
var modulusEncoded: [UInt8] = [];
310-
modulusEncoded.append(0x02);
311-
modulusEncoded.append(contentsOf: lengthField(of: modulusBytes));
312-
modulusEncoded.append(contentsOf: modulusBytes);
313-
314-
var exponentEncoded: [UInt8] = [];
315-
exponentEncoded.append(0x02);
316-
exponentEncoded.append(contentsOf: lengthField(of: exponentBytes));
317-
exponentEncoded.append(contentsOf: exponentBytes);
318-
319-
var sequenceEncoded: [UInt8] = [];
320-
sequenceEncoded.append(0x30);
321-
sequenceEncoded.append(contentsOf: lengthField(of: (modulusEncoded + exponentEncoded)));
322-
sequenceEncoded.append(contentsOf: (modulusEncoded + exponentEncoded));
323-
324-
let keyData = Data(bytes: sequenceEncoded);
325-
let keySize = (modulusBytes.count * 8);
326-
327-
let attributes: [String: Any] = [
328-
kSecAttrKeyType as String: kSecAttrKeyTypeRSA,
329-
kSecAttrKeyClass as String: kSecAttrKeyClassPublic,
330-
kSecAttrKeySizeInBits as String: keySize
331-
];
332-
333-
encryptionKey = SecKeyCreateWithData(keyData as CFData, attributes as CFDictionary, nil);
334-
#endif
335-
}
336-
337-
public func encryptString(value : String) throws -> String {
338-
#if os(Linux)
339-
// Encryption of passwords in query params not supported on linux
340-
return value;
307+
// Encryption of passwords in query params not supported on linux
341308
#else
342-
let buffer = value.data(using: .utf8)!;
343-
var error: Unmanaged<CFError>? = nil;
344-
345-
// Encrypto should less than key length
346-
let secData = SecKeyCreateEncryptedData(encryptionKey!, .rsaEncryptionPKCS1, buffer as CFData, &error)!;
347-
var secBuffer = [UInt8](repeating: 0, count: CFDataGetLength(secData));
348-
CFDataGetBytes(secData, CFRangeMake(0, CFDataGetLength(secData)), &secBuffer);
349-
return Data(bytes: secBuffer).base64EncodedString().replacingOccurrences(of: "+", with: "%2B").replacingOccurrences(of: "/", with: "%2F");
350-
#endif
309+
public func encryptString(data : String) throws -> String {
310+
return encryptor.encrypt(data);
351311
}
352-
353-
public func isEncryptionAllowed() -> Bool {
354-
#if os(Linux)
355-
return false;
356-
#else
357-
return true;
358312
#endif
359-
}
360313
}

Sources/AsposeWordsCloud/Api/Configuration.swift

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,23 +45,52 @@ public class Configuration : Codable {
4545
// Specify request timeout
4646
private var timeout: TimeInterval;
4747

48+
#if os(Linux)
49+
// Encryption of passwords in query params not supported on linux
50+
#else
51+
// Specify RSA exponent
52+
private var rsaExponent: String;
53+
54+
// Specify RSA modulus
55+
private var rsaModulus: String;
56+
#endif
57+
58+
4859
private enum CodingKeys: String, CodingKey {
4960
case baseUrl = "BaseUrl";
5061
case clientId = "ClientId";
5162
case clientSecret = "ClientSecret";
5263
case debugMode = "DebugMode";
5364
case timeout = "Timeout";
65+
#if os(Linux)
66+
// Encryption of passwords in query params not supported on linux
67+
#else
68+
case rsaExponent = "RsaExponent";
69+
case rsaModulus = "RsaModulus";
70+
#endif
5471
case invalidCodingKey;
5572
}
5673

5774
// Initialize new instance of Aspose.Words for Cloud configuration object with given parameters
75+
#if os(Linux)
5876
public init(clientId: String, clientSecret: String, baseUrl: String = "https://api.aspose.cloud", debugMode: Bool = false, timeout: TimeInterval = 300) {
5977
self.clientId = clientId;
6078
self.clientSecret = clientSecret;
6179
self.baseUrl = baseUrl;
6280
self.debugMode = debugMode;
6381
self.timeout = timeout;
82+
}
83+
#else
84+
public init(clientId: String, clientSecret: String, baseUrl: String = "https://api.aspose.cloud", debugMode: Bool = false, timeout: TimeInterval = 300, rsaExponent: String = nil, rsaModulus: String = nil) {
85+
self.clientId = clientId;
86+
self.clientSecret = clientSecret;
87+
self.baseUrl = baseUrl;
88+
self.debugMode = debugMode;
89+
self.timeout = timeout;
90+
self.rsaExponent = rsaExponent;
91+
self.rsaModulus = rsaModulus;
6492
}
93+
#endif
6594

6695
public required init(from decoder: Decoder) throws {
6796
let container = try decoder.container(keyedBy: CodingKeys.self);
@@ -70,6 +99,12 @@ public class Configuration : Codable {
7099
self.clientSecret = try container.decode(String.self, forKey: .clientSecret);
71100
self.debugMode = try container.decodeIfPresent(Bool.self, forKey: .debugMode);
72101
self.timeout = try container.decodeIfPresent(TimeInterval.self, forKey: .timeout) ?? 300;
102+
#if os(Linux)
103+
// Encryption of passwords in query params not supported on linux
104+
#else
105+
self.rsaExponent = try container.decodeIfPresent(String.self, forKey: .rsaExponent) ?? nil;
106+
self.rsaModulus = try container.decodeIfPresent(String.self, forKey: .rsaModulus) ?? nil;
107+
#endif
73108
}
74109

75110
public func encode(to encoder: Encoder) throws {
@@ -81,6 +116,16 @@ public class Configuration : Codable {
81116
try container.encode(self.debugMode, forKey: .debugMode);
82117
}
83118
try container.encode(self.timeout, forKey: .timeout);
119+
#if os(Linux)
120+
// Encryption of passwords in query params not supported on linux
121+
#else
122+
if (self.rsaExponent != nil) {
123+
try container.encode(self.rsaExponent, forKey: .rsaExponent);
124+
}
125+
if (self.rsaModulus != nil) {
126+
try container.encode(self.rsaModulus, forKey: .rsaModulus);
127+
}
128+
#endif
84129
}
85130

86131
// Returns Aspose.Words for Cloud base URL
@@ -108,6 +153,19 @@ public class Configuration : Codable {
108153
return self.timeout;
109154
}
110155

156+
#if os(Linux)
157+
#else
158+
// Returns RSA exponent
159+
public func getRsaExponent() -> String {
160+
return self.rsaExponent;
161+
}
162+
163+
// Returns RSA modulus
164+
public func getRsaModulus() -> String {
165+
return self.rsaModulus;
166+
}
167+
#endif
168+
111169
// Returns general version of cloud api
112170
public func getApiVersion() -> String {
113171
return "v4.0";
@@ -130,6 +188,6 @@ public class Configuration : Codable {
130188

131189
// Returns SDK version for using in statistics headers
132190
public func getSdkVersion() -> String {
133-
return "22.2";
191+
return "22.3";
134192
}
135193
}

0 commit comments

Comments
 (0)