crypt/file.h

Go to the documentation of this file.
00001 // -*- c++ -*-
00002 //
00003 // $Id: file.h,v 1.9 2008-02-27 09:29:33 rafi Exp $
00004 //
00005 // YAPET -- Yet Another Password Encryption Tool
00006 // Copyright (C) 2008  Rafael Ostertag
00007 //
00008 // This program is free software: you can redistribute it and/or modify
00009 // it under the terms of the GNU General Public License as published by
00010 // the Free Software Foundation, either version 3 of the License, or
00011 // (at your option) any later version.
00012 //
00013 // This program is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 // GNU General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU General Public License
00019 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
00020 //
00021 
00022 #ifndef _FILE_H
00023 #define _FILE_H
00024 
00025 #ifdef HAVE_CONFIG_H
00026 # include <config.h>
00027 #endif
00028 
00029 #ifdef HAVE_STRING
00030 # include <string>
00031 #endif
00032 
00033 #ifdef HAVE_LIST
00034 # include <list>
00035 #endif
00036 
00037 #include "yapetexception.h"
00038 
00039 #include "bdbuffer.h"
00040 #include "structs.h"
00041 #include "key.h"
00042 #include "partdec.h"
00043 
00044 namespace YAPET {
00159     class File {
00160     private:
00166         int fd;
00172         std::string filename;
00182         time_t mtime;
00183 
00184 
00186         void openCreate() throw(YAPETException);
00188         void openNoCreate() throw(YAPETException);
00190         time_t lastModified() const throw(YAPETException);
00192         void seekCurr(off_t offset) const throw(YAPETException);
00194         void seekAbs(off_t offset) const throw(YAPETException);
00196         void preparePWSave() throw(YAPETException);
00197 
00198     protected:
00205         struct WORD {
00206             uint8_t a;
00207             uint8_t b;
00208         };
00209 
00216         struct DWORD {
00217             WORD a;
00218             WORD b;
00219         };
00220 
00227         union ENDIAN {
00233             uint32_t abcd;
00234             DWORD dword;
00235         };
00236 
00237 #ifndef WORDS_BIGENDIAN
00240         uint32_t uint32_to_disk(uint32_t i) const;
00243         uint32_t uint32_from_disk(uint32_t i) const;
00244 #else
00245 
00256         inline uint32_t uint32_to_disk(uint32_t i) const { return i; }
00269         inline uint32_t uint32_from_disk(uint32_t i) const { return i; }
00270 #endif // WORDS_BIGENDIAN
00271 
00274         void seekDataSection() const throw(YAPETException);
00275 
00277         BDBuffer* read() const throw(YAPETException);
00279         void write(const BDBuffer& buff,
00280                bool forceappend=false,
00281                bool forcewrite=false)
00282         throw(YAPETException, YAPETRetryException);
00284         bool isempty() const throw(YAPETException);
00286         void initFile(const Key& key) throw(YAPETException);
00288         void writeHeader(const Record<FileHeader>& header,
00289                  const Key& key)
00290         throw(YAPETException);
00292         void writeHeader(const BDBuffer& enc_header) throw(YAPETException);
00294         BDBuffer* readHeader() const throw(YAPETException);
00296         void validateKey(const Key& key)
00297         throw(YAPETException,YAPETInvalidPasswordException);
00298 
00299     public:
00301         File(const std::string& fn,
00302          const Key& key,
00303          bool create=false)
00304         throw(YAPETException);
00305         File(const File& f) throw(YAPETException);
00306         ~File();
00307 
00309         void save(std::list<PartDec>& records) throw(YAPETException);
00311         std::list<PartDec> read(const Key& key) const throw(YAPETException);
00313         std::string getFilename() const { return filename; }
00315         void setNewKey(const Key& oldkey, const Key& newkey)
00316         throw(YAPETException);
00317         time_t getMasterPWSet(const Key& key) const
00318         throw(YAPETException,YAPETInvalidPasswordException);
00320         const File& operator=(const File& f) throw(YAPETException);
00321     };
00322 }
00323 #endif // _FILE_H

Generated on Wed Feb 27 16:15:41 2008 for YAPET by  doxygen 1.5.4