mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 08:21:25 +00:00
Merge pull request #133 from gnustep/NSSecureCoding_branch
Start implementing some secure coding methods.
This commit is contained in:
commit
de0282fdac
2 changed files with 49 additions and 22 deletions
|
@ -87,6 +87,18 @@ extern "C" {
|
||||||
*/
|
*/
|
||||||
+ (NSData*) archivedDataWithRootObject: (id)anObject;
|
+ (NSData*) archivedDataWithRootObject: (id)anObject;
|
||||||
|
|
||||||
|
|
||||||
|
#if OS_API_VERSION(MAC_OS_X_VERSION_10_13,GS_API_LATEST)
|
||||||
|
/**
|
||||||
|
* Encodes anObject and returns the resulting data object. Allows
|
||||||
|
* secure coding if specified. Returns an error if an object
|
||||||
|
* violates secure coding rules.
|
||||||
|
*/
|
||||||
|
+ (NSData *) archivedDataWithRootObject: (id)anObject
|
||||||
|
requiringSecureCoding: (BOOL)requiresSecureCoding
|
||||||
|
error: (NSError **)error;
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encodes anObject and writes the resulting data ti aPath.
|
* Encodes anObject and writes the resulting data ti aPath.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -430,16 +430,18 @@ static NSDictionary *makeReference(unsigned ref)
|
||||||
|
|
||||||
@implementation NSKeyedArchiver
|
@implementation NSKeyedArchiver
|
||||||
|
|
||||||
/*
|
+ (NSData *) archivedDataWithRootObject: (id)anObject
|
||||||
* When I tried this on MacOS 10.3 it encoded the object with the key 'root',
|
requiringSecureCoding: (BOOL)requiresSecureCoding
|
||||||
* so this implementation does the same.
|
error: (NSError **)error
|
||||||
*/
|
|
||||||
+ (NSData*) archivedDataWithRootObject: (id)anObject
|
|
||||||
{
|
{
|
||||||
NSMutableData *m = nil;
|
|
||||||
NSKeyedArchiver *a = nil;
|
|
||||||
NSData *d = nil;
|
NSData *d = nil;
|
||||||
|
|
||||||
|
if (requiresSecureCoding == NO)
|
||||||
|
{
|
||||||
|
NSMutableData *m = nil;
|
||||||
|
NSKeyedArchiver *a = nil;
|
||||||
|
|
||||||
|
error = NULL;
|
||||||
NS_DURING
|
NS_DURING
|
||||||
{
|
{
|
||||||
m = [[NSMutableData alloc] initWithCapacity: 10240];
|
m = [[NSMutableData alloc] initWithCapacity: 10240];
|
||||||
|
@ -456,10 +458,23 @@ static NSDictionary *makeReference(unsigned ref)
|
||||||
DESTROY(a);
|
DESTROY(a);
|
||||||
[localException raise];
|
[localException raise];
|
||||||
}
|
}
|
||||||
NS_ENDHANDLER
|
NS_ENDHANDLER;
|
||||||
|
}
|
||||||
|
|
||||||
return AUTORELEASE(d);
|
return AUTORELEASE(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* When I tried this on MacOS 10.3 it encoded the object with the key 'root',
|
||||||
|
* so this implementation does the same.
|
||||||
|
*/
|
||||||
|
+ (NSData*) archivedDataWithRootObject: (id)anObject
|
||||||
|
{
|
||||||
|
return [self archivedDataWithRootObject: anObject
|
||||||
|
requiringSecureCoding: NO
|
||||||
|
error: NULL];
|
||||||
|
}
|
||||||
|
|
||||||
+ (BOOL) archiveRootObject: (id)anObject toFile: (NSString*)aPath
|
+ (BOOL) archiveRootObject: (id)anObject toFile: (NSString*)aPath
|
||||||
{
|
{
|
||||||
NSAutoreleasePool *pool = [NSAutoreleasePool new];
|
NSAutoreleasePool *pool = [NSAutoreleasePool new];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue