Commit d22db52b authored by mmaerean@adobe.com's avatar mmaerean@adobe.com

src/crypto should build on the x86_64 architecture.

This patch solves the build issues that are directly related to building crypto for the x86_64 architecture.

BUG=136072

Review URL: https://chromiumcodereview.appspot.com/10738003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@149047 0039d316-1c4b-4281-b951-d872f2087c98
parent 6684dc81
...@@ -8,6 +8,10 @@ ...@@ -8,6 +8,10 @@
namespace crypto { namespace crypto {
// static
const SecKeychainSearchRef MockKeychain::kDummySearchRef =
reinterpret_cast<SecKeychainSearchRef>(1000);
MockKeychain::MockKeychain() MockKeychain::MockKeychain()
: next_item_key_(0), : next_item_key_(0),
search_copy_count_(0), search_copy_count_(0),
...@@ -17,7 +21,7 @@ MockKeychain::MockKeychain() ...@@ -17,7 +21,7 @@ MockKeychain::MockKeychain()
called_add_generic_(false), called_add_generic_(false),
password_data_count_(0) {} password_data_count_(0) {}
void MockKeychain::InitializeKeychainData(unsigned int key) const { void MockKeychain::InitializeKeychainData(MockKeychainItemType key) const {
UInt32 tags[] = { kSecAccountItemAttr, UInt32 tags[] = { kSecAccountItemAttr,
kSecServerItemAttr, kSecServerItemAttr,
kSecPortItemAttr, kSecPortItemAttr,
...@@ -61,7 +65,7 @@ void MockKeychain::InitializeKeychainData(unsigned int key) const { ...@@ -61,7 +65,7 @@ void MockKeychain::InitializeKeychainData(unsigned int key) const {
} }
MockKeychain::~MockKeychain() { MockKeychain::~MockKeychain() {
for (std::map<unsigned int, SecKeychainAttributeList>::iterator it = for (std::map<MockKeychainItemType, SecKeychainAttributeList>::iterator it =
keychain_attr_list_.begin(); it != keychain_attr_list_.end(); ++it) { keychain_attr_list_.begin(); it != keychain_attr_list_.end(); ++it) {
for (unsigned int i = 0; i < it->second.count; ++i) { for (unsigned int i = 0; i < it->second.count; ++i) {
if (it->second.attr[i].data) if (it->second.attr[i].data)
...@@ -92,7 +96,7 @@ SecKeychainAttribute* MockKeychain::AttributeWithTag( ...@@ -92,7 +96,7 @@ SecKeychainAttribute* MockKeychain::AttributeWithTag(
return &(attribute_list.attr[attribute_index]); return &(attribute_list.attr[attribute_index]);
} }
void MockKeychain::SetTestDataBytes(int item, void MockKeychain::SetTestDataBytes(MockKeychainItemType item,
UInt32 tag, UInt32 tag,
const void* data, const void* data,
size_t length) { size_t length) {
...@@ -110,25 +114,31 @@ void MockKeychain::SetTestDataBytes(int item, ...@@ -110,25 +114,31 @@ void MockKeychain::SetTestDataBytes(int item,
} }
} }
void MockKeychain::SetTestDataString(int item, UInt32 tag, const char* value) { void MockKeychain::SetTestDataString(
MockKeychainItemType item,
UInt32 tag,
const char* value) {
SetTestDataBytes(item, tag, value, value ? strlen(value) : 0); SetTestDataBytes(item, tag, value, value ? strlen(value) : 0);
} }
void MockKeychain::SetTestDataPort(int item, UInt32 value) { void MockKeychain::SetTestDataPort(MockKeychainItemType item, UInt32 value) {
SecKeychainAttribute* attribute = AttributeWithTag(keychain_attr_list_[item], SecKeychainAttribute* attribute = AttributeWithTag(keychain_attr_list_[item],
kSecPortItemAttr); kSecPortItemAttr);
UInt32* data = static_cast<UInt32*>(attribute->data); UInt32* data = static_cast<UInt32*>(attribute->data);
*data = value; *data = value;
} }
void MockKeychain::SetTestDataProtocol(int item, SecProtocolType value) { void MockKeychain::SetTestDataProtocol(MockKeychainItemType item,
SecProtocolType value) {
SecKeychainAttribute* attribute = AttributeWithTag(keychain_attr_list_[item], SecKeychainAttribute* attribute = AttributeWithTag(keychain_attr_list_[item],
kSecProtocolItemAttr); kSecProtocolItemAttr);
SecProtocolType* data = static_cast<SecProtocolType*>(attribute->data); SecProtocolType* data = static_cast<SecProtocolType*>(attribute->data);
*data = value; *data = value;
} }
void MockKeychain::SetTestDataAuthType(int item, SecAuthenticationType value) { void MockKeychain::SetTestDataAuthType(
MockKeychainItemType item,
SecAuthenticationType value) {
SecKeychainAttribute* attribute = AttributeWithTag( SecKeychainAttribute* attribute = AttributeWithTag(
keychain_attr_list_[item], kSecAuthenticationTypeItemAttr); keychain_attr_list_[item], kSecAuthenticationTypeItemAttr);
SecAuthenticationType* data = static_cast<SecAuthenticationType*>( SecAuthenticationType* data = static_cast<SecAuthenticationType*>(
...@@ -136,21 +146,23 @@ void MockKeychain::SetTestDataAuthType(int item, SecAuthenticationType value) { ...@@ -136,21 +146,23 @@ void MockKeychain::SetTestDataAuthType(int item, SecAuthenticationType value) {
*data = value; *data = value;
} }
void MockKeychain::SetTestDataNegativeItem(int item, Boolean value) { void MockKeychain::SetTestDataNegativeItem(MockKeychainItemType item,
Boolean value) {
SecKeychainAttribute* attribute = AttributeWithTag(keychain_attr_list_[item], SecKeychainAttribute* attribute = AttributeWithTag(keychain_attr_list_[item],
kSecNegativeItemAttr); kSecNegativeItemAttr);
Boolean* data = static_cast<Boolean*>(attribute->data); Boolean* data = static_cast<Boolean*>(attribute->data);
*data = value; *data = value;
} }
void MockKeychain::SetTestDataCreator(int item, OSType value) { void MockKeychain::SetTestDataCreator(MockKeychainItemType item, OSType value) {
SecKeychainAttribute* attribute = AttributeWithTag(keychain_attr_list_[item], SecKeychainAttribute* attribute = AttributeWithTag(keychain_attr_list_[item],
kSecCreatorItemAttr); kSecCreatorItemAttr);
OSType* data = static_cast<OSType*>(attribute->data); OSType* data = static_cast<OSType*>(attribute->data);
*data = value; *data = value;
} }
void MockKeychain::SetTestDataPasswordBytes(int item, const void* data, void MockKeychain::SetTestDataPasswordBytes(MockKeychainItemType item,
const void* data,
size_t length) { size_t length) {
keychain_data_[item].length = length; keychain_data_[item].length = length;
if (length > 0) { if (length > 0) {
...@@ -163,7 +175,9 @@ void MockKeychain::SetTestDataPasswordBytes(int item, const void* data, ...@@ -163,7 +175,9 @@ void MockKeychain::SetTestDataPasswordBytes(int item, const void* data,
} }
} }
void MockKeychain::SetTestDataPasswordString(int item, const char* value) { void MockKeychain::SetTestDataPasswordString(
MockKeychainItemType item,
const char* value) {
SetTestDataPasswordBytes(item, value, value ? strlen(value) : 0); SetTestDataPasswordBytes(item, value, value ? strlen(value) : 0);
} }
...@@ -175,7 +189,8 @@ OSStatus MockKeychain::ItemCopyAttributesAndData( ...@@ -175,7 +189,8 @@ OSStatus MockKeychain::ItemCopyAttributesAndData(
UInt32* length, UInt32* length,
void** outData) const { void** outData) const {
DCHECK(itemRef); DCHECK(itemRef);
unsigned int key = reinterpret_cast<unsigned int>(itemRef) - 1; MockKeychainItemType key =
reinterpret_cast<MockKeychainItemType>(itemRef) - 1;
if (keychain_attr_list_.find(key) == keychain_attr_list_.end()) if (keychain_attr_list_.find(key) == keychain_attr_list_.end())
return errSecInvalidItemRef; return errSecInvalidItemRef;
...@@ -204,7 +219,8 @@ OSStatus MockKeychain::ItemModifyAttributesAndData( ...@@ -204,7 +219,8 @@ OSStatus MockKeychain::ItemModifyAttributesAndData(
return errSecAuthFailed; return errSecAuthFailed;
} }
unsigned int key = reinterpret_cast<unsigned int>(itemRef) - 1; MockKeychainItemType key =
reinterpret_cast<MockKeychainItemType>(itemRef) - 1;
if (keychain_attr_list_.find(key) == keychain_attr_list_.end()) if (keychain_attr_list_.find(key) == keychain_attr_list_.end())
return errSecInvalidItemRef; return errSecInvalidItemRef;
...@@ -232,7 +248,8 @@ OSStatus MockKeychain::ItemFreeAttributesAndData( ...@@ -232,7 +248,8 @@ OSStatus MockKeychain::ItemFreeAttributesAndData(
} }
OSStatus MockKeychain::ItemDelete(SecKeychainItemRef itemRef) const { OSStatus MockKeychain::ItemDelete(SecKeychainItemRef itemRef) const {
unsigned int key = reinterpret_cast<unsigned int>(itemRef) - 1; MockKeychainItemType key =
reinterpret_cast<MockKeychainItemType>(itemRef) - 1;
for (unsigned int i = 0; i < keychain_attr_list_[key].count; ++i) { for (unsigned int i = 0; i < keychain_attr_list_[key].count; ++i) {
if (keychain_attr_list_[key].attr[i].data) if (keychain_attr_list_[key].attr[i].data)
...@@ -256,8 +273,10 @@ OSStatus MockKeychain::SearchCreateFromAttributes( ...@@ -256,8 +273,10 @@ OSStatus MockKeychain::SearchCreateFromAttributes(
// Figure out which of our mock items matches, and set up the array we'll use // Figure out which of our mock items matches, and set up the array we'll use
// to generate results out of SearchCopyNext. // to generate results out of SearchCopyNext.
remaining_search_results_.clear(); remaining_search_results_.clear();
for (std::map<unsigned int, SecKeychainAttributeList>::const_iterator it = for (std::map<MockKeychainItemType, SecKeychainAttributeList>::const_iterator
keychain_attr_list_.begin(); it != keychain_attr_list_.end(); ++it) { it = keychain_attr_list_.begin();
it != keychain_attr_list_.end();
++it) {
bool mock_item_matches = true; bool mock_item_matches = true;
for (UInt32 search_attr = 0; search_attr < attrList->count; ++search_attr) { for (UInt32 search_attr = 0; search_attr < attrList->count; ++search_attr) {
SecKeychainAttribute* mock_attribute = SecKeychainAttribute* mock_attribute =
...@@ -274,7 +293,7 @@ OSStatus MockKeychain::SearchCreateFromAttributes( ...@@ -274,7 +293,7 @@ OSStatus MockKeychain::SearchCreateFromAttributes(
} }
DCHECK(searchRef); DCHECK(searchRef);
*searchRef = reinterpret_cast<SecKeychainSearchRef>(kDummySearchRef); *searchRef = kDummySearchRef;
++search_copy_count_; ++search_copy_count_;
return noErr; return noErr;
} }
...@@ -291,8 +310,10 @@ bool MockKeychain::AlreadyContainsInternetPassword( ...@@ -291,8 +310,10 @@ bool MockKeychain::AlreadyContainsInternetPassword(
UInt16 port, UInt16 port,
SecProtocolType protocol, SecProtocolType protocol,
SecAuthenticationType authenticationType) const { SecAuthenticationType authenticationType) const {
for (std::map<unsigned int, SecKeychainAttributeList>::const_iterator it = for (std::map<MockKeychainItemType, SecKeychainAttributeList>::const_iterator
keychain_attr_list_.begin(); it != keychain_attr_list_.end(); ++it) { it = keychain_attr_list_.begin();
it != keychain_attr_list_.end();
++it) {
SecKeychainAttribute* attribute; SecKeychainAttribute* attribute;
attribute = AttributeWithTag(it->second, kSecServerItemAttr); attribute = AttributeWithTag(it->second, kSecServerItemAttr);
if ((attribute->length != serverNameLength) || if ((attribute->length != serverNameLength) ||
...@@ -385,7 +406,7 @@ OSStatus MockKeychain::AddInternetPassword( ...@@ -385,7 +406,7 @@ OSStatus MockKeychain::AddInternetPassword(
} }
// Pick the next unused slot. // Pick the next unused slot.
unsigned int key = next_item_key_++; MockKeychainItemType key = next_item_key_++;
// Initialize keychain data storage at the target location. // Initialize keychain data storage at the target location.
InitializeKeychainData(key); InitializeKeychainData(key);
...@@ -424,7 +445,7 @@ OSStatus MockKeychain::SearchCopyNext(SecKeychainSearchRef searchRef, ...@@ -424,7 +445,7 @@ OSStatus MockKeychain::SearchCopyNext(SecKeychainSearchRef searchRef,
SecKeychainItemRef* itemRef) const { SecKeychainItemRef* itemRef) const {
if (remaining_search_results_.empty()) if (remaining_search_results_.empty())
return errSecItemNotFound; return errSecItemNotFound;
unsigned int key = remaining_search_results_.front(); MockKeychainItemType key = remaining_search_results_.front();
remaining_search_results_.erase(remaining_search_results_.begin()); remaining_search_results_.erase(remaining_search_results_.begin());
*itemRef = reinterpret_cast<SecKeychainItemRef>(key + 1); *itemRef = reinterpret_cast<SecKeychainItemRef>(key + 1);
++keychain_item_copy_count_; ++keychain_item_copy_count_;
...@@ -483,7 +504,7 @@ void MockKeychain::Free(CFTypeRef ref) const { ...@@ -483,7 +504,7 @@ void MockKeychain::Free(CFTypeRef ref) const {
if (!ref) if (!ref)
return; return;
if (reinterpret_cast<int>(ref) == kDummySearchRef) { if (ref == kDummySearchRef) {
--search_copy_count_; --search_copy_count_;
} else { } else {
--keychain_item_copy_count_; --keychain_item_copy_count_;
...@@ -503,8 +524,10 @@ int MockKeychain::UnfreedAttributeDataCount() const { ...@@ -503,8 +524,10 @@ int MockKeychain::UnfreedAttributeDataCount() const {
} }
bool MockKeychain::CreatorCodesSetForAddedItems() const { bool MockKeychain::CreatorCodesSetForAddedItems() const {
for (std::set<unsigned int>::const_iterator i = added_via_api_.begin(); for (std::set<MockKeychainItemType>::const_iterator
i != added_via_api_.end(); ++i) { i = added_via_api_.begin();
i != added_via_api_.end();
++i) {
SecKeychainAttribute* attribute = AttributeWithTag(keychain_attr_list_[*i], SecKeychainAttribute* attribute = AttributeWithTag(keychain_attr_list_[*i],
kSecCreatorItemAttr); kSecCreatorItemAttr);
OSType* data = static_cast<OSType*>(attribute->data); OSType* data = static_cast<OSType*>(attribute->data);
...@@ -515,7 +538,7 @@ bool MockKeychain::CreatorCodesSetForAddedItems() const { ...@@ -515,7 +538,7 @@ bool MockKeychain::CreatorCodesSetForAddedItems() const {
} }
void MockKeychain::AddTestItem(const KeychainTestData& item_data) { void MockKeychain::AddTestItem(const KeychainTestData& item_data) {
unsigned int key = next_item_key_++; MockKeychainItemType key = next_item_key_++;
InitializeKeychainData(key); InitializeKeychainData(key);
SetTestDataAuthType(key, item_data.auth_type); SetTestDataAuthType(key, item_data.auth_type);
...@@ -531,4 +554,4 @@ void MockKeychain::AddTestItem(const KeychainTestData& item_data) { ...@@ -531,4 +554,4 @@ void MockKeychain::AddTestItem(const KeychainTestData& item_data) {
SetTestDataNegativeItem(key, item_data.negative_item); SetTestDataNegativeItem(key, item_data.negative_item);
} }
} // namespace crypto } // namespace crypto
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#ifndef CRYPTO_MOCK_KEYCHAIN_MAC_H_ #ifndef CRYPTO_MOCK_KEYCHAIN_MAC_H_
#define CRYPTO_MOCK_KEYCHAIN_MAC_H_ #define CRYPTO_MOCK_KEYCHAIN_MAC_H_
#include <stdint.h>
#include <map> #include <map>
#include <set> #include <set>
#include <string> #include <string>
...@@ -15,6 +17,9 @@ ...@@ -15,6 +17,9 @@
namespace crypto { namespace crypto {
// Type used for the keys in the std::map(s) and MockKeychain items.
typedef uintptr_t MockKeychainItemType;
// Mock Keychain wrapper for testing code that interacts with the OS X // Mock Keychain wrapper for testing code that interacts with the OS X
// Keychain. Implemented by storing SecKeychainAttributeList and // Keychain. Implemented by storing SecKeychainAttributeList and
// KeychainPasswordData values in separate mutable containers and // KeychainPasswordData values in separate mutable containers and
...@@ -149,34 +154,44 @@ class CRYPTO_EXPORT MockKeychain : public MacKeychain { ...@@ -149,34 +154,44 @@ class CRYPTO_EXPORT MockKeychain : public MacKeychain {
SecProtocolType protocol, SecProtocolType protocol,
SecAuthenticationType authenticationType) const; SecAuthenticationType authenticationType) const;
// Initializes storage for keychain data at |key|. // Initializes storage for keychain data at |key|.
void InitializeKeychainData(unsigned int key) const; void InitializeKeychainData(MockKeychainItemType key) const;
// Sets the data and length of |tag| in the item-th test item. // Sets the data and length of |tag| in the item-th test item.
void SetTestDataBytes(int item, UInt32 tag, const void* data, size_t length); void SetTestDataBytes(
MockKeychainItemType item,
UInt32 tag,
const void* data,
size_t length);
// Sets the data and length of |tag| in the item-th test item based on // Sets the data and length of |tag| in the item-th test item based on
// |value|. The null-terminator will not be included; the Keychain Services // |value|. The null-terminator will not be included; the Keychain Services
// docs don't indicate whether it is or not, so clients should not assume // docs don't indicate whether it is or not, so clients should not assume
// that it will be. // that it will be.
void SetTestDataString(int item, UInt32 tag, const char* value); void SetTestDataString(MockKeychainItemType item,
UInt32 tag,
const char* value);
// Sets the data of the corresponding attribute of the item-th test item to // Sets the data of the corresponding attribute of the item-th test item to
// |value|. Assumes that the space has alread been allocated, and the length // |value|. Assumes that the space has alread been allocated, and the length
// set. // set.
void SetTestDataPort(int item, UInt32 value); void SetTestDataPort(MockKeychainItemType item, UInt32 value);
void SetTestDataProtocol(int item, SecProtocolType value); void SetTestDataProtocol(MockKeychainItemType item, SecProtocolType value);
void SetTestDataAuthType(int item, SecAuthenticationType value); void SetTestDataAuthType(MockKeychainItemType item,
void SetTestDataNegativeItem(int item, Boolean value); SecAuthenticationType value);
void SetTestDataCreator(int item, OSType value); void SetTestDataNegativeItem(MockKeychainItemType item, Boolean value);
void SetTestDataCreator(MockKeychainItemType item, OSType value);
// Sets the password data and length for the item-th test item. // Sets the password data and length for the item-th test item.
void SetTestDataPasswordBytes(int item, const void* data, size_t length); void SetTestDataPasswordBytes(
MockKeychainItemType item,
const void* data,
size_t length);
// Sets the password for the item-th test item. As with SetTestDataString, // Sets the password for the item-th test item. As with SetTestDataString,
// the data will not be null-terminated. // the data will not be null-terminated.
void SetTestDataPasswordString(int item, const char* value); void SetTestDataPasswordString(MockKeychainItemType item, const char* value);
// Returns the address of the attribute in attribute_list with tag |tag|. // Returns the address of the attribute in attribute_list with tag |tag|.
static SecKeychainAttribute* AttributeWithTag( static SecKeychainAttribute* AttributeWithTag(
const SecKeychainAttributeList& attribute_list, const SecKeychainAttributeList& attribute_list,
UInt32 tag); UInt32 tag);
static const int kDummySearchRef = 1000; static const SecKeychainSearchRef kDummySearchRef;
typedef struct KeychainPasswordData { typedef struct KeychainPasswordData {
KeychainPasswordData() : data(NULL), length(0) {} KeychainPasswordData() : data(NULL), length(0) {}
...@@ -186,15 +201,16 @@ class CRYPTO_EXPORT MockKeychain : public MacKeychain { ...@@ -186,15 +201,16 @@ class CRYPTO_EXPORT MockKeychain : public MacKeychain {
// Mutable because the MockKeychain API requires its internal keychain storage // Mutable because the MockKeychain API requires its internal keychain storage
// to be modifiable by users of this class. // to be modifiable by users of this class.
mutable std::map<unsigned int, SecKeychainAttributeList> keychain_attr_list_; mutable std::map<MockKeychainItemType,
mutable std::map<unsigned int, KeychainPasswordData> keychain_data_; SecKeychainAttributeList> keychain_attr_list_;
mutable unsigned int next_item_key_; mutable std::map<MockKeychainItemType, KeychainPasswordData> keychain_data_;
mutable MockKeychainItemType next_item_key_;
// Tracks the items that should be returned in subsequent calls to // Tracks the items that should be returned in subsequent calls to
// SearchCopyNext, based on the last call to SearchCreateFromAttributes. // SearchCopyNext, based on the last call to SearchCreateFromAttributes.
// We can't handle multiple active searches, since we don't track the search // We can't handle multiple active searches, since we don't track the search
// ref we return, but we don't need to for our mocking. // ref we return, but we don't need to for our mocking.
mutable std::vector<unsigned int> remaining_search_results_; mutable std::vector<MockKeychainItemType> remaining_search_results_;
// Track copies and releases to make sure they balance. Really these should // Track copies and releases to make sure they balance. Really these should
// be maps to track per item, but this should be good enough to catch // be maps to track per item, but this should be good enough to catch
...@@ -204,7 +220,7 @@ class CRYPTO_EXPORT MockKeychain : public MacKeychain { ...@@ -204,7 +220,7 @@ class CRYPTO_EXPORT MockKeychain : public MacKeychain {
mutable int attribute_data_copy_count_; mutable int attribute_data_copy_count_;
// Tracks which items (by key) were added with AddInternetPassword. // Tracks which items (by key) were added with AddInternetPassword.
mutable std::set<unsigned int> added_via_api_; mutable std::set<MockKeychainItemType> added_via_api_;
// Result code for the |FindGenericPassword()| method. // Result code for the |FindGenericPassword()| method.
OSStatus find_generic_result_; OSStatus find_generic_result_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment