• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

crypt/file.h

Go to the documentation of this file.
00001 // -*- c++ -*-
00002 //
00003 // $Id: file.h 3342 2010-09-17 18:32:00Z java $
00004 //
00005 // Copyright (C) 2008-2010  Rafael Ostertag
00006 //
00007 // This file is part of YAPET.
00008 //
00009 // YAPET is free software: you can redistribute it and/or modify it under the
00010 // terms of the GNU General Public License as published by the Free Software
00011 // Foundation, either version 3 of the License, or (at your option) any later
00012 // version.
00013 //
00014 // YAPET is distributed in the hope that it will be useful, but WITHOUT ANY
00015 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00016 // FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
00017 // details.
00018 //
00019 // You should have received a copy of the GNU General Public License along with
00020 // YAPET.  If not, see <http://www.gnu.org/licenses/>.
00021 //
00022 // Additional permission under GNU GPL version 3 section 7
00023 //
00024 // If you modify this program, or any covered work, by linking or combining it
00025 // with the OpenSSL project's OpenSSL library (or a modified version of that
00026 // library), containing parts covered by the terms of the OpenSSL or SSLeay
00027 // licenses, Rafael Ostertag grants you additional permission to convey the
00028 // resulting work.  Corresponding Source for a non-source form of such a
00029 // combination shall include the source code for the parts of OpenSSL used as
00030 // well as that of the covered work.
00031 //
00032 
00033 #ifndef _FILE_H
00034 #define _FILE_H
00035 
00036 #ifdef HAVE_CONFIG_H
00037 # include <config.h>
00038 #endif
00039 
00040 #ifdef HAVE_ASSERT_H
00041 # include <assert.h>
00042 #endif
00043 
00044 #ifdef HAVE_STRING
00045 # include <string>
00046 #endif
00047 
00048 #ifdef HAVE_LIST
00049 # include <list>
00050 #endif
00051 
00052 #include "yapetexception.h"
00053 
00054 #include "bdbuffer.h"
00055 #include "structs.h"
00056 #include "key.h"
00057 #include "partdec.h"
00058 
00059 namespace YAPET {
00193     class File {
00194         private:
00200             int fd;
00206             std::string filename;
00218         int64_t mtime;
00219 
00232             bool usefsecurity;
00233 
00235             void checkFileSecurity() throw (YAPETException);
00237             void setFileSecurity() throw (YAPETException);
00238 
00240             void openCreate() throw (YAPETException);
00242             void openNoCreate() throw (YAPETException);
00244             int64_t lastModified() const throw (YAPETException);
00246             void seekCurr (off_t offset) const throw (YAPETException);
00248             void seekAbs (off_t offset) const throw (YAPETException);
00250             void preparePWSave() throw (YAPETException);
00251 
00252         protected:
00253         template <class t>
00254             union ENDIAN {
00260             t value;
00261             uint8_t fields[sizeof(t)];
00262             };
00263 
00264 #ifndef WORDS_BIGENDIAN
00265 
00275         template<class t>
00276             t int_to_disk (t le) const {
00277         ENDIAN<t> in;
00278         ENDIAN<t> out;
00279         in.value = le;
00280         out.value = 0;
00281         for (register unsigned int i=0; i < sizeof(t); i++)
00282             out.fields[(sizeof(t)-1)-i] = in.fields[i];
00283         return out.value;
00284         }
00295         template<class t>
00296         t int_from_disk (t i) const {
00297         return int_to_disk<t>(i);
00298         }
00299 #else
00300 
00311         template<class t>
00312             t int_to_disk (t i) const {
00313                 return i;
00314             }
00327         template<class t>
00328             t int_from_disk (t i) const {
00329                 return i;
00330             }
00331 #endif // WORDS_BIGENDIAN
00332 
00335             void seekDataSection() const throw (YAPETException);
00336 
00338             BDBuffer* read() const throw (YAPETException);
00340             void write (const BDBuffer& buff,
00341                         bool forceappend = false,
00342                         bool forcewrite = false)
00343             throw (YAPETException, YAPETRetryException);
00345             bool isempty() const throw (YAPETException);
00347             void initFile (const Key& key) throw (YAPETException);
00349             void writeHeader (const Record<FileHeader_64>& header,
00350                               const Key& key)
00351             throw (YAPETException);
00353             void writeHeader (const BDBuffer& enc_header) throw (YAPETException);
00355             BDBuffer* readHeader() const throw (YAPETException);
00357         void readHeader(const Key& key, Record<FileHeader_32>** ptr32, Record<FileHeader_64>** ptr64) const throw(YAPETException);
00359             void validateKey (const Key& key)
00360             throw (YAPETException, YAPETInvalidPasswordException);
00361 
00362         public:
00364             File (const std::string& fn,
00365                   const Key& key,
00366                   bool create = false,
00367                   bool secure = true)
00368             throw (YAPETException);
00369             File (const File& f) throw (YAPETException);
00370             ~File();
00371 
00373             void save (std::list<PartDec>& records) throw (YAPETException);
00375             std::list<PartDec> read (const Key& key) const throw (YAPETException);
00377             std::string getFilename() const {
00378                 return filename;
00379             }
00381             void setNewKey (const Key& oldkey, const Key& newkey) throw (YAPETException);
00382             int64_t getMasterPWSet (const Key& key) const throw (YAPETException, YAPETInvalidPasswordException);
00384         FILE_VERSION getFileVersion(const Key& key) const throw (YAPETException, YAPETInvalidPasswordException);
00386             const File& operator= (const File& f) throw (YAPETException);
00387 
00389             bool filesecurityEnabled() const {
00390                 return usefsecurity;
00391             }
00393             void setFilesecurity (bool secure) {
00394                 usefsecurity = secure;
00395             }
00396     };
00397 }
00398 #endif // _FILE_H

Generated on Sun Sep 19 2010 15:37:13 for YAPET by  doxygen 1.7.1