pEp macOS Desktop adapter
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

134 lines
6.1 KiB

  1. //
  2. // PEPObjCAdapterXPCApi.m
  3. // foundation.pEp.adapter.macOS
  4. //
  5. // Created by David Alarcon on 9/2/21.
  6. // Copyright © 2021 pp foundation. All rights reserved.
  7. //
  8. #import "PEPObjCAdapterXPCApi.h"
  9. #import "PEPSession.h"
  10. #import "PEPIdentity.h"
  11. #import "PEPObjCAdapterXpcApiResult.h"
  12. #import "PEPObjcAdapter.h"
  13. @implementation PEPObjCAdapterXPCApi
  14. - (void)myself:(PEPIdentity *)identity resultBlock:(void (^)(PEPObjCAdapterXpcApiResult * _Nonnull))resultCallback {
  15. PEPSession *session = [PEPSession new];
  16. [session mySelf:identity errorCallback:^(NSError * _Nonnull error) {
  17. PEPObjCAdapterXpcApiResult *result = [[PEPObjCAdapterXpcApiResult alloc] initWithResult:nil error:error];
  18. resultCallback(result);
  19. } successCallback:^(PEPIdentity * _Nonnull identity) {
  20. PEPObjCAdapterXpcApiResult *result = [[PEPObjCAdapterXpcApiResult alloc] initWithResult:@[identity] error:nil];
  21. resultCallback(result);
  22. }];
  23. }
  24. - (void)encryptMessage:(PEPMessage *)message
  25. extraKeys:(PEPStringList * _Nullable)extraKeys
  26. encFormat:(PEPEncFormat)encFormat
  27. resultBlock:(void (^)(PEPObjCAdapterXpcApiResult *))resultCallback {
  28. NSLog(@"%s", __PRETTY_FUNCTION__);
  29. PEPSession *session = [PEPSession new];
  30. [session encryptMessage:message extraKeys:extraKeys encFormat:encFormat
  31. errorCallback:^(NSError * _Nonnull error) {
  32. PEPObjCAdapterXpcApiResult *result = [[PEPObjCAdapterXpcApiResult alloc]
  33. initWithResult:nil
  34. error:error];
  35. resultCallback(result);
  36. } successCallback:^(PEPMessage * _Nonnull srcMessage, PEPMessage * _Nonnull destMessage) {
  37. PEPObjCAdapterXpcApiResult *result = [[PEPObjCAdapterXpcApiResult alloc]
  38. initWithResult:@[srcMessage, destMessage]
  39. error:nil];
  40. resultCallback(result);
  41. }];
  42. }
  43. - (void)outgoingRatingForMessage:(PEPMessage *)theMessage
  44. resultBlock:(void (^)(PEPObjCAdapterXpcApiResult * _Nonnull))resultCallback {
  45. NSLog(@"%s", __PRETTY_FUNCTION__);
  46. PEPSession *session = [PEPSession new];
  47. [session outgoingRatingForMessage:theMessage errorCallback:^(NSError * _Nonnull error) {
  48. PEPObjCAdapterXpcApiResult *result = [[PEPObjCAdapterXpcApiResult alloc]
  49. initWithResult:nil
  50. error:error];
  51. resultCallback(result);
  52. } successCallback:^(PEPRating rating) {
  53. PEPObjCAdapterXpcApiResult *result = [[PEPObjCAdapterXpcApiResult alloc]
  54. initWithResult:@[@(rating)]
  55. error:nil];
  56. resultCallback(result);
  57. }];
  58. }
  59. - (void)colorFromRating:(PEPRating)rating
  60. resultBlock:(void (^)(PEPObjCAdapterXpcApiResult * _Nonnull))resultCallback {
  61. NSLog(@"%s", __PRETTY_FUNCTION__);
  62. PEPSession *session = [PEPSession new];
  63. PEPColor color = [session colorFromRating:rating];
  64. PEPObjCAdapterXpcApiResult *result = [[PEPObjCAdapterXpcApiResult alloc]
  65. initWithResult:@[@(color)]
  66. error:nil];
  67. resultCallback(result);
  68. }
  69. - (void)encryptMessage:(PEPMessage *)message
  70. forSelf:(PEPIdentity *)ownIdentity
  71. extraKeys:(PEPStringList *)extraKeys
  72. resultBlock:(void (^)(PEPObjCAdapterXpcApiResult * _Nonnull))resultCallback {
  73. NSLog(@"%s", __PRETTY_FUNCTION__);
  74. PEPSession *session = [PEPSession new];
  75. [session encryptMessage:message forSelf:ownIdentity extraKeys:extraKeys errorCallback:^(NSError * _Nonnull error) {
  76. PEPObjCAdapterXpcApiResult *result = [[PEPObjCAdapterXpcApiResult alloc]
  77. initWithResult:nil
  78. error:error];
  79. resultCallback(result);
  80. } successCallback:^(PEPMessage * _Nonnull srcMessage, PEPMessage * _Nonnull destMessage) {
  81. PEPObjCAdapterXpcApiResult *result = [[PEPObjCAdapterXpcApiResult alloc]
  82. initWithResult:@[srcMessage, destMessage]
  83. error:nil];
  84. resultCallback(result);
  85. }];
  86. }
  87. - (void)decryptMessage:(PEPMessage *)message
  88. flags:(PEPDecryptFlags)flags
  89. extraKeys:(PEPStringList *)extraKeys
  90. resultBlock:(void (^)(PEPObjCAdapterXpcApiResult * _Nonnull))resultCallback {
  91. NSLog(@"%s", __PRETTY_FUNCTION__);
  92. PEPSession *session = [PEPSession new];
  93. [session decryptMessage:message flags:flags extraKeys:extraKeys errorCallback:^(NSError * _Nonnull error) {
  94. PEPObjCAdapterXpcApiResult *result = [[PEPObjCAdapterXpcApiResult alloc]
  95. initWithResult:nil
  96. error:error];
  97. resultCallback(result);
  98. } successCallback:^(PEPMessage * _Nonnull srcMessage,
  99. PEPMessage * _Nonnull dstMessage,
  100. PEPStringList * _Nonnull keyList,
  101. PEPRating rating,
  102. PEPDecryptFlags flags,
  103. BOOL isFormerlyEncryptedReuploadedMessage) {
  104. PEPObjCAdapterXpcApiResult *result = [[PEPObjCAdapterXpcApiResult alloc]
  105. initWithResult:@[srcMessage,
  106. dstMessage,
  107. keyList,
  108. @(rating),
  109. @(flags),
  110. @(isFormerlyEncryptedReuploadedMessage)]
  111. error:nil];
  112. resultCallback(result);
  113. }];
  114. }
  115. - (void)setPassiveModeEnabled:(BOOL)enabled {
  116. NSLog(@"%s <%@>", __PRETTY_FUNCTION__, enabled ? @"ON" : @"OFF");
  117. [PEPObjCAdapter setPassiveModeEnabled:enabled];
  118. }
  119. @end