Bugfix: Labels are backwards for "Block" and "Block32" encoding

Block32 should be used for case-insensitive systems (not Block)
This commit is contained in:
Charles Munson 2016-03-21 22:43:22 +01:00
parent da03864538
commit aa08c382d9
2 changed files with 13 additions and 13 deletions

View File

@ -71,7 +71,7 @@ static bool BlockIO32_registered = NameIO::Register(
// description of block name encoding algorithm.. // description of block name encoding algorithm..
// xgroup(setup) // xgroup(setup)
gettext_noop( gettext_noop(
"Block encoding with base32 output for case-sensitive systems"), "Block encoding with base32 output for case-insensitive systems"),
BlockNameIO::CurrentInterface(true), NewBlockNameIO32); BlockNameIO::CurrentInterface(true), NewBlockNameIO32);
/* /*
@ -91,9 +91,9 @@ static bool BlockIO32_registered = NameIO::Register(
- Version 4.0 adds support for base32, creating names more suitable for - Version 4.0 adds support for base32, creating names more suitable for
case-insensitive filesystems (eg Mac). case-insensitive filesystems (eg Mac).
*/ */
Interface BlockNameIO::CurrentInterface(bool caseSensitive) { Interface BlockNameIO::CurrentInterface(bool caseInsensitive) {
// implement major version 4 plus support for two prior versions // implement major version 4 plus support for two prior versions
if (caseSensitive) if (caseInsensitive)
return Interface("nameio/block32", 4, 0, 2); return Interface("nameio/block32", 4, 0, 2);
else else
return Interface("nameio/block", 4, 0, 2); return Interface("nameio/block", 4, 0, 2);
@ -101,12 +101,12 @@ Interface BlockNameIO::CurrentInterface(bool caseSensitive) {
BlockNameIO::BlockNameIO(const rel::Interface &iface, BlockNameIO::BlockNameIO(const rel::Interface &iface,
const shared_ptr<Cipher> &cipher, const CipherKey &key, const shared_ptr<Cipher> &cipher, const CipherKey &key,
int blockSize, bool caseSensitiveEncoding) int blockSize, bool caseInsensitiveEncoding)
: _interface(iface.current()), : _interface(iface.current()),
_bs(blockSize), _bs(blockSize),
_cipher(cipher), _cipher(cipher),
_key(key), _key(key),
_caseSensitive(caseSensitiveEncoding) { _caseInsensitive(caseInsensitiveEncoding) {
// just to be safe.. // just to be safe..
rAssert(blockSize < 128); rAssert(blockSize < 128);
} }
@ -114,7 +114,7 @@ BlockNameIO::BlockNameIO(const rel::Interface &iface,
BlockNameIO::~BlockNameIO() {} BlockNameIO::~BlockNameIO() {}
Interface BlockNameIO::interface() const { Interface BlockNameIO::interface() const {
return CurrentInterface(_caseSensitive); return CurrentInterface(_caseInsensitive);
} }
int BlockNameIO::maxEncodedNameLen(int plaintextNameLen) const { int BlockNameIO::maxEncodedNameLen(int plaintextNameLen) const {
@ -122,14 +122,14 @@ int BlockNameIO::maxEncodedNameLen(int plaintextNameLen) const {
// the size of too much space rather then too little. // the size of too much space rather then too little.
int numBlocks = (plaintextNameLen + _bs) / _bs; int numBlocks = (plaintextNameLen + _bs) / _bs;
int encodedNameLen = numBlocks * _bs + 2; // 2 checksum bytes int encodedNameLen = numBlocks * _bs + 2; // 2 checksum bytes
if (_caseSensitive) if (_caseInsensitive)
return B256ToB32Bytes(encodedNameLen); return B256ToB32Bytes(encodedNameLen);
else else
return B256ToB64Bytes(encodedNameLen); return B256ToB64Bytes(encodedNameLen);
} }
int BlockNameIO::maxDecodedNameLen(int encodedNameLen) const { int BlockNameIO::maxDecodedNameLen(int encodedNameLen) const {
int decLen256 = _caseSensitive ? B32ToB256Bytes(encodedNameLen) int decLen256 = _caseInsensitive ? B32ToB256Bytes(encodedNameLen)
: B64ToB256Bytes(encodedNameLen); : B64ToB256Bytes(encodedNameLen);
return decLen256 - 2; // 2 checksum bytes removed.. return decLen256 - 2; // 2 checksum bytes removed..
} }
@ -164,7 +164,7 @@ int BlockNameIO::encodeName(const char *plaintextName, int length, uint64_t *iv,
int encodedStreamLen = length + 2 + padding; int encodedStreamLen = length + 2 + padding;
int encLen; int encLen;
if (_caseSensitive) { if (_caseInsensitive) {
encLen = B256ToB32Bytes(encodedStreamLen); encLen = B256ToB32Bytes(encodedStreamLen);
changeBase2Inline((unsigned char *)encodedName, encodedStreamLen, 8, 5, changeBase2Inline((unsigned char *)encodedName, encodedStreamLen, 8, 5,
@ -184,7 +184,7 @@ int BlockNameIO::encodeName(const char *plaintextName, int length, uint64_t *iv,
int BlockNameIO::decodeName(const char *encodedName, int length, uint64_t *iv, int BlockNameIO::decodeName(const char *encodedName, int length, uint64_t *iv,
char *plaintextName) const { char *plaintextName) const {
int decLen256 = int decLen256 =
_caseSensitive ? B32ToB256Bytes(length) : B64ToB256Bytes(length); _caseInsensitive ? B32ToB256Bytes(length) : B64ToB256Bytes(length);
int decodedStreamLen = decLen256 - 2; int decodedStreamLen = decLen256 - 2;
// don't bother trying to decode files which are too small // don't bother trying to decode files which are too small
@ -196,7 +196,7 @@ int BlockNameIO::decodeName(const char *encodedName, int length, uint64_t *iv,
BUFFER_INIT(tmpBuf, 32, (unsigned int)length); BUFFER_INIT(tmpBuf, 32, (unsigned int)length);
// decode into tmpBuf, // decode into tmpBuf,
if (_caseSensitive) { if (_caseInsensitive) {
AsciiToB32((unsigned char *)tmpBuf, (unsigned char *)encodedName, length); AsciiToB32((unsigned char *)tmpBuf, (unsigned char *)encodedName, length);
changeBase2Inline((unsigned char *)tmpBuf, length, 5, 8, false); changeBase2Inline((unsigned char *)tmpBuf, length, 5, 8, false);
} else { } else {

View File

@ -42,7 +42,7 @@ class BlockNameIO : public NameIO {
BlockNameIO(const rel::Interface &iface, const shared_ptr<Cipher> &cipher, BlockNameIO(const rel::Interface &iface, const shared_ptr<Cipher> &cipher,
const CipherKey &key, int blockSize, const CipherKey &key, int blockSize,
bool caseSensitiveEncoding = false); bool caseInsensitiveEncoding = false);
virtual ~BlockNameIO(); virtual ~BlockNameIO();
virtual rel::Interface interface() const; virtual rel::Interface interface() const;
@ -64,7 +64,7 @@ class BlockNameIO : public NameIO {
int _bs; int _bs;
shared_ptr<Cipher> _cipher; shared_ptr<Cipher> _cipher;
CipherKey _key; CipherKey _key;
bool _caseSensitive; bool _caseInsensitive;
}; };
#endif #endif