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

crypt/partdec.cc

Go to the documentation of this file.
00001 // $Id: partdec.cc 3342 2010-09-17 18:32:00Z java $
00002 //
00003 // Copyright (C) 2008-2010  Rafael Ostertag
00004 //
00005 // This file is part of YAPET.
00006 //
00007 // YAPET is free software: you can redistribute it and/or modify it under the
00008 // terms of the GNU General Public License as published by the Free Software
00009 // Foundation, either version 3 of the License, or (at your option) any later
00010 // version.
00011 //
00012 // YAPET is distributed in the hope that it will be useful, but WITHOUT ANY
00013 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00014 // FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
00015 // details.
00016 //
00017 // You should have received a copy of the GNU General Public License along with
00018 // YAPET.  If not, see <http://www.gnu.org/licenses/>.
00019 //
00020 // Additional permission under GNU GPL version 3 section 7
00021 //
00022 // If you modify this program, or any covered work, by linking or combining it
00023 // with the OpenSSL project's OpenSSL library (or a modified version of that
00024 // library), containing parts covered by the terms of the OpenSSL or SSLeay
00025 // licenses, Rafael Ostertag grants you additional permission to convey the
00026 // resulting work.  Corresponding Source for a non-source form of such a
00027 // combination shall include the source code for the parts of OpenSSL used as
00028 // well as that of the covered work.
00029 //
00030 
00031 #ifdef HAVE_STRING_H
00032 # include<string.h>
00033 #endif
00034 
00035 #include "partdec.h"
00036 
00037 #include "record.h"
00038 #include "crypt.h"
00039 
00040 using namespace YAPET;
00041 
00042 PartDec::PartDec() {
00043     memset (name, 0, NAME_SIZE);
00044 }
00045 
00046 PartDec::PartDec (BDBuffer& bd, const Key& key)
00047 throw (YAPETException) : enc_data (bd) {
00048     Crypt crypt (key);
00049     Record<PasswordRecord>* dec_pw_rec = crypt.decrypt<PasswordRecord> (bd);
00050     PasswordRecord* ptr_dec_pw_rec = *dec_pw_rec;
00051     memcpy (name, ptr_dec_pw_rec->name, NAME_SIZE);
00052     delete dec_pw_rec;
00053 }
00054 
00055 PartDec::PartDec (Record<PasswordRecord>& pr, const Key& key) throw (YAPETException) {
00056     setRecord (pr, key);
00057 }
00058 
00059 PartDec::PartDec (const PartDec& pd) : enc_data (pd.enc_data) {
00060     memcpy (name, pd.name, NAME_SIZE);
00061 }
00062 
00063 PartDec::~PartDec() {
00064     memset (name, 0, NAME_SIZE);
00065 }
00066 
00067 void
00068 PartDec::setRecord (Record<PasswordRecord>& pr, const Key& key) throw (YAPETException) {
00069     PasswordRecord* ptr_pr = pr;
00070     memcpy (name, ptr_pr->name, NAME_SIZE);
00071     Crypt crypt (key);
00072     BDBuffer* enc_pr = crypt.encrypt (pr);
00073     enc_data = *enc_pr;
00074     delete enc_pr;
00075 }
00076 
00077 const PartDec&
00078 PartDec::operator= (const PartDec & pd) {
00079     if (this == &pd) return *this;
00080 
00081     memset (name, 0, NAME_SIZE);
00082     memcpy (name, pd.name, NAME_SIZE);
00083     enc_data = pd.enc_data;
00084     return *this;
00085 }
00086 
00090 bool
00091 PartDec::operator< (const PartDec& pd) const {
00092     if (this == &pd) return false;
00093 
00094     if (strcmp ( (const char*) name, (const char*) pd.name) < 0)
00095         return true;
00096 
00097     return false;
00098 }

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