]> git.saurik.com Git - apple/hfs.git/blame - tests/cases/test-transcode.m
hfs-366.70.1.tar.gz
[apple/hfs.git] / tests / cases / test-transcode.m
CommitLineData
558d2836
A
1//
2// test-transcode.m
3// hfs
4//
5// Created by Chris Suter on 8/21/15.
6//
7//
8
9#import <TargetConditionals.h>
10
11#if TARGET_OS_EMBEDDED
12
13#import <fcntl.h>
14#import <MobileKeyBag/MobileKeyBag.h>
15#import <Foundation/Foundation.h>
16#import <sys/param.h>
17#import <sys/mount.h>
18
19#import "hfs-tests.h"
20#import "test-utils.h"
21
22TEST(transcode)
23
24#define TEST_FILE "/tmp/transcode-test.file"
25
26int run_transcode(__unused test_ctx_t *ctx)
27{
28 // The root file system needs to be HFS
29 struct statfs sfs;
30
31 assert(statfs("/tmp", &sfs) == 0);
32 if (strcmp(sfs.f_fstypename, "hfs")) {
33 printf("transcode needs hfs as root file system.\n");
34 return 0;
35 }
36
37 MKBKeyBagHandleRef handle;
38 CFDataRef data;
39
40 assert_no_err(MKBKeyBagCreateOTABackup(NULL, &handle));
41 assert_no_err(MKBKeyBagCopyData(handle, &data));
42 assert_no_err(MKBKeyBagRegisterOTABackup(data, NULL));
43
44 unlink(TEST_FILE);
45 int fd = open_dprotected_np(TEST_FILE, O_RDWR | O_CREAT,
46 1, 0, 0666);
47
48 assert_with_errno(fd >= 0);
49
50 char *key = malloc(1024);
51 int res = fcntl(fd, F_TRANSCODEKEY, key);
52
53 assert_with_errno(res != -1);
54
55 // Keys should be at least 16 bytes
56 assert(res >= 16);
57
58 assert_no_err(unlink(TEST_FILE));
59
60 assert_no_err(MKBKeyBagRegisterOTABackup(NULL, NULL));
61 assert_no_err(MKBKeyBagRelease(handle));
62
63 return 0;
64}
65
66#endif