2 // secd-82-persistent-ref.c
5 // Copyright (c) 2013-2014 Apple Inc. All Rights Reserved.
9 #include <Security/Security.h>
11 #include "secd_regressions.h"
12 #include "SecdTestKeychainUtilities.h"
14 int secd_82_persistent_ref(int argc
, char *const *argv
)
18 /* custom keychain dir */
19 secd_test_setup_temp_keychain("secd_82_persistent_ref", NULL
);
21 CFMutableDictionaryRef attrs
;
22 CFMutableDictionaryRef query
;
29 attrs
= CFDictionaryCreateMutable( NULL
, 0, &kCFTypeDictionaryKeyCallBacks
, &kCFTypeDictionaryValueCallBacks
);
30 CFDictionarySetValue( attrs
, kSecClass
, kSecClassGenericPassword
);
31 CFDictionarySetValue( attrs
, kSecAttrAccessible
, kSecAttrAccessibleAlways
);
32 CFDictionarySetValue( attrs
, kSecAttrLabel
, CFSTR( "TestLabel" ) );
33 CFDictionarySetValue( attrs
, kSecAttrDescription
, CFSTR( "TestDescription" ) );
34 CFDictionarySetValue( attrs
, kSecAttrAccount
, CFSTR( "TestAccount" ) );
35 CFDictionarySetValue( attrs
, kSecAttrService
, CFSTR( "TestService" ) );
36 data
= CFDataCreate( NULL
, (const uint8_t *) "\x00\x01\x02", 3 );
37 CFDictionarySetValue( attrs
, kSecValueData
, data
);
40 is(SecItemAdd(attrs
, NULL
), errSecSuccess
);
43 query
= CFDictionaryCreateMutable( NULL
, 0, &kCFTypeDictionaryKeyCallBacks
, &kCFTypeDictionaryValueCallBacks
);
44 CFDictionarySetValue( query
, kSecClass
, kSecClassGenericPassword
);
45 CFDictionarySetValue( query
, kSecAttrSynchronizable
, kSecAttrSynchronizableAny
);;
46 CFDictionarySetValue( query
, kSecReturnAttributes
, kCFBooleanTrue
);
47 CFDictionarySetValue( query
, kSecReturnPersistentRef
, kCFBooleanTrue
);
48 CFDictionarySetValue( query
, kSecMatchLimit
, kSecMatchLimitAll
);
50 is(SecItemCopyMatching(query
, &result
), errSecSuccess
);
52 array
= (CFArrayRef
) result
;
54 n
= CFArrayGetCount( array
);
55 for( i
= 0; i
< n
; ++i
)
57 item
= (CFDictionaryRef
) CFArrayGetValueAtIndex(array
, i
);
59 ok((CFDataRef
) CFDictionaryGetValue(item
, kSecValuePersistentRef
));