Start implementing some secure coding methods.

This commit is contained in:
Gregory John Casamento 2020-04-24 03:59:17 -04:00
parent a9767cdff7
commit 082f87fbc3
2 changed files with 32 additions and 0 deletions

View file

@ -87,6 +87,16 @@ extern "C" {
*/
+ (NSData*) archivedDataWithRootObject: (id)anObject;
/**
* 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;
/**
* Encodes anObject and writes the resulting data ti aPath.
*/

View file

@ -460,6 +460,28 @@ static NSDictionary *makeReference(unsigned ref)
return AUTORELEASE(d);
}
+ (NSData *) archivedDataWithRootObject: (id)anObject
requiringSecureCoding: (BOOL)requiresSecureCoding
error: (NSError **)error
{
NSData *data = nil;
if (requiresSecureCoding == YES)
{
*error = [NSError errorWithDomain: @"NSKeyedArchiver"
code: 0
userInfo: [NSDictionary dictionaryWithObjectsAndKeys:
@"Could not create secure keyed archive",
NSLocalizedDescriptionKey, nil]];
}
else
{
error = NULL;
data = [self archivedDataWithRootObject: anObject];
}
return data;
}
+ (BOOL) archiveRootObject: (id)anObject toFile: (NSString*)aPath
{
NSAutoreleasePool *pool = [NSAutoreleasePool new];