Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1511)

Unified Diff: chrome/browser/keychain_mock_mac.cc

Issue 151176: Implement Add and Update for PasswordStoreMac.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/keychain_mock_mac.cc
===================================================================
--- chrome/browser/keychain_mock_mac.cc (revision 19737)
+++ chrome/browser/keychain_mock_mac.cc (working copy)
@@ -17,7 +17,8 @@
kSecAuthenticationTypeItemAttr,
kSecSecurityDomainItemAttr,
kSecCreationDateItemAttr,
- kSecNegativeItemAttr };
+ kSecNegativeItemAttr,
+ kSecCreatorItemAttr };
// Create the test keychain data storage.
keychain_attr_list_ = static_cast<SecKeychainAttributeList*>(
@@ -44,6 +45,9 @@
case kSecNegativeItemAttr:
data_size = sizeof(Boolean);
break;
+ case kSecCreatorItemAttr:
+ data_size = sizeof(OSType);
+ break;
}
if (data_size > 0) {
keychain_attr_list_[i].attr[j].length = data_size;
@@ -69,30 +73,37 @@
free(keychain_data_);
}
-int MockKeychain::IndexForTag(const SecKeychainAttributeList& attribute_list,
- UInt32 tag) {
+
+SecKeychainAttribute* MockKeychain::AttributeWithTag(
+ const SecKeychainAttributeList& attribute_list, UInt32 tag) {
+ int attribute_index = -1;
for (unsigned int i = 0; i < attribute_list.count; ++i) {
if (attribute_list.attr[i].tag == tag) {
- return i;
+ attribute_index = i;
+ break;
}
}
- DCHECK(false);
- return -1;
+ if (attribute_index == -1) {
+ NOTREACHED();
Mark Mentovai 2009/07/02 03:03:33 Do we really need the NOTREACHED? You documented
+ return NULL;
+ }
+ return &(attribute_list.attr[attribute_index]);
}
void MockKeychain::SetTestDataBytes(int item, UInt32 tag, const void* data,
size_t length) {
- int attribute_index = IndexForTag(keychain_attr_list_[item], tag);
- keychain_attr_list_[item].attr[attribute_index].length = length;
+ SecKeychainAttribute* attribute = AttributeWithTag(keychain_attr_list_[item],
+ tag);
+ attribute->length = length;
if (length > 0) {
- if (keychain_attr_list_[item].attr[attribute_index].data) {
- free(keychain_attr_list_[item].attr[attribute_index].data);
+ if (attribute->data) {
+ free(attribute->data);
}
- keychain_attr_list_[item].attr[attribute_index].data = malloc(length);
- CHECK(keychain_attr_list_[item].attr[attribute_index].data);
- memcpy(keychain_attr_list_[item].attr[attribute_index].data, data, length);
+ attribute->data = malloc(length);
+ CHECK(attribute->data);
+ memcpy(attribute->data, data, length);
} else {
- keychain_attr_list_[item].attr[attribute_index].data = NULL;
+ attribute->data = NULL;
}
}
@@ -101,33 +112,41 @@
}
void MockKeychain::SetTestDataPort(int item, UInt32 value) {
- int attribute_index = IndexForTag(keychain_attr_list_[item],
- kSecPortItemAttr);
- void* data = keychain_attr_list_[item].attr[attribute_index].data;
- *(static_cast<UInt32*>(data)) = value;
+ SecKeychainAttribute* attribute = AttributeWithTag(keychain_attr_list_[item],
+ kSecPortItemAttr);
+ UInt32* data = static_cast<UInt32*>(attribute->data);
+ *data = value;
}
void MockKeychain::SetTestDataProtocol(int item, SecProtocolType value) {
- int attribute_index = IndexForTag(keychain_attr_list_[item],
- kSecProtocolItemAttr);
- void* data = keychain_attr_list_[item].attr[attribute_index].data;
- *(static_cast<SecProtocolType*>(data)) = value;
+ SecKeychainAttribute* attribute = AttributeWithTag(keychain_attr_list_[item],
+ kSecProtocolItemAttr);
+ SecProtocolType* data = static_cast<SecProtocolType*>(attribute->data);
+ *data = value;
}
void MockKeychain::SetTestDataAuthType(int item, SecAuthenticationType value) {
- int attribute_index = IndexForTag(keychain_attr_list_[item],
- kSecAuthenticationTypeItemAttr);
- void* data = keychain_attr_list_[item].attr[attribute_index].data;
- *(static_cast<SecAuthenticationType*>(data)) = value;
+ SecKeychainAttribute* attribute = AttributeWithTag(
+ keychain_attr_list_[item], kSecAuthenticationTypeItemAttr);
+ SecAuthenticationType* data = static_cast<SecAuthenticationType*>(
+ attribute->data);
+ *data = value;
}
void MockKeychain::SetTestDataNegativeItem(int item, Boolean value) {
- int attribute_index = IndexForTag(keychain_attr_list_[item],
- kSecNegativeItemAttr);
- void* data = keychain_attr_list_[item].attr[attribute_index].data;
- *(static_cast<Boolean*>(data)) = value;
+ SecKeychainAttribute* attribute = AttributeWithTag(keychain_attr_list_[item],
+ kSecNegativeItemAttr);
+ Boolean* data = static_cast<Boolean*>(attribute->data);
+ *data = value;
}
+void MockKeychain::SetTestDataCreator(int item, OSType value) {
+ SecKeychainAttribute* attribute = AttributeWithTag(keychain_attr_list_[item],
+ kSecCreatorItemAttr);
+ OSType* data = static_cast<OSType*>(attribute->data);
+ *data = value;
+}
+
void MockKeychain::SetTestDataPasswordBytes(int item, const void* data,
size_t length) {
keychain_data_[item].length = length;
@@ -185,11 +204,19 @@
return errSecInvalidItemRef;
}
+ MockKeychain* mutable_this = const_cast<MockKeychain*>(this);
if (attrList) {
- NOTIMPLEMENTED();
+ for (UInt32 change_attr = 0; change_attr < attrList->count; ++change_attr) {
+ if (attrList->attr[change_attr].tag == kSecCreatorItemAttr) {
+ void* data = attrList->attr[change_attr].data;
+ mutable_this->SetTestDataCreator(item_index,
+ *(static_cast<OSType*>(data)));
+ } else {
+ NOTIMPLEMENTED();
+ }
+ }
}
if (data) {
- MockKeychain* mutable_this = const_cast<MockKeychain*>(this);
mutable_this->SetTestDataPasswordBytes(item_index, data, length);
}
return noErr;
@@ -212,10 +239,9 @@
for (unsigned int mock_item = 0; mock_item < item_count_; ++mock_item) {
bool mock_item_matches = true;
for (UInt32 search_attr = 0; search_attr < attrList->count; ++search_attr) {
- int mock_attr = IndexForTag(keychain_attr_list_[mock_item],
- attrList->attr[search_attr].tag);
SecKeychainAttribute* mock_attribute =
- &(keychain_attr_list_[mock_item].attr[mock_attr]);
+ AttributeWithTag(keychain_attr_list_[mock_item],
+ attrList->attr[search_attr].tag);
if (mock_attribute->length != attrList->attr[search_attr].length ||
memcmp(mock_attribute->data, attrList->attr[search_attr].data,
attrList->attr[search_attr].length) != 0) {
@@ -277,8 +303,11 @@
mutable_this->SetTestDataString(target_item, kSecCreationDateItemAttr,
time_string);
+ added_via_api_.insert(target_item);
+
if (itemRef) {
*itemRef = reinterpret_cast<SecKeychainItemRef>(target_item + 1);
+ ++keychain_item_copy_count_;
}
return noErr;
}
@@ -319,6 +348,19 @@
return attribute_data_copy_count_;
}
+bool MockKeychain::CreatorCodesSetForAddedItems() const {
+ for (std::set<unsigned int>::const_iterator i = added_via_api_.begin();
+ i != added_via_api_.end(); ++i) {
+ SecKeychainAttribute* attribute = AttributeWithTag(keychain_attr_list_[*i],
+ kSecCreatorItemAttr);
+ OSType* data = static_cast<OSType*>(attribute->data);
+ if (*data == 0) {
Mark Mentovai 2009/07/02 03:03:33 Oh yeah. Much clearer this way.
+ return false;
+ }
+ }
+ return true;
+}
+
void MockKeychain::AddTestItem(const KeychainTestData& item_data) {
unsigned int index = item_count_++;
CHECK(index < item_capacity_);

Powered by Google App Engine
This is Rietveld 408576698