IOSAD-72 trustwordsForFingerprint
authorDirk Zimmermann <dirk@pep-project.org>
Thu, 15 Mar 2018 08:04:31 +0100
changeset 5318bd62764f284
parent 530 66abca44d192
child 532 775c55945da1
IOSAD-72 trustwordsForFingerprint
pEpObjCAdapter/PEPInternalSession.m
pEpObjCAdapter/PEPSession.m
pEpObjCAdapter/PEPSessionProtocol.h
pEpObjCTests/PEPSessionTest.m
     1.1 --- a/pEpObjCAdapter/PEPInternalSession.m	Thu Mar 15 08:04:30 2018 +0100
     1.2 +++ b/pEpObjCAdapter/PEPInternalSession.m	Thu Mar 15 08:04:31 2018 +0100
     1.3 @@ -410,17 +410,18 @@
     1.4      return YES;
     1.5  }
     1.6  
     1.7 -- (NSArray *)trustwords:(NSString *)fpr
     1.8 -            forLanguage:(NSString *)languageID
     1.9 -              shortened:(BOOL)shortened
    1.10 +- (NSArray * _Nullable)trustwordsForFingerprint:(NSString * _Nonnull)fingerprint
    1.11 +                                     languageID:(NSString * _Nonnull)languageID
    1.12 +                                      shortened:(BOOL)shortened
    1.13 +                                          error:(NSError * _Nullable * _Nullable)error
    1.14  {
    1.15      NSMutableArray *array = [NSMutableArray array];
    1.16  
    1.17 -    for (int i = 0; i < [fpr length]; i += 4) {
    1.18 +    for (int i = 0; i < [fingerprint length]; i += 4) {
    1.19          if (shortened && i >= 20)
    1.20              break;
    1.21  
    1.22 -        NSString *str = [fpr substringWithRange:NSMakeRange(i, 4)];
    1.23 +        NSString *str = [fingerprint substringWithRange:NSMakeRange(i, 4)];
    1.24  
    1.25          unsigned int value;
    1.26          [[NSScanner scannerWithString:str] scanHexInt:&value];
    1.27 @@ -428,8 +429,11 @@
    1.28          char *word;
    1.29          size_t size;
    1.30  
    1.31 -        @synchronized (self) {
    1.32 -            trustword(_session, value, [languageID UTF8String], &word, &size);
    1.33 +        PEP_STATUS status = trustword(_session, value, [languageID UTF8String], &word, &size);
    1.34 +
    1.35 +        if ([NSError setError:error fromPEPStatus:status]) {
    1.36 +            free(word);
    1.37 +            return nil;
    1.38          }
    1.39  
    1.40          [array addObject:[NSString stringWithUTF8String:word]];
     2.1 --- a/pEpObjCAdapter/PEPSession.m	Thu Mar 15 08:04:30 2018 +0100
     2.2 +++ b/pEpObjCAdapter/PEPSession.m	Thu Mar 15 08:04:31 2018 +0100
     2.3 @@ -142,11 +142,17 @@
     2.4      return [session rating:rating forIdentity:identity error:error];
     2.5  }
     2.6  
     2.7 -- (nonnull NSArray *)trustwords:(nonnull NSString *)fpr forLanguage:(nonnull NSString *)languageID
     2.8 -                      shortened:(BOOL)shortened
     2.9 +- (NSArray * _Nullable)trustwordsForFingerprint:(NSString * _Nonnull)fingerprint
    2.10 +                                     languageID:(NSString * _Nonnull)languageID
    2.11 +                                      shortened:(BOOL)shortened
    2.12 +                                          error:(NSError * _Nullable * _Nullable)error
    2.13  {
    2.14      PEPInternalSession *session = [PEPSessionProvider session];
    2.15 -    return [session trustwords:fpr forLanguage:languageID shortened:shortened];
    2.16 +    return [session
    2.17 +            trustwordsForFingerprint:fingerprint
    2.18 +            languageID:languageID
    2.19 +            shortened:shortened
    2.20 +            error:error];
    2.21  }
    2.22  
    2.23  - (void)mySelf:(nonnull PEPIdentity *)identity
     3.1 --- a/pEpObjCAdapter/PEPSessionProtocol.h	Thu Mar 15 08:04:30 2018 +0100
     3.2 +++ b/pEpObjCAdapter/PEPSessionProtocol.h	Thu Mar 15 08:04:31 2018 +0100
     3.3 @@ -99,8 +99,10 @@
     3.4           error:(NSError * _Nullable * _Nullable)error;
     3.5  
     3.6  /** Get trustwords for a fingerprint */
     3.7 -- (nonnull NSArray *)trustwords:(nonnull NSString *)fpr forLanguage:(nonnull NSString *)languageID
     3.8 -                      shortened:(BOOL)shortened;
     3.9 +- (NSArray * _Nullable)trustwordsForFingerprint:(NSString * _Nonnull)fingerprint
    3.10 +                                     languageID:(NSString * _Nonnull)languageID
    3.11 +                                      shortened:(BOOL)shortened
    3.12 +                                          error:(NSError * _Nullable * _Nullable)error;
    3.13  
    3.14  /**
    3.15   Supply an account used by our user himself. The identity is supplemented with the missing parts
     4.1 --- a/pEpObjCTests/PEPSessionTest.m	Thu Mar 15 08:04:30 2018 +0100
     4.2 +++ b/pEpObjCTests/PEPSessionTest.m	Thu Mar 15 08:04:31 2018 +0100
     4.3 @@ -69,8 +69,13 @@
     4.4  {
     4.5      PEPSession *session = [PEPSession new];
     4.6  
     4.7 -    NSArray *trustwords = [session trustwords:@"DB47DB47DB47DB47DB47DB47DB47DB47DB47DB47"
     4.8 -                                  forLanguage:@"en" shortened:false];
     4.9 +    NSError *error = nil;
    4.10 +    NSArray *trustwords = [session
    4.11 +                           trustwordsForFingerprint:@"DB47DB47DB47DB47DB47DB47DB47DB47DB47DB47"
    4.12 +                           languageID:@"en"
    4.13 +                           shortened:false
    4.14 +                           error:&error];
    4.15 +    XCTAssertNil(error);
    4.16      XCTAssertEqual([trustwords count], 10);
    4.17  
    4.18      for(id word in trustwords)