pEpObjCAdapter/PEPPassphraseCache.m
author Dirk Zimmermann <dz@pep.security>
Thu, 25 Jun 2020 17:08:21 +0200
branchIOSAD-172
changeset 1457 98e4f0837759
parent 1456 752e8d0380a1
child 1459 a2d09a38d424
permissions -rw-r--r--
IOSAD-172 Can return stored passphrases
     1 //
     2 //  PEPPassphraseCache.m
     3 //  pEpObjCAdapter
     4 //
     5 //  Created by Dirk Zimmermann on 25.06.20.
     6 //  Copyright © 2020 p≡p. All rights reserved.
     7 //
     8 
     9 #import "PEPPassphraseCache.h"
    10 
    11 static NSUInteger s_numberOfPassphrases = 20;
    12 
    13 @interface PEPPassphraseCache ()
    14 
    15 @property (nonatomic) dispatch_queue_t queue;
    16 @property (nonatomic) NSMutableArray *mutablePassphrases;
    17 
    18 @end
    19 
    20 @implementation PEPPassphraseCache
    21 
    22 /// Internal constructor (for now).
    23 - (instancetype)initTimeout:(NSUInteger)timeout
    24 {
    25     self = [super init];
    26     if (self) {
    27         _timeout = timeout;
    28         _queue = dispatch_queue_create("PEPPassphraseCache Queue", DISPATCH_QUEUE_SERIAL);
    29         _mutablePassphrases = [NSMutableArray arrayWithCapacity:s_numberOfPassphrases];
    30     }
    31     return self;
    32 }
    33 
    34 /// Public constructor with default values.
    35 - (instancetype)init
    36 {
    37     return [self initTimeout:10 * 60];
    38 }
    39 
    40 - (void)addPassphrase:(NSString *)passphrase
    41 {
    42 }
    43 
    44 - (NSArray *)passphrases
    45 {
    46     NSMutableArray *resultingPassphrases = [NSMutableArray
    47                                             arrayWithCapacity:s_numberOfPassphrases + 1];
    48     [resultingPassphrases addObject:@""];
    49     dispatch_sync(self.queue, ^{
    50         for (NSString *passphrase in self.mutablePassphrases) {
    51             [resultingPassphrases addObject:passphrase];
    52         }
    53     });
    54     return [NSArray arrayWithArray:resultingPassphrases];
    55 }
    56 
    57 @end