I'm learning about the NSSecureCoding
protocol introduced by Apple in iOS 6.
From my understanding so far, it should be used whenever a class encodes/decodes instances of itself, in order to prevent substitution attacks.
I'm wondering whether it would be appropriate to use it in other cases.
Specifically if a class conforms to NSCoding
by encoding/decoding its instance variables, as opposed to the whole instance of itself, would it still be advisable to implement NSSecureCoding
?
EDIT
Suppose I have a class that is implementing NSCoding
like follows
- (void)encodeWithCoder:(NSCoder *)encoder {
[encoder encodeObject:self.aString forKey:@"aMeaningfulString"];
}
- (id)initWithCoder:(NSCoder *)decoder {
if((self = [super init])) {
self.aString = [decoder decodeObjectForKey:@"aMeaningfulString"];
}
return self;
}
and suppose also that no XPC is involved. Instances of this class will be archived in a plist stored on disk.
Security-wise, is there any benefit in using -decodeObjectOfClass:forKey:
as opposed to
-decodeObjectForKey:
?