Commit a517f671 authored by George Nachman's avatar George Nachman

Fix various inconsistencies in retain/release in SIG code, and rename ivars not starting with _

parent 9a8dd690
......@@ -20,6 +20,7 @@
self = [super init];
if (self) {
_secCertificate = secCertificate;
CFRetain(secCertificate);
}
return self;
}
......@@ -35,6 +36,10 @@
return self;
}
- (void)dealloc {
CFRelease(_secCertificate);
}
- (SIGKey *)publicKey {
if (_publicKey) {
return _publicKey;
......@@ -54,7 +59,8 @@
}
_publicKey = [[SIGKey alloc] initWithSecKey:key];
CFRelease(key);
CFRelease(key);
return _publicKey;
}
......
......@@ -99,7 +99,9 @@
return nil;
}
return [[SIGKey alloc] initWithSecKey:privateKey];
SIGKey *result = [[SIGKey alloc] initWithSecKey:privateKey];
CFRelease(privateKey);
return result;
}
- (SIGCertificate *)signingCertificate {
......
......@@ -13,6 +13,7 @@
- (instancetype)initWithSecKey:(SecKeyRef)secKey {
self = [super init];
if (self) {
CFRetain(secKey);
_secKey = secKey;
}
return self;
......
......@@ -12,12 +12,6 @@
SecPolicyRef _policy;
}
- (void)dealloc {
if (_policy) {
CFRelease(_policy);
}
}
- (instancetype)init {
self = [super init];
if (self) {
......@@ -29,6 +23,12 @@
return self;
}
- (void)dealloc {
if (_policy) {
CFRelease(_policy);
}
}
- (SecPolicyRef)secPolicy {
return _policy;
}
......@@ -39,12 +39,6 @@
SecPolicyRef _policy;
}
- (void)dealloc {
if (_policy) {
CFRelease(_policy);
}
}
- (instancetype)init {
self = [super init];
if (self) {
......@@ -57,6 +51,12 @@
return self;
}
- (void)dealloc {
if (_policy) {
CFRelease(_policy);
}
}
- (SecPolicyRef)secPolicy {
return _policy;
}
......
......@@ -13,10 +13,10 @@
#import "SIGKey.h"
@implementation SIGSHA2SigningAlgorithm {
SecTransformRef readTransform;
SecTransformRef dataDigestTransform;
SecTransformRef dataSignTransform;
SecGroupTransformRef group;
SecTransformRef _readTransform;
SecTransformRef _dataDigestTransform;
SecTransformRef _dataSignTransform;
SecGroupTransformRef _group;
}
+ (NSString *)name {
......@@ -24,17 +24,17 @@
}
- (void)dealloc {
if (readTransform) {
CFRelease(readTransform);
if (_readTransform) {
CFRelease(_readTransform);
}
if (dataDigestTransform) {
CFRelease(dataDigestTransform);
if (_dataDigestTransform) {
CFRelease(_dataDigestTransform);
}
if (dataSignTransform) {
CFRelease(dataSignTransform);
if (_dataSignTransform) {
CFRelease(_dataSignTransform);
}
if (group) {
CFRelease(group);
if (_group) {
CFRelease(_group);
}
}
......@@ -51,8 +51,8 @@
return nil;
}
readTransform = SecTransformCreateReadTransformWithReadStream((__bridge CFReadStreamRef)readStream);
if (!readTransform) {
_readTransform = SecTransformCreateReadTransformWithReadStream((__bridge CFReadStreamRef)readStream);
if (!_readTransform) {
if (error) {
*error = [SIGError errorWrapping:(__bridge NSError *)err
code:SIGErrorCodeAlgorithmCreationFailed
......@@ -61,10 +61,10 @@
return nil;
}
dataDigestTransform = SecDigestTransformCreate(kSecDigestSHA2,
_dataDigestTransform = SecDigestTransformCreate(kSecDigestSHA2,
256,
&err);
if (!dataDigestTransform) {
if (!_dataDigestTransform) {
if (error) {
*error = [SIGError errorWrapping:(__bridge NSError *)err
code:SIGErrorCodeAlgorithmCreationFailed
......@@ -73,9 +73,9 @@
return nil;
}
dataSignTransform = SecSignTransformCreate(privateKey.secKey,
_dataSignTransform = SecSignTransformCreate(privateKey.secKey,
&err);
if (!dataSignTransform) {
if (!_dataSignTransform) {
if (error) {
*error = [SIGError errorWrapping:(__bridge NSError *)err
code:SIGErrorCodeAlgorithmCreationFailed
......@@ -84,7 +84,7 @@
return nil;
}
SecTransformSetAttribute(dataSignTransform,
SecTransformSetAttribute(_dataSignTransform,
kSecInputIsAttributeName,
kSecInputIsDigest,
&err);
......@@ -97,7 +97,7 @@
return nil;
}
SecTransformSetAttribute(dataSignTransform,
SecTransformSetAttribute(_dataSignTransform,
kSecDigestTypeAttribute,
kSecDigestSHA2,
&err);
......@@ -110,7 +110,7 @@
return nil;
}
SecTransformSetAttribute(dataSignTransform,
SecTransformSetAttribute(_dataSignTransform,
kSecDigestLengthAttribute,
(__bridge CFTypeRef _Nonnull)@256,
&err);
......@@ -123,12 +123,12 @@
return nil;
}
group = SecTransformCreateGroupTransform();
SecTransformConnectTransforms(readTransform,
_group = SecTransformCreateGroupTransform();
SecTransformConnectTransforms(_readTransform,
kSecTransformOutputAttributeName,
dataDigestTransform,
_dataDigestTransform,
kSecTransformInputAttributeName,
group,
_group,
&err);
if (err != nil) {
if (error) {
......@@ -139,11 +139,11 @@
return nil;
}
SecTransformConnectTransforms(dataDigestTransform,
SecTransformConnectTransforms(_dataDigestTransform,
kSecTransformOutputAttributeName,
dataSignTransform,
_dataSignTransform,
kSecTransformInputAttributeName,
group,
_group,
&err);
if (err != nil) {
if (error) {
......@@ -154,7 +154,7 @@
return nil;
}
NSData *signature = (__bridge_transfer NSData *)SecTransformExecute(group, &err);
NSData *signature = (__bridge_transfer NSData *)SecTransformExecute(_group, &err);
if (err != nil) {
if (error) {
*error = [SIGError errorWrapping:(__bridge NSError *)err
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment