Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add SecureEncoder support to PFFileObject #1768

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion Parse/Parse/Source/PFFileObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ __attribute__((unavailable("PFFile was renamed to PFFileObject. Please use it in
`PFFileObject` representes a file of binary data stored on the Parse servers.
This can be a image, video, or anything else that an application needs to reference in a non-relational way.
*/
@interface PFFileObject : NSObject
@interface PFFileObject : NSObject <NSSecureCoding>

/**
Class property required for NSSecureCoding: also it must return YES

@return Whether the class supports NSSecureCoding..
*/
+ (BOOL)supportsSecureCoding;

///--------------------------------------
#pragma mark - Creating a PFFileObject
Expand Down
20 changes: 20 additions & 0 deletions Parse/Parse/Source/PFFileObject.m
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@

@synthesize stagedFilePath = _stagedFilePath;

+ (BOOL)supportsSecureCoding { return YES; }

Check warning on line 54 in Parse/Parse/Source/PFFileObject.m

View check run for this annotation

Codecov / codecov/patch

Parse/Parse/Source/PFFileObject.m#L54

Added line #L54 was not covered by tests

///--------------------------------------
#pragma mark - Public
///--------------------------------------
Expand Down Expand Up @@ -503,6 +505,24 @@
return [Parse _currentManager].coreManager.fileController;
}

#pragma mark - NSSecureCoding

- (void)encodeWithCoder:(NSCoder *)coder {
PFEncoder *encoder = [PFEncoder objectEncoder];
__autoreleasing NSError *error;
NSDictionary *dict = [encoder encodeObject:self error:&error];
if (dict && error == nil) {
[coder encodeObject:dict];
}
}

Check warning on line 517 in Parse/Parse/Source/PFFileObject.m

View check run for this annotation

Codecov / codecov/patch

Parse/Parse/Source/PFFileObject.m#L510-L517

Added lines #L510 - L517 were not covered by tests

- (nullable instancetype)initWithCoder:(NSCoder *)coder {
NSDictionary *dict = [coder decodeObject];
PFDecoder *decoder = [PFDecoder objectDecoder];
PFFileObject *fileObject = [decoder decodeObject:dict];
return (fileObject.name && fileObject.url) ? fileObject : nil;
}

Check warning on line 524 in Parse/Parse/Source/PFFileObject.m

View check run for this annotation

Codecov / codecov/patch

Parse/Parse/Source/PFFileObject.m#L519-L524

Added lines #L519 - L524 were not covered by tests

@end

///--------------------------------------
Expand Down
Loading