//
-// Open Service Platform
// Copyright (c) 2012 Samsung Electronics Co., Ltd.
//
// Licensed under the Apache License, Version 2.0 (the License);
static const int SECURE_IO_4_BITS = 4;
static const int SECURE_IO_8_BITS = 8;
static const int SECURE_IO_3_BYTES = 3;
-static const int SECURE_IO_4_BYTES = 4;
-static const int SECURE_IO_5_BYTES = 5;
-static const int SECURE_IO_8_BYTES = 8;
static const int SECURE_IO_9_BYTES = 9;
static const int SECURE_IO_HEX_0F = 0x0f;
static const int SECURE_IO_HEX_FC = 0xfc;
result
_SecureIoUtil::CheckSecureFileHeader(const Tizen::Base::String& filePath, const ByteBuffer* pSecretKey)
{
- result r = E_SUCCESS;
- int ret = 0;
- _NormalFile normalFile;
- byte secureFileHeader[SECURE_FILE_HEADER_SIZE_V1];
- byte reservedValue[SECURE_IO_STATIC_BIN_LEN] = {0xCA, 0xFE, 0xBE, 0xBE, 0xDA, 0xEF, 0xEB, 0xEB};
+ byte secureFileHeader[SECURE_FILE_HEADER_SIZE_V1] = { 0, };
+ byte reservedValue[SECURE_IO_STATIC_BIN_LEN] = { 0xCA, 0xFE, 0xBE, 0xBE, 0xDA, 0xEF, 0xEB, 0xEB };
- ClearLastResult();
-
- r = normalFile.Construct(filePath, "r");
- SysTryReturn(NID_IO, !IsFailed(r), r, r, "[%s] Failed to call constuct.", GetErrorMessage(r));
+ _NormalFile normalFile;
+ result r = normalFile.Construct(filePath, "r");
+ SysTryReturnResult(NID_IO, !IsFailed(r), r, "Failed to open the file (%ls).", filePath.GetPointer());
- ret = normalFile.Read(secureFileHeader, SECURE_FILE_HEADER_SIZE_V1);
+ int ret = normalFile.Read(secureFileHeader, SECURE_FILE_HEADER_SIZE_V1);
if (ret < SECURE_FILE_HEADER_SIZE_V1)
{
- r = GetLastResult();
+ r = GetLastResult();
if (IsEndOfFile(&normalFile))
{
if (ret && pSecretKey)
{
- return E_INVALID_ARG;
+ r = E_INVALID_ARG;
}
else
{
- return E_SUCCESS;
+ r = E_SUCCESS;
}
}
- return r;
+ goto CATCH;
}
- //check if the file is encrypted file. (in normal and secure mode)
+ // Checks if the file is encrypted file. (in normal or secure mode)
ret = memcmp(secureFileHeader, SECURE_FILE_HEADER_STRING, SECURE_FILE_HEADER_STRING_SIZE);
ret |= memcmp(secureFileHeader + SECURE_FILE_HEADER_STRING_SIZE, reservedValue, SECURE_IO_STATIC_BIN_LEN);
-
SysTryReturnResult(NID_IO, !(ret && pSecretKey), E_INVALID_ARG, "Failed to match secure header in file.");
- return E_SUCCESS;
+CATCH:
+ ClearLastResult();
+ return r;
}
result