void OTData::Assign(const OTData &theSource) { if ((&theSource) == this) return; // can't assign to self. if (false == theSource.IsEmpty()) // If something is there... { Assign(theSource.m_pData, theSource.m_lSize); // Copy it. } else Release(); // Otherwise if it's empty, then empty this also. }
void OTData::Assign(const OTData& source) { // can't assign to self. if (&source == this) { return; } if (!source.IsEmpty()) { Assign(source.data_, source.size_); } else { // Otherwise if it's empty, then empty this also. Release(); } }
// static bool OTKeyring::Windows_StoreSecret(const OTString& strUser, const OTPassword& thePassword, const std::string& str_display) { OT_ASSERT(strUser.Exists()); OT_ASSERT(thePassword.getMemorySize() > 0); DATA_BLOB input; input.pbData = const_cast<BYTE*>( reinterpret_cast<const BYTE*>(thePassword.getMemory())); input.cbData = static_cast<DWORD>(thePassword.getMemorySize()); // CRYPTPROTECT_PROMPTSTRUCT PromptStruct; // ZeroMemory(&PromptStruct, sizeof(PromptStruct)); // PromptStruct.cbSize = sizeof(PromptStruct); // PromptStruct.dwPromptFlags = CRYPTPROTECT_PROMPT_ON_PROTECT; // PromptStruct.szPrompt = L"This is a user prompt."; DATA_BLOB output; BOOL result = CryptProtectData(&input, L"", // description string nullptr, // optional entropy nullptr, // reserved nullptr, //&PromptStruct 0, &output); if (!result) { otErr << __FUNCTION__ << ": Failed calling Win32: CryptProtectData \n"; return false; } // // this does a copy // // std::string ciphertext; // ciphertext.assign(reinterpret_cast<std::string::value_type*>(output.pbData), // output.cbData); OTData theOutput; theOutput.Assign(static_cast<void*>(output.pbData), static_cast<uint32_t>(output.cbData)); LocalFree(output.pbData); // Note: should have a check for nullptr here... ? // And above... // Success encrypting to ciphertext (std::string or OTData) // // Write it to local storage. // if (theOutput.IsEmpty()) { otErr << __FUNCTION__ << ": Error: Output of Win32 CryptProtectData was empty.\n"; } else { OTASCIIArmor ascData(theOutput); const OTString strFoldername("win32_data"); // todo hardcoding. if (ascData.Exists()) return ascData.WriteArmoredFile(strFoldername, strUser, // this is filename "WINDOWS KEYRING MASTERKEY"); } return false; }