From 0df633b3411265866c84e6793e2ed341717c2933 Mon Sep 17 00:00:00 2001 From: Danny Greg Date: Tue, 24 Aug 2010 11:58:23 +0100 Subject: [PATCH] Wrote a function to assign errors nicely. Not overly happy with this but it needs to be available to multiple classes. --- objc/CFobError.h | 3 ++- objc/CFobError.m | 18 ++++++++++++++++++ objc/cocoafob.xcodeproj/project.pbxproj | 8 ++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 objc/CFobError.m diff --git a/objc/CFobError.h b/objc/CFobError.h index 233933e..e7cbe4a 100644 --- a/objc/CFobError.h +++ b/objc/CFobError.h @@ -13,5 +13,6 @@ enum _CFobErrorCode { CFobErrorCodeCouldNotDecode = -2, CFobErrorCodeSigningFailed = -3, CFobErrorCodeCouldNotEncode = -4, - CFobErrorCodeInvalidKey = -5 }; + +void CFobAssignErrorWithDescriptionAndCode(NSError **err, NSString *description, NSInteger code); diff --git a/objc/CFobError.m b/objc/CFobError.m new file mode 100644 index 0000000..6058554 --- /dev/null +++ b/objc/CFobError.m @@ -0,0 +1,18 @@ +// +// CFobError.h +// cocoafob +// +// Created by Danny Greg on 24/08/2010. +// Copyright 2010 Realmac Software. All rights reserved. +// Licensed under CC Attribution Licence 3.0 +// + +#import "CFobError.h" + +#import "CFobLicVerifier.h" + +void CFobAssignErrorWithDescriptionAndCode(NSError **err, NSString *description, NSInteger code) +{ + if (err != NULL) + *err = [NSError errorWithDomain:[[NSBundle bundleForClass:[CFobLicVerifier class]] bundleIdentifier] code:code userInfo:[NSDictionary dictionaryWithObject:NSLocalizedStringFromTableInBundle(description, nil, [NSBundle bundleForClass:[CFobLicVerifier class]], nil) forKey:NSLocalizedDescriptionKey]]; +} diff --git a/objc/cocoafob.xcodeproj/project.pbxproj b/objc/cocoafob.xcodeproj/project.pbxproj index b62641d..b811426 100644 --- a/objc/cocoafob.xcodeproj/project.pbxproj +++ b/objc/cocoafob.xcodeproj/project.pbxproj @@ -24,6 +24,8 @@ 3035258E1223C01100AACD22 /* NSString+PECrypt.h in Headers */ = {isa = PBXBuildFile; fileRef = C7E3784D0F59DB15002061CD /* NSString+PECrypt.h */; }; 3035258F1223C01100AACD22 /* NSString-Base64Extensions.h in Headers */ = {isa = PBXBuildFile; fileRef = C7A731670F5F42D500D40AFE /* NSString-Base64Extensions.h */; }; 303525A81223C19D00AACD22 /* libcrypto.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 303524D01223BE4D00AACD22 /* libcrypto.dylib */; }; + 303526851223D4DA00AACD22 /* CFobError.h in Headers */ = {isa = PBXBuildFile; fileRef = 303526831223D4DA00AACD22 /* CFobError.h */; }; + 303526981223DC9600AACD22 /* CFobError.m in Sources */ = {isa = PBXBuildFile; fileRef = 303526971223DC9600AACD22 /* CFobError.m */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -32,6 +34,8 @@ 303524091223BB9600AACD22 /* CocoaFob-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "CocoaFob-Info.plist"; sourceTree = ""; }; 303524D01223BE4D00AACD22 /* libcrypto.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libcrypto.dylib; path = usr/lib/libcrypto.dylib; sourceTree = SDKROOT; }; 303524D61223BE6700AACD22 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; + 303526831223D4DA00AACD22 /* CFobError.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CFobError.h; sourceTree = ""; }; + 303526971223DC9600AACD22 /* CFobError.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CFobError.m; sourceTree = ""; }; 32A70AAB03705E1F00C91783 /* cocoafob_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cocoafob_Prefix.pch; sourceTree = ""; }; C6859EA3029092ED04C91782 /* cocoafob.1 */ = {isa = PBXFileReference; lastKnownFileType = text.man; path = cocoafob.1; sourceTree = ""; }; C7A731670F5F42D500D40AFE /* NSString-Base64Extensions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString-Base64Extensions.h"; sourceTree = ""; }; @@ -87,6 +91,8 @@ C7E3784A0F59DB15002061CD /* CFobLicVerifier.m */, 32A70AAB03705E1F00C91783 /* cocoafob_Prefix.pch */, 08FB7796FE84155DC02AAC07 /* cocoafob.m */, + 303526831223D4DA00AACD22 /* CFobError.h */, + 303526971223DC9600AACD22 /* CFobError.m */, ); name = Source; sourceTree = ""; @@ -169,6 +175,7 @@ 303525891223BFFF00AACD22 /* encoder.h in Headers */, 303524231223BCB500AACD22 /* CFobLicVerifier.h in Headers */, 303524241223BCBA00AACD22 /* CFobLicGenerator.h in Headers */, + 303526851223D4DA00AACD22 /* CFobError.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -233,6 +240,7 @@ 303524141223BC2200AACD22 /* NSData+PECrypt.m in Sources */, 303524151223BC2200AACD22 /* NSString+PECrypt.m in Sources */, 303524161223BC2200AACD22 /* NSString-Base64Extensions.m in Sources */, + 303526981223DC9600AACD22 /* CFobError.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; };