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