}
off_t getDecryptedSize(const runtime::File &file) {
- off_t originalSize = file.size();
- off_t result = originalSize;
+ off_t result = file.size();
if (wasEncrypted(file.getPath())) {
- if (originalSize > 2 * 4096) {
- result = originalSize - 2 * 4096;
+ if (result > 2 * 4096) {
+ result -= (2 * 4096);
}
}
- result = originalSize;
-
//TODO : block size have to not hard-coded.
// If there is a better way, the followings have to be changed.
blksize_t blockSize = 4096;
if (!a)
return 0;
+ if (!b)
+ throw runtime::Exception("Cannot divide by zero");
+
return ((a - 1) / b) + 1;
}
};
runtime::Process proc("/usr/bin/ode", args);
- proc.execute();
+ if (proc.execute() == -1)
+ ERROR(SINK, "Failed to execute progress UI");
}
unsigned int getOptions()
static void RNG(unsigned char *buf, size_t resultSize)
{
- ::RAND_bytes(buf, resultSize);
+ if (::RAND_bytes(buf, resultSize) != 1)
+ throw runtime::Exception("RAND_bytes() failed");
}
static void XORBlock(const unsigned char *src1, const unsigned char *src2, unsigned char *dst, size_t size)
iv = htonl(iv);
uint32_t digestSize = 168 / 8; // use SHA1 in default
- unsigned char buf[digestSize] = {0x00, };
+ unsigned char buf[digestSize] = {0};
SHA_CTX context;
if (!::SHA1_Init(&context))
#include <openssl/sha.h>
#include <klay/filesystem.h>
+#include <klay/exception.h>
#include "../logger.h"
#include "key-generator.h"
{
BinaryData ret(resultSize);
- ::RAND_bytes(ret.data(), resultSize);
+ if(::RAND_bytes(ret.data(), resultSize) != 1)
+ throw runtime::Exception("RAND_bytes() failed");
return ret;
}