]> git.saurik.com Git - apple/security.git/blob - Keychain/EditItemViewController.m
Security-57031.1.35.tar.gz
[apple/security.git] / Keychain / EditItemViewController.m
1 //
2 // EditItemViewController.m
3 // Security
4 //
5 // Created by john on 10/24/12.
6 //
7 //
8
9 #import "EditItemViewController.h"
10 #import "MyKeychain.h"
11 //#import <regressions/SOSRegressionUtilities.h>
12 //#import <SOSCircle/Regressions/SOSRegressionUtilities.h>
13 #import <CKBridge/SOSCloudKeychainClient.h>
14 #import <CKBridge/SOSCloudKeychainConstants.h>
15 #include "utilities.h"
16
17 static const CFStringRef kAddItemKeyY = CFSTR("AddItem");
18
19
20 @interface EditItemViewController ()
21
22 @end
23
24 @implementation EditItemViewController
25
26 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
27 {
28 self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
29 if (self) {
30 // Custom initialization
31 }
32 return self;
33 }
34
35 - (void)viewDidLoad
36 {
37 [super viewDidLoad];
38 // Do any additional setup after loading the view.
39 NSLog(@"_itemDetailModel: %@", _itemDetailModel);
40
41 dgroup = dispatch_group_create();
42 xpc_queue = dispatch_queue_create("EditItemViewController", DISPATCH_QUEUE_CONCURRENT);
43 _itemName.text = [_itemDetailModel objectForKey:(__bridge id)(kSecAttrService)];
44 _itemAccount.text = [_itemDetailModel objectForKey:(__bridge id)(kSecAttrAccount)];
45 // _itemPassword.text = @"TODO";//[_itemDetailModel objectForKey:(__bridge id)(kSecValueData)];
46 NSData *pwdData = [_itemDetailModel objectForKey:(__bridge id)(kSecValueData)];
47 if (pwdData)
48 {
49 NSString *pwd = [[NSString alloc] initWithData:pwdData encoding:NSUTF8StringEncoding];
50 _itemPassword.text = pwd;
51 }
52 else
53 _itemPassword.text = @"";
54
55 }
56
57 - (void)didReceiveMemoryWarning
58 {
59 [super didReceiveMemoryWarning];
60 // Dispose of any resources that can be recreated.
61 }
62
63 - (void)postToCloud:(NSDictionary *)kcitem
64 {
65 CFErrorRef error = NULL;
66 testPutObjectInCloud(kAddItemKeyY, (__bridge CFTypeRef)(kcitem), &error, dgroup, xpc_queue);
67 NSLog(@"NOT IMPLEMENTED: Sent new item to cloud: %@", kcitem);
68 }
69
70 - (IBAction)handlePasswordEditDone:(id)sender
71 {
72 NSLog(@"handlePasswordEditDone");
73
74 NSMutableDictionary *newItem = [NSMutableDictionary dictionaryWithCapacity:0];
75 [newItem setObject:[_itemPassword text] forKey:kItemPasswordKey];
76 [newItem setObject:[_itemAccount text] forKey:kItemAccountKey];
77 [newItem setObject:[_itemName text] forKey:kItemNameKey];
78
79 [[MyKeychain sharedInstance] setItem:newItem];
80 [self postToCloud:newItem];
81 }
82
83
84 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
85 {
86 NSLog(@"prepareForSegue EditDone");
87 if ([[segue identifier] isEqualToString:@"EditDone"])
88 {
89 NSLog(@"seque EditDone");
90 [self handlePasswordEditDone:NULL];
91 }
92 }
93
94 @end