49 lines
1.3 KiB
Mathematica
49 lines
1.3 KiB
Mathematica
|
|
//
|
||
|
|
// 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
|