mirror of
https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git
synced 2025-07-17 10:52:46 +00:00
Fix paths and move GetSecureEncryptionKey so things compile again
This commit is contained in:
@ -1,3 +1,4 @@
|
||||
include_directories(../PubUtilLib/plUnifiedTime) # EVIL: For plFileUtils.cpp
|
||||
add_definitions(-D_LIB)
|
||||
|
||||
if(NOT WCHAR_BYTES)
|
||||
|
@ -57,9 +57,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
||||
#include "hsStringTokenizer.h"
|
||||
|
||||
|
||||
#include "plUnifiedTime/plUnifiedTime.h"
|
||||
|
||||
#include "plSecureStream.h" // for the default key
|
||||
#include "plUnifiedTime.h"
|
||||
|
||||
#include <time.h>
|
||||
#include <sys/types.h>
|
||||
@ -503,61 +501,3 @@ uint32_t plFileUtils::GetFileSize( const wchar_t *path )
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
//// GetSecureEncryptionKey //////////////////////////////////////////////////
|
||||
|
||||
bool plFileUtils::GetSecureEncryptionKey(const char* filename, uint32_t* key, unsigned length)
|
||||
{
|
||||
wchar_t* wFilename = hsStringToWString(filename);
|
||||
bool ret = GetSecureEncryptionKey(wFilename, key, length);
|
||||
delete [] wFilename;
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool plFileUtils::GetSecureEncryptionKey(const wchar_t* filename, uint32_t* key, unsigned length)
|
||||
{
|
||||
// looks for an encryption key file in the same directory, and reads it
|
||||
std::wstring sFilename = filename;
|
||||
|
||||
// grab parent directory
|
||||
size_t loc = sFilename.rfind(L"\\");
|
||||
if (loc == std::wstring::npos)
|
||||
loc = sFilename.rfind(L"/");
|
||||
|
||||
std::wstring sDir;
|
||||
if (loc != std::wstring::npos)
|
||||
sDir = sFilename.substr(0, loc);
|
||||
else // no directory
|
||||
sDir = L"./";
|
||||
if ((sDir[sDir.length()-1] != L'/') && (sDir[sDir.length()-1] != L'\\'))
|
||||
sDir += L'/'; // add the slash, if it doesn't has one
|
||||
|
||||
// now add the key filename
|
||||
std::wstring keyFile = sDir + kWKeyFilename;
|
||||
|
||||
if (FileExists(keyFile.c_str()))
|
||||
{
|
||||
// file exists, read from it
|
||||
hsUNIXStream file;
|
||||
file.Open(keyFile.c_str(), L"rb");
|
||||
|
||||
unsigned bytesToRead = length * sizeof(uint32_t);
|
||||
uint8_t* buffer = (uint8_t*)malloc(bytesToRead);
|
||||
unsigned bytesRead = file.Read(bytesToRead, buffer);
|
||||
|
||||
file.Close();
|
||||
|
||||
unsigned memSize = min(bytesToRead, bytesRead);
|
||||
memcpy(key, buffer, memSize);
|
||||
free(buffer);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// file doesn't exist, use default key
|
||||
unsigned memSize = min(length, arrsize(plSecureStream::kDefaultKey));
|
||||
memSize *= sizeof(uint32_t);
|
||||
memcpy(key, plSecureStream::kDefaultKey, memSize);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -56,9 +56,6 @@ class plUnifiedTime;
|
||||
|
||||
namespace plFileUtils
|
||||
{
|
||||
static const char kKeyFilename[] = "encryption.key";
|
||||
static const wchar_t kWKeyFilename[] = L"encryption.key";
|
||||
|
||||
// Creates the directory specified. Returns false if unsuccessful or directory already exists
|
||||
bool CreateDir( const char *path );
|
||||
bool CreateDir( const wchar_t *path );
|
||||
@ -113,12 +110,6 @@ namespace plFileUtils
|
||||
// Concatenates fileName onto path, making sure to add a slash if necessary
|
||||
void ConcatFileName(char* path, const char* fileName);
|
||||
void ConcatFileName(wchar_t* path, const wchar_t* fileName);
|
||||
|
||||
// searches the parent directory of filename for the encryption key file, and reads it
|
||||
// into the key passed in. Returns false if the key file didn't exist (and sets key to
|
||||
// the default key)
|
||||
bool GetSecureEncryptionKey(const char* filename, uint32_t* key, unsigned length);
|
||||
bool GetSecureEncryptionKey(const wchar_t* filename, uint32_t* key, unsigned length);
|
||||
};
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user