Files
firebase-ios-sdk/FirebaseInstallations/Source/Tests/Utils/FIRKeyedArchivingUtils.m
T
Nick Cooke ef636bd28f [v9] Remove GHA workflows that test with --use-libraries (#9463)
* Remove `--use-libraries` workflows

* [Will Revert] Run only the cron workflows

* Add ENABLE_TESTING_SEARCH_PATHS flag

* Add blank swift file to statically link Swift lib

* Link in swift for ABTesting, Crashlytics, and FIS test specs

* [skip ci] Revert "Link in swift for ABTesting, Crashlytics, and FIS test specs"

This reverts commit 95e4a492a8.

* [skip ci] Revert "Add blank swift file to statically link Swift lib"

This reverts commit 43555ecf88.

* [skip ci] Revert "Add ENABLE_TESTING_SEARCH_PATHS flag"

This reverts commit e551fbee1a.

* Bump macOS test version in ABTesting, CSH, and FIS specs

* Ignore warings in FIS tests

* Ignore messaging warnings in cron jobs

* [skip ci] Revert "[Will Revert] Run only the cron workflows"

This reverts commit b39eaee5bd.

* [skip ci] Revert "Ignore messaging warnings in cron jobs"

This reverts commit 8a3faabe99.

* Add `@unknown default` case for FCM's Swift enum build tests

* [skip ci] Fix typo
2022-03-23 06:08:14 -07:00

86 lines
3.2 KiB
Objective-C

/*
* Copyright 2019 Google
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#import "FirebaseInstallations/Source/Tests/Utils/FIRKeyedArchivingUtils.h"
@implementation FIRKeyedArchivingUtils
+ (nullable NSData *)archivedDataWithRootObject:(id)object error:(NSError **)outError {
NSData *archivedData;
if (@available(macOS 10.13, iOS 11.0, tvOS 11.0, *)) {
archivedData = [NSKeyedArchiver archivedDataWithRootObject:object
requiringSecureCoding:YES
error:outError];
} else {
@try {
NSMutableData *data = [NSMutableData data];
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
#pragma clang diagnostic pop
archiver.requiresSecureCoding = YES;
[archiver encodeObject:object forKey:NSKeyedArchiveRootObjectKey];
[archiver finishEncoding];
archivedData = [data copy];
} @catch (NSException *exception) {
if (outError) {
NSString *failureReason = [NSString stringWithFormat:@"Exception: %@", exception];
*outError = [NSError errorWithDomain:@"FIRKeyedArchivingUtils"
code:-1
userInfo:@{
NSLocalizedFailureReasonErrorKey : failureReason,
}];
}
}
}
return archivedData;
}
+ (nullable id)unarchivedObjectOfClass:(Class)class
fromData:(NSData *)data
error:(NSError **)outError {
id object;
if (@available(macOS 10.13, iOS 11.0, tvOS 11.0, *)) {
object = [NSKeyedUnarchiver unarchivedObjectOfClass:class fromData:data error:outError];
} else {
@try {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
#pragma clang diagnostic pop
unarchiver.requiresSecureCoding = YES;
object = [unarchiver decodeObjectOfClass:class forKey:NSKeyedArchiveRootObjectKey];
} @catch (NSException *exception) {
if (outError) {
NSString *failureReason = [NSString stringWithFormat:@"Exception: %@", exception];
*outError = [NSError errorWithDomain:@"FIRKeyedArchivingUtils"
code:-1
userInfo:@{
NSLocalizedFailureReasonErrorKey : failureReason,
}];
}
}
}
return object;
}
@end