1 /***************************************************************************** 2 * Author: Valient Gough <vgough@pobox.com> 3 * 4 ***************************************************************************** 5 * Copyright (c) 2004, Valient Gough 6 * 7 * This program is free software: you can redistribute it and/or modify it 8 * under the terms of the GNU Lesser General Public License as published by the 9 * Free Software Foundation, either version 3 of the License, or (at your 10 * option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, but WITHOUT 13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 15 * for more details. 16 * 17 * You should have received a copy of the GNU Lesser General Public License 18 * along with this program. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 21 #ifndef _BlockNameIO_incl_ 22 #define _BlockNameIO_incl_ 23 24 #include <memory> 25 #include <stdint.h> // for uint64_t 26 27 #include "CipherKey.h" // for CipherKey 28 #include "Interface.h" // for Interface 29 #include "NameIO.h" // for NameIO 30 31 namespace encfs { 32 33 class Cipher; 34 35 /* 36 Implement NameIO interface for filename encoding. Uses cipher in block 37 mode to encode filenames. The filenames are padded to be a multiple of the 38 cipher block size. 39 */ 40 class BlockNameIO : public NameIO { 41 public: 42 static Interface CurrentInterface(bool caseInsensitive = false); 43 44 BlockNameIO(const Interface &iface, std::shared_ptr<Cipher> cipher, 45 CipherKey key, int blockSize, 46 bool caseInsensitiveEncoding = false); 47 virtual ~BlockNameIO(); 48 49 virtual Interface interface() const; 50 51 virtual int maxEncodedNameLen(int plaintextNameLen) const; 52 virtual int maxDecodedNameLen(int encodedNameLen) const; 53 54 // hack to help with static builds 55 static bool Enabled(); 56 57 protected: 58 virtual int encodeName(const char *plaintextName, int length, uint64_t *iv, 59 char *encodedName, int bufferLength) const; 60 virtual int decodeName(const char *encodedName, int length, uint64_t *iv, 61 char *plaintextName, int bufferLength) const; 62 63 private: 64 int _interface; 65 int _bs; 66 std::shared_ptr<Cipher> _cipher; 67 CipherKey _key; 68 bool _caseInsensitive; 69 }; 70 71 } // namespace encfs 72 73 #endif 74