TestObjectFactory.m 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // _____ _
  2. // |_ _| |_ _ _ ___ ___ _ __ __ _
  3. // | | | ' \| '_/ -_) -_) ' \/ _` |_
  4. // |_| |_||_|_| \___\___|_|_|_\__,_(_)
  5. //
  6. // Threema iOS Client
  7. // Copyright (c) 2014-2020 Threema GmbH
  8. //
  9. // This program is free software: you can redistribute it and/or modify
  10. // it under the terms of the GNU Affero General Public License, version 3,
  11. // as published by the Free Software Foundation.
  12. //
  13. // This program is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. // GNU Affero General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Affero General Public License
  19. // along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. #import "TestObjectFactory.h"
  21. #import "MyIdentityStore.h"
  22. #import "NaClCrypto.h"
  23. #import "ProtocolDefines.h"
  24. @interface TestObjectFactory ()
  25. @end
  26. @implementation TestObjectFactory
  27. + (instancetype)testObjectFactory {
  28. TestObjectFactory *factory = [[TestObjectFactory alloc] init];
  29. return factory;
  30. }
  31. + (instancetype)testObjectFactoryTemporaryContext {
  32. TestObjectFactory *factory = [[TestObjectFactory alloc] init];
  33. return factory;
  34. }
  35. - (NSData *) groupIdForString:(NSString *)groupIdString {
  36. return [[groupIdString dataUsingEncoding:NSASCIIStringEncoding] subdataWithRange:NSMakeRange(0, kGroupIdLen)];
  37. }
  38. - (Conversation *)groupConversationWithId:(NSString *)groupId {
  39. NSData *groupIdData = [self groupIdForString: groupId];
  40. Conversation *conversation = [_entityManager.entityFetcher conversationForGroupId:groupIdData];
  41. if (conversation == nil) {
  42. conversation = [_entityManager.entityCreator conversation];
  43. conversation.groupId = groupIdData;
  44. conversation.groupMyIdentity = [MyIdentityStore sharedMyIdentityStore].identity;
  45. }
  46. return conversation;
  47. }
  48. - (Contact *)contactWithIdentity:(NSString *)identity publicKey:(NSData *)publicKey {
  49. Contact *contact = [_entityManager.entityFetcher contactForId: identity];
  50. if (contact == nil) {
  51. contact = [_entityManager.entityCreator contact];
  52. contact.identity = identity;
  53. contact.publicKey = publicKey;
  54. contact.verificationLevel = [NSNumber numberWithInt:kVerificationLevelUnverified];
  55. }
  56. return contact;
  57. }
  58. - (Conversation *)conversationWithEchoEcho {
  59. Contact *contact = [self contactWithIdentity:@"ECHOECHO" publicKey:[[NSData alloc] initWithBase64EncodedString:@"4a6a1b34 dcef15d4 3cb74de2 fd36091b e99fbbaf 126d099d 47d83d91 9712c72b" options:NSDataBase64DecodingIgnoreUnknownCharacters]];
  60. Conversation *conversation = [_entityManager conversationForContact:contact createIfNotExisting:YES];
  61. return conversation;
  62. }
  63. @end