Browse Source

IOSAD-73 ratingFromString:, stringFromRating:

IOSAD-92
Dirk Zimmermann 5 years ago
parent
commit
1d1042a2e5
3 changed files with 86 additions and 1 deletions
  1. +52
    -0
      pEpObjCAdapter/PEPInternalSession.m
  2. +23
    -1
      pEpObjCAdapter/PEPSession.m
  3. +11
    -0
      pEpObjCAdapter/PEPSessionProtocol.h

+ 52
- 0
pEpObjCAdapter/PEPInternalSession.m View File

@ -567,4 +567,56 @@ DYNAMIC_API PEP_STATUS identity_rating(PEP_SESSION session, pEp_identity *ident,
return undo_last_mistrust(_session);
}
static NSDictionary *ratingToString;
static NSDictionary *stringToRating;
+ (void)initialize
{
NSDictionary *ratingToStringIntern =
@{
[NSNumber numberWithInteger:PEP_rating_cannot_decrypt]: @"cannot_decrypt",
[NSNumber numberWithInteger:PEP_rating_have_no_key]: @"have_no_key",
[NSNumber numberWithInteger:PEP_rating_unencrypted]: @"unencrypted",
[NSNumber numberWithInteger:PEP_rating_unencrypted_for_some]: @"unencrypted_for_some",
[NSNumber numberWithInteger:PEP_rating_unreliable]: @"unreliable",
[NSNumber numberWithInteger:PEP_rating_reliable]: @"reliable",
[NSNumber numberWithInteger:PEP_rating_trusted]: @"trusted",
[NSNumber numberWithInteger:PEP_rating_trusted_and_anonymized]: @"trusted_and_anonymized",
[NSNumber numberWithInteger:PEP_rating_fully_anonymous]: @"fully_anonymous",
[NSNumber numberWithInteger:PEP_rating_mistrust]: @"mistrust",
[NSNumber numberWithInteger:PEP_rating_b0rken]: @"b0rken",
[NSNumber numberWithInteger:PEP_rating_under_attack]: @"under_attack",
[NSNumber numberWithInteger:PEP_rating_undefined]: @"undefined",
};
NSMutableDictionary *stringToRatingMutable = [NSMutableDictionary
dictionaryWithCapacity:
ratingToStringIntern.count];
for (NSNumber *ratingNumber in ratingToStringIntern.allKeys) {
NSString *ratingName = [ratingToStringIntern objectForKey:ratingNumber];
[stringToRatingMutable setObject:ratingNumber forKey:ratingName];
}
ratingToString = ratingToStringIntern;
stringToRating = [NSDictionary dictionaryWithDictionary:stringToRatingMutable];
}
- (PEP_rating)ratingFromString:(NSString * _Nonnull)string
{
NSNumber *num = [stringToRating objectForKey:string];
if (num) {
return (PEP_rating) [num integerValue];
} else {
return PEP_rating_undefined;
}
}
- (NSString * _Nonnull)stringFromRating:(PEP_rating)rating
{
NSString *stringRating = [ratingToString objectForKey:[NSNumber numberWithInteger:rating]];
if (stringRating) {
return stringRating;
} else {
return @"undefined";
}
}
@end

+ 23
- 1
pEpObjCAdapter/PEPSession.m View File

@ -196,7 +196,17 @@
return [PEPSession undoLastMistrust];
}
#pragma mark - Static
- (PEP_rating)ratingFromString:(NSString * _Nonnull)string
{
return [PEPSession ratingFromString:string];
}
- (NSString * _Nonnull)stringFromRating:(PEP_rating)rating
{
return [PEPSession stringFromRating:rating];
}
#pragma mark - Static
+ (PEP_rating)decryptMessageDict:(nonnull PEPDict *)src
dest:(PEPDict * _Nullable * _Nullable)dst
@ -382,4 +392,16 @@
return [session undoLastMistrust];
}
+ (PEP_rating)ratingFromString:(NSString * _Nonnull)string
{
PEPInternalSession *session = [PEPSessionProvider session];
return [session ratingFromString:string];
}
+ (NSString * _Nonnull)stringFromRating:(PEP_rating)rating
{
PEPInternalSession *session = [PEPSessionProvider session];
return [session stringFromRating:rating];
}
@end

+ 11
- 0
pEpObjCAdapter/PEPSessionProtocol.h View File

@ -172,4 +172,15 @@ typedef NSArray<NSString *> PEPStringList;
*/
- (PEP_STATUS)undoLastMistrust;
/**
Can convert a string like "cannot_decrypt" into its equivalent PEP_rating_cannot_decrypt.
*/
- (PEP_rating)ratingFromString:(NSString * _Nonnull)string;
/**
Can convert a pEp rating like PEP_rating_cannot_decrypt
into its equivalent string "cannot_decrypt" .
*/
- (NSString * _Nonnull)stringFromRating:(PEP_rating)rating;
@end

Loading…
Cancel
Save