Add 'server/' from commit '800090542d91beae40bc81fc41b67ba61c47da77'
git-subtree-dir: server git-subtree-mainline:6a4054c15agit-subtree-split:800090542d
This commit is contained in:
48
server/Tests/CryptoTests.m
Normal file
48
server/Tests/CryptoTests.m
Normal file
@@ -0,0 +1,48 @@
|
||||
//
|
||||
// Tests.m
|
||||
// Tests
|
||||
//
|
||||
// Created by James Magahern on 11/15/18.
|
||||
// Copyright © 2018 James Magahern. All rights reserved.
|
||||
//
|
||||
|
||||
#import <XCTest/XCTest.h>
|
||||
|
||||
#import "NSData+AES.h"
|
||||
|
||||
// base64 encoded
|
||||
static NSString *const kTestKey = @"QMeDmiHj8eCFVfrQWQfDpw==";
|
||||
|
||||
@interface Tests : XCTestCase
|
||||
@property (nonatomic, strong) NSString *commonPayload;
|
||||
@property (nonatomic, strong) NSData *commonIVData;
|
||||
@property (nonatomic, strong) NSData *symmetricKeyData;
|
||||
@end
|
||||
|
||||
@implementation Tests
|
||||
|
||||
- (void)setUp {
|
||||
self.commonPayload = @"Hey this is a test";
|
||||
|
||||
NSString *IVDataString = [[NSUUID UUID] UUIDString];
|
||||
self.commonIVData = [IVDataString dataUsingEncoding:NSUTF8StringEncoding];
|
||||
|
||||
self.symmetricKeyData = [[NSData alloc] initWithBase64EncodedString:kTestKey options:0];
|
||||
XCTAssert(self.commonIVData && self.symmetricKeyData);
|
||||
}
|
||||
|
||||
- (void)testEncryptionAndDecryption
|
||||
{
|
||||
NSData *inputData = [self.commonPayload dataUsingEncoding:NSUTF8StringEncoding];
|
||||
|
||||
NSError *error = nil;
|
||||
NSData *encryptedData = [inputData encryptedDataWithKey:self.symmetricKeyData iv:self.commonIVData error:&error];
|
||||
XCTAssert(!error);
|
||||
|
||||
NSData *decryptedData = [encryptedData decryptedDataWithKey:self.symmetricKeyData iv:self.commonIVData error:&error];
|
||||
XCTAssert(!error);
|
||||
|
||||
XCTAssert([decryptedData isEqualToData:inputData]);
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user