views:

99

answers:

1

I'd like to know if it is possible to hide library implementation from consumers of a static library.

This great thread spawned a few questions in regards to a licensing system for static libraries: http://stackoverflow.com/questions/1739373/licensing-system-for-static-library. The scheme I'd like to use is:

  • Give consumer a license key they put into a plist
  • plist is deployed
  • strong key is generated off of bundle identifier and matched against key in plist

Here is why that system is flawed: I need to run an algorithm (for strong key generation on the fly) that then outputs some string. The problem is I must include header files for the library to be used. At this point, anyone using the library can step into implementations. If I have a method named checkLicense(), a consumer of the library can step into that method and see how the strong key is being generated.

Also, for static methods, am I to run the key generation every time since there isn't any state? I could probably use a singleton and call it in each static method call?

My main problem is that implementation can be seen within a static library if you have the header files. Is there some way of hiding implementation?

+2  A: 

Assuming this static library you are creating is written in Objective-C, one method you could use is to create an anonymous category of your class in your implementation file (not your header). In that category, declare your sensitive methods and then just implement them in your class like normal. This makes it so you don't have to expose those methods in your public headers.

For example, in SomeClass.m:

@interface SomeClass (/*Secret stuff*/)
- (BOOL)validateRegistration:(NSData *)key;
@end


@implementation SomeClass

// Other methods....

- (BOOL)validateRegistration:(NSData *)key { /* ... */ }

@end

Notice that this is an anonymous category because I haven't given the category a name (that's just a comment inside the parentheses). This makes it so you don't have to declare a separate implementation block specifically for that category's implementation, which helps hide those methods a little further.

Marc W
From someone wanting to use the library, how do they access any function without the headers? If they type in [SomeClass DoThis], they don't get any code hints and the compiler complains about an undefined (undeclared?) class. Do you have a link explaining how that works?Actually, I think the 320 project from Joe Hewitt did it this way. No header files, yet you are able to use its methods. Do you have a link that discusses that technique? In that case, it isn't a library but a bundle correct?
4thSpace
Ah I think I misunderstood your question. I'm editing my response.
Marc W
Maybe I am doing something wrong but I can still step into the implementation of validateRegistration for example. I also have a header file declaring only the interface (otherwise it doesn't compile). No methods
4thSpace
Add the code you have to your original question?
Marc W
Actually, I don't think it is even that complicated. I had the host app in a subfolder of the static library project. Once I moved out all of the static library files into another folder, Xcode could not longer find them and I could not step into the implementation. I don't think the anonymous category is needed. Does that jive with you?
4thSpace
@4thSpace: It's not headers that allows source-level debugging, it's debug symbols. Even without those, however, it's possible to debug at the assembly level. Also, you can still call methods that aren't declared, though they are assumed to be variadic (http://developer.apple.com/mac/library/qa/qa2005/qa1405.html) and return an `id`.
outis
@outis: Thanks. I think at that point I probably just admit defeat. But for the extreme majority of anyone using the library, I believe the static library and strong key with plist will work fine. If you see a whole in the logic, please let me know.
4thSpace
By the way, will Apple reject an app using this type of library. If the key is invalid, a popup will appear probably rendering much of the app useless. Is that grounds for rejection?
4thSpace
No idea. Only the App Store reviewers at Apple would know.
Marc W