From 314f437f43ae028705538dc394d2757d505e0796 Mon Sep 17 00:00:00 2001 From: Daniel Ferreira Date: Sun, 25 Jun 2017 06:35:23 +1000 Subject: [PATCH] NSCoder: implement NSSecureCoding stub Implement stubs for NSSecureCoding which do not break projects that rely on it. --- Headers/Foundation/NSCoder.h | 17 +++++++++++++++++ Headers/Foundation/NSObject.h | 4 ++++ Source/NSCoder.m | 24 ++++++++++++++++++++++++ Source/NSKeyedUnarchiver.m | 15 +++++++++++++++ 4 files changed, 60 insertions(+) diff --git a/Headers/Foundation/NSCoder.h b/Headers/Foundation/NSCoder.h index 05102e128..189def839 100644 --- a/Headers/Foundation/NSCoder.h +++ b/Headers/Foundation/NSCoder.h @@ -28,6 +28,7 @@ #import #import +#import #import #if defined(__cplusplus) @@ -303,6 +304,8 @@ extern "C" { */ - (id) decodeObjectForKey: (NSString*)aKey; + + /** * Encodes aBool and associates the encoded value with aKey. */ @@ -363,6 +366,20 @@ extern "C" { * Decodes an NSInteger associated with the key. */ - (NSInteger) decodeIntegerForKey: (NSString *)key; +#endif + +#if OS_API_VERSION(MAC_OS_X_VERSION_10_8, GS_API_LATEST) + +#if GS_HAS_DECLARED_PROPERTIES +@property (nonatomic, assign) BOOL requiresSecureCoding; +#else +- (BOOL) requiresSecureCoding; +- (void) setRequiresSecureCoding: (BOOL)requires; +#endif + +- (id) decodeObjectOfClass: (Class)cls forKey: (NSString *)key; +- (id) decodeObjectOfClasses: (NSSet *)classes forKey: (NSString *)key; + #endif @end diff --git a/Headers/Foundation/NSObject.h b/Headers/Foundation/NSObject.h index 377bd4e0e..6cbb52d47 100644 --- a/Headers/Foundation/NSObject.h +++ b/Headers/Foundation/NSObject.h @@ -283,6 +283,10 @@ extern "C" { - (id) initWithCoder: (NSCoder*)aDecoder; @end +@protocol NSSecureCoding ++ (BOOL)supportsSecureCoding; +@end + GS_ROOT_CLASS @interface NSObject { diff --git a/Source/NSCoder.m b/Source/NSCoder.m index 004958e3c..9a097ba85 100644 --- a/Source/NSCoder.m +++ b/Source/NSCoder.m @@ -35,6 +35,7 @@ #define EXPOSE_NSCoder_IVARS 1 #import "Foundation/NSData.h" #import "Foundation/NSCoder.h" +#import "Foundation/NSSet.h" #import "Foundation/NSSerialization.h" #import "Foundation/NSUserDefaults.h" @@ -331,6 +332,17 @@ static unsigned systemVersion = MAX_SUPPORTED_SYSTEM_VERSION; // Keyed archiving extensions +- (BOOL) requiresSecureCoding +{ + [self subclassResponsibility: _cmd]; + return NO; +} + +- (void) setRequiresSecureCoding: (BOOL)secure +{ + [self subclassResponsibility: _cmd]; +} + - (BOOL) allowsKeyedCoding { return NO; @@ -397,6 +409,18 @@ static unsigned systemVersion = MAX_SUPPORTED_SYSTEM_VERSION; return nil; } +- (id) decodeObjectOfClass: (Class)cls forKey: (NSString *)aKey +{ + return [self decodeObjectOfClasses: [NSSet setWithObject:(id)cls] + forKey: aKey]; +} + +- (id) decodeObjectOfClasses: (NSSet *)classes forKey: (NSString *)aKey +{ + [self subclassResponsibility: _cmd]; + return nil; +} + - (void) encodeBool: (BOOL) aBool forKey: (NSString*)aKey { [self subclassResponsibility: _cmd]; diff --git a/Source/NSKeyedUnarchiver.m b/Source/NSKeyedUnarchiver.m index 9695b329d..87de3db3a 100644 --- a/Source/NSKeyedUnarchiver.m +++ b/Source/NSKeyedUnarchiver.m @@ -365,6 +365,16 @@ static NSMapTable *globalClassMap = 0; return YES; } +- (BOOL)requiresSecureCoding +{ + return NO; +} + +- (void)setRequiresSecureCoding: (BOOL)secure +{ + return; +} + - (Class) classForClassName: (NSString*)aString { return _clsMap == 0 ? Nil : (Class)NSMapGet(_clsMap, (void*)aString); @@ -636,6 +646,11 @@ static NSMapTable *globalClassMap = 0; return nil; } +- (id) decodeObjectOfClasses: (NSSet *)classes forKey: (NSString *)key +{ + return [self decodeObjectForKey: key]; +} + - (NSPoint) decodePoint { NSPoint p;