From f505113fb7a6d61015ad8050b3fb4e26df029150 Mon Sep 17 00:00:00 2001 From: Chris Ballinger Date: Sat, 9 Apr 2016 14:00:30 -0700 Subject: Initial test passing --- xcode/OLMKitTests/OLMKitTests.m | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'xcode/OLMKitTests/OLMKitTests.m') diff --git a/xcode/OLMKitTests/OLMKitTests.m b/xcode/OLMKitTests/OLMKitTests.m index 944d11c..7075057 100644 --- a/xcode/OLMKitTests/OLMKitTests.m +++ b/xcode/OLMKitTests/OLMKitTests.m @@ -31,10 +31,27 @@ OLMAccount *alice = [[OLMAccount alloc] initNewAccount]; OLMAccount *bob = [[OLMAccount alloc] initNewAccount]; [bob generateOneTimeKeys:5]; - NSDictionary *identityKeys = bob.identityKeys; - NSDictionary *oneTimeKeys = bob.oneTimeKeys; - NSParameterAssert(identityKeys != nil); - NSParameterAssert(oneTimeKeys != nil); + NSDictionary *bobIdKeys = bob.identityKeys; + NSString *bobIdKey = bobIdKeys[@"curve25519"]; + NSDictionary *bobOneTimeKeys = bob.oneTimeKeys; + NSParameterAssert(bobIdKey != nil); + NSParameterAssert(bobOneTimeKeys != nil); + __block NSString *bobOneTimeKey = nil; + NSDictionary *bobOtkCurve25519 = bobOneTimeKeys[@"curve25519"]; + [bobOtkCurve25519 enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) { + bobOneTimeKey = obj; + }]; + XCTAssert([bobOneTimeKey isKindOfClass:[NSString class]]); + + OLMSession *aliceSession = [[OLMSession alloc] initOutboundSessionWithAccount:alice theirIdentityKey:bobIdKey theirOneTimeKey:bobOneTimeKey]; + NSString *message = @"Hello!"; + OLMMessage *aliceToBobMsg = [aliceSession encryptMessage:message]; + + OLMSession *bobSession = [[OLMSession alloc] initInboundSessionWithAccount:bob oneTimeKeyMessage:aliceToBobMsg.ciphertext]; + NSString *plaintext = [bobSession decryptMessage:aliceToBobMsg]; + XCTAssertEqualObjects(message, plaintext); + BOOL success = [bobSession removeOneTimeKeys]; + XCTAssertTrue(success); } -- cgit v1.2.3