Consolidate rAssert statements in BlockNameIO

Whitespace cleanup
StreamNameIO rAssert statements should be the same
This commit is contained in:
Charles Munson 2016-03-24 16:34:52 +01:00
parent a0e02cb3ea
commit 6db69c2b0a
5 changed files with 14 additions and 16 deletions

View File

@ -137,17 +137,16 @@ int BlockNameIO::maxDecodedNameLen(int encodedNameLen) const {
int BlockNameIO::encodeName(const char *plaintextName, int length, uint64_t *iv,
char *encodedName, int bufferLength) const {
// copy the data into the encoding buffer..
rAssert(length <= (bufferLength - 2));
memcpy(encodedName + 2, plaintextName, length);
// Pad encryption buffer to block boundary..
int padding = _bs - length % _bs;
if (padding == 0) padding = _bs; // padding a full extra block!
rAssert(padding <= (bufferLength - length - 2));
rAssert(bufferLength >= length + 2 + padding);
memset(encodedName + length + 2, (unsigned char)padding, padding);
// copy the data into the encoding buffer..
memcpy(encodedName + 2, plaintextName, length);
// store the IV before it is modified by the MAC call.
uint64_t tmpIV = 0;
if (iv && _interface >= 3) tmpIV = *iv;

View File

@ -166,10 +166,10 @@ std::string NameIO::recodePath(const char *path,
// figure out buffer sizes
int approxLen = (this->*_length)(len);
if (approxLen <= 0) throw ERROR("Filename too small to decode");
int bufSize = 0;
int bufSize = 0;
BUFFER_INIT_S(codeBuf, 32, (unsigned int)approxLen + 1, bufSize)
// code the name
int codedLen = (this->*_code)(path, len, iv, codeBuf, bufSize);
rAssert(codedLen <= approxLen);
@ -231,7 +231,7 @@ std::string NameIO::_encodeName(const char *plaintextName, int length) const {
int bufSize = 0;
BUFFER_INIT_S(codeBuf, 32, (unsigned int)approxLen + 1, bufSize)
// code the name
int codedLen = encodeName(plaintextName, length, 0, codeBuf, bufSize);
rAssert(codedLen <= approxLen);
@ -250,7 +250,7 @@ std::string NameIO::_decodeName(const char *encodedName, int length) const {
int bufSize = 0;
BUFFER_INIT_S(codeBuf, 32, (unsigned int)approxLen + 1, bufSize)
// code the name
int codedLen = decodeName(encodedName, length, 0, codeBuf, bufSize);
rAssert(codedLen <= approxLen);

View File

@ -108,11 +108,11 @@ class NameIO {
};
/*
Helper macros for creating temporary buffers with an optimization that
below a given size (OptimizedSize) is allocated on the stack, and when a
larger size is requested it is allocated on the heap.
Helper macros for creating temporary buffers with an optimization that
below a given size (OptimizedSize) is allocated on the stack, and when a
larger size is requested it is allocated on the heap.
BUFFER_RESET should be called for the same name as BUFFER_INIT
BUFFER_RESET should be called for the same name as BUFFER_INIT
*/
#define BUFFER_INIT(Name, OptimizedSize, Size) \
char Name##_Raw[OptimizedSize]; \

View File

@ -58,7 +58,7 @@ int NullNameIO::maxDecodedNameLen(int encodedNameLen) const {
int NullNameIO::encodeName(const char *plaintextName, int length, uint64_t *iv,
char *encodedName, int bufferLength) const {
(void)iv;
rAssert(length <= bufferLength);
memcpy(encodedName, plaintextName, length);

View File

@ -99,18 +99,17 @@ int StreamNameIO::encodeName(const char *plaintextName, int length,
// add on checksum bytes
unsigned char *encodeBegin;
rAssert(bufferLength >= length + 2);
if (_interface >= 1) {
// current versions store the checksum at the beginning
encodedName[0] = (mac >> 8) & 0xff;
encodedName[1] = (mac)&0xff;
encodeBegin = (unsigned char *)encodedName + 2;
rAssert(length <= (bufferLength - 2));
} else {
// encfs 0.x stored checksums at the end.
encodedName[length] = (mac >> 8) & 0xff;
encodedName[length + 1] = (mac)&0xff;
encodeBegin = (unsigned char *)encodedName;
rAssert(length <= bufferLength);
}
// stream encode the plaintext bytes