Skip to content

Commit

Permalink
Refactor responseQueue
Browse files Browse the repository at this point in the history
  • Loading branch information
rnapier committed Jun 21, 2012
1 parent 67df473 commit f13f526
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 44 deletions.
4 changes: 4 additions & 0 deletions RNCryptor.xcodeproj/project.pbxproj
Expand Up @@ -25,6 +25,7 @@
FB7565241512D9BE007B807B /* RNDecryptor.h in Headers */ = {isa = PBXBuildFile; fileRef = FB7565241512D9BE007B807A /* RNDecryptor.h */; };
FB7565241512D9BE007B807D /* RNCryptorEngine.m in Sources */ = {isa = PBXBuildFile; fileRef = FB7565241512D9BE007B807C /* RNCryptorEngine.m */; };
FB7565241512D9BE007B807F /* RNCryptorEngine.h in Headers */ = {isa = PBXBuildFile; fileRef = FB7565241512D9BE007B807E /* RNCryptorEngine.h */; };
FB7565241512D9BE007B8085 /* RNCryptor+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = FB7565241512D9BE007B8084 /* RNCryptor+Private.h */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -59,6 +60,7 @@
FB7565241512D9BE007B807A /* RNDecryptor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNDecryptor.h; sourceTree = "<group>"; };
FB7565241512D9BE007B807C /* RNCryptorEngine.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNCryptorEngine.m; sourceTree = "<group>"; };
FB7565241512D9BE007B807E /* RNCryptorEngine.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNCryptorEngine.h; sourceTree = "<group>"; };
FB7565241512D9BE007B8084 /* RNCryptor+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "RNCryptor+Private.h"; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -116,6 +118,7 @@
FB7564F51512D3C4007B806B /* RNCryptor */ = {
isa = PBXGroup;
children = (
FB7565241512D9BE007B8084 /* RNCryptor+Private.h */,
FB7565241512D9BE007B807E /* RNCryptorEngine.h */,
FB7565241512D9BE007B807C /* RNCryptorEngine.m */,
FB7565241512D9BE007B807A /* RNDecryptor.h */,
Expand Down Expand Up @@ -171,6 +174,7 @@
FB7565241512D9BE007B8077 /* RNEncryptor.h in Headers */,
FB7565241512D9BE007B807B /* RNDecryptor.h in Headers */,
FB7565241512D9BE007B807F /* RNCryptorEngine.h in Headers */,
FB7565241512D9BE007B8085 /* RNCryptor+Private.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
31 changes: 31 additions & 0 deletions RNCryptor/RNCryptor+Private.h
@@ -0,0 +1,31 @@
//
// RNCryptor(Private)
//
// Copyright (c) 2012 Rob Napier
//
// This code is licensed under the MIT License:
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//

#import <Foundation/Foundation.h>
#import "RNCryptor.h"

@interface RNCryptor (Private)
@end
2 changes: 2 additions & 0 deletions RNCryptor/RNCryptor.h
Expand Up @@ -103,6 +103,8 @@ typedef void (^RNCryptorCompletion)(NSData *, NSError *);

@interface RNCryptor : NSObject

@property (nonatomic, readwrite) dispatch_queue_t responseQueue;

/** Generate key given a password and salt using a PBKDF
*
* @param password Password to use for PBKDF
Expand Down
31 changes: 31 additions & 0 deletions RNCryptor/RNCryptor.m
Expand Up @@ -29,6 +29,7 @@
NSString *const kRNCryptorErrorDomain = @"net.robnapier.RNCryptManager";

@implementation RNCryptor
@synthesize responseQueue = _responseQueue;

+ (NSData *)keyForPassword:(NSString *)password withSalt:(NSData *)salt andSettings:(RNCryptorKeyDerivationSettings)keySettings
{
Expand Down Expand Up @@ -61,4 +62,34 @@ + (NSData *)randomDataOfLength:(size_t)length
return data;
}

- (id)init
{
self = [super init];
if (self) {
_responseQueue = dispatch_get_current_queue();
dispatch_retain(_responseQueue);
}
}

- (void)dealloc
{
if (_responseQueue) {
dispatch_release(_responseQueue);
_responseQueue = NULL;
}
}

- (void)setResponseQueue:(dispatch_queue_t)aResponseQueue
{
if (aResponseQueue) {
dispatch_retain(aResponseQueue);
}

if (_responseQueue) {
dispatch_release(_responseQueue);
}

_responseQueue = aResponseQueue;
}

@end
1 change: 0 additions & 1 deletion RNCryptor/RNDecryptor.h
Expand Up @@ -29,7 +29,6 @@


@interface RNDecryptor : RNCryptor
@property (nonatomic, readwrite) dispatch_queue_t responseQueue;

- (RNDecryptor *)initWithEncryptionKey:(NSData *)encryptionKey
HMACKey:(NSData *)HMACKey
Expand Down
19 changes: 0 additions & 19 deletions RNCryptor/RNDecryptor.m
Expand Up @@ -88,7 +88,6 @@ @implementation RNDecryptor
@synthesize completion = _completion;
@synthesize queue = _queue;
@synthesize HMACLength = _HMACLength;
@synthesize responseQueue = _responseQueue;
@synthesize encryptionKey = _encryptionKey;
@synthesize HMACKey = _HMACKey;
@synthesize engine = _engine;
Expand Down Expand Up @@ -134,8 +133,6 @@ - (RNDecryptor *)initWithEncryptionKey:(NSData *)anEncryptionKey HMACKey:(NSData
_queue = dispatch_queue_create("net.robnapier.RNDecryptor", DISPATCH_QUEUE_SERIAL);
_inData = [NSMutableData data];
__outData = [NSMutableData data];
_responseQueue = dispatch_get_current_queue();
dispatch_retain(_responseQueue);
}

return self;
Expand All @@ -160,10 +157,6 @@ - (void)cleanup
_handler = nil;
_completion = nil;

if (_responseQueue) {
dispatch_release(_responseQueue);
_responseQueue = NULL;
}
}

- (void)dealloc
Expand All @@ -175,18 +168,6 @@ - (void)dealloc
}
}

- (void)setResponseQueue:(dispatch_queue_t)aResponseQueue
{
if (aResponseQueue) {
dispatch_retain(aResponseQueue);
}

if (_responseQueue) {
dispatch_release(_responseQueue);
}

_responseQueue = aResponseQueue;
}

- (void)decryptData:(NSData *)data
{
Expand Down
2 changes: 0 additions & 2 deletions RNCryptor/RNEncryptor.h
Expand Up @@ -28,8 +28,6 @@
#import "RNCryptor.h"

@interface RNEncryptor : RNCryptor
@property (nonatomic, readwrite) dispatch_queue_t responseQueue;

- (RNEncryptor *)initWithSettings:(RNCryptorSettings)settings
encryptionKey:(NSData *)encryptionKey
HMACKey:(NSData *)HMACKey
Expand Down
22 changes: 0 additions & 22 deletions RNCryptor/RNEncryptor.m
Expand Up @@ -46,7 +46,6 @@ @implementation RNEncryptor
@synthesize completion = _completion;
@synthesize queue = _queue;
@synthesize HMACLength = __HMACLength;
@synthesize responseQueue = _responseQueue;
@synthesize engine = __engine;


Expand Down Expand Up @@ -96,9 +95,6 @@ - (RNEncryptor *)initWithSettings:(RNCryptorSettings)theSettings encryptionKey:(
_completion = [aCompletion copy];
_queue = dispatch_queue_create("net.robnapier.RNEncryptor", DISPATCH_QUEUE_SERIAL);

_responseQueue = dispatch_get_current_queue();
dispatch_retain(_responseQueue);

NSError *error;
__engine = [[RNCryptorEngine alloc] initWithOperation:kCCEncrypt
settings:theSettings
Expand Down Expand Up @@ -149,11 +145,6 @@ - (void)cleanup
_handler = nil;
_completion = nil;

if (_responseQueue) {
dispatch_release(_responseQueue);
_responseQueue = NULL;
}

__engine = nil;
}

Expand All @@ -166,19 +157,6 @@ - (void)dealloc
}
}

- (void)setResponseQueue:(dispatch_queue_t)aResponseQueue
{
if (aResponseQueue) {
dispatch_retain(aResponseQueue);
}

if (_responseQueue) {
dispatch_release(_responseQueue);
}

_responseQueue = aResponseQueue;
}

- (void)addData:(NSData *)data
{
NSAssert(self.engine != NULL, @"Cryptor has be completed");
Expand Down

0 comments on commit f13f526

Please sign in to comment.