aboutsummaryrefslogtreecommitdiff
path: root/xcode/OLMKit/OLMOutboundGroupSession.m
diff options
context:
space:
mode:
authormanuroe <manu@matrix.org>2016-11-14 16:54:51 +0100
committermanuroe <manu@matrix.org>2016-11-14 16:54:51 +0100
commitcf66af6f2e7c69a3e0712317f8473ab09711d426 (patch)
tree425ad41ff31014973628daa8054772939e53edcd /xcode/OLMKit/OLMOutboundGroupSession.m
parent27a8c28da4e5c62d8863ee3d30642109d713c4d6 (diff)
OLMKit: Replaced NSAsserts by NSErrors
Diffstat (limited to 'xcode/OLMKit/OLMOutboundGroupSession.m')
-rw-r--r--xcode/OLMKit/OLMOutboundGroupSession.m29
1 files changed, 20 insertions, 9 deletions
diff --git a/xcode/OLMKit/OLMOutboundGroupSession.m b/xcode/OLMKit/OLMOutboundGroupSession.m
index c86fa9f..9741db1 100644
--- a/xcode/OLMKit/OLMOutboundGroupSession.m
+++ b/xcode/OLMKit/OLMOutboundGroupSession.m
@@ -56,7 +56,7 @@
size_t result = olm_init_outbound_group_session(session, random.mutableBytes, random.length);
if (result == olm_error()) {
const char *error = olm_outbound_group_session_last_error(session);
- NSAssert(NO, @"olm_init_outbound_group_session error: %s", error);
+ NSLog(@"olm_init_outbound_group_session error: %s", error);
return nil;
}
}
@@ -72,7 +72,7 @@
size_t result = olm_outbound_group_session_id(session, idData.mutableBytes, idData.length);
if (result == olm_error()) {
const char *error = olm_outbound_group_session_last_error(session);
- NSAssert(NO, @"olm_outbound_group_session_id error: %s", error);
+ NSLog(@"olm_outbound_group_session_id error: %s", error);
return nil;
}
NSString *idString = [[NSString alloc] initWithData:idData encoding:NSUTF8StringEncoding];
@@ -92,14 +92,14 @@
size_t result = olm_outbound_group_session_key(session, sessionKeyData.mutableBytes, sessionKeyData.length);
if (result == olm_error()) {
const char *error = olm_outbound_group_session_last_error(session);
- NSAssert(NO, @"olm_outbound_group_session_key error: %s", error);
+ NSLog(@"olm_outbound_group_session_key error: %s", error);
return nil;
}
NSString *sessionKey = [[NSString alloc] initWithData:sessionKeyData encoding:NSUTF8StringEncoding];
return sessionKey;
}
-- (NSString *)encryptMessage:(NSString *)message {
+- (NSString *)encryptMessage:(NSString *)message error:(NSError**)error {
NSData *plaintextData = [message dataUsingEncoding:NSUTF8StringEncoding];
size_t ciphertextLength = olm_group_encrypt_message_length(session, plaintextData.length);
NSMutableData *ciphertext = [NSMutableData dataWithLength:ciphertextLength];
@@ -108,8 +108,19 @@
}
size_t result = olm_group_encrypt(session, plaintextData.bytes, plaintextData.length, ciphertext.mutableBytes, ciphertext.length);
if (result == olm_error()) {
- const char *error = olm_outbound_group_session_last_error(session);
- NSAssert(NO, @"olm_group_encrypt error: %s", error);
+ const char *olm_error = olm_outbound_group_session_last_error(session);
+
+ NSString *errorString = [NSString stringWithUTF8String:olm_error];
+ NSLog(@"olm_group_encrypt error: %@", errorString);
+
+ if (error && olm_error && errorString) {
+ *error = [NSError errorWithDomain:OLMErrorDomain
+ code:0
+ userInfo:@{
+ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"olm_group_encrypt error: %@", errorString]
+ }];
+ }
+
return nil;
}
return [[NSString alloc] initWithData:ciphertext encoding:NSUTF8StringEncoding];
@@ -127,7 +138,7 @@
NSParameterAssert(serializedData.length > 0);
if (key.length == 0 || serializedData.length == 0) {
if (error) {
- *error = [NSError errorWithDomain:@"org.matrix.olm" code:0 userInfo:@{NSLocalizedDescriptionKey: @"Bad length."}];
+ *error = [NSError errorWithDomain:OLMErrorDomain code:0 userInfo:@{NSLocalizedDescriptionKey: @"Bad length."}];
}
return nil;
}
@@ -137,7 +148,7 @@
const char *olm_error = olm_outbound_group_session_last_error(session);
NSString *errorString = [NSString stringWithUTF8String:olm_error];
if (error && errorString) {
- *error = [NSError errorWithDomain:@"org.matrix.olm" code:0 userInfo:@{NSLocalizedDescriptionKey: errorString}];
+ *error = [NSError errorWithDomain:OLMErrorDomain code:0 userInfo:@{NSLocalizedDescriptionKey: errorString}];
}
return nil;
}
@@ -154,7 +165,7 @@
const char *olm_error = olm_outbound_group_session_last_error(session);
NSString *errorString = [NSString stringWithUTF8String:olm_error];
if (error && errorString) {
- *error = [NSError errorWithDomain:@"org.matrix.olm" code:0 userInfo:@{NSLocalizedDescriptionKey: errorString}];
+ *error = [NSError errorWithDomain:OLMErrorDomain code:0 userInfo:@{NSLocalizedDescriptionKey: errorString}];
}
return nil;
}