crypt/partdec.cc

Go to the documentation of this file.
00001 // $Id: partdec.cc,v 1.3 2008-02-07 23:39:10 rafi Exp $
00002 //
00003 // YAPET -- Yet Another Password Encryption Tool
00004 // Copyright (C) 2008  Rafael Ostertag
00005 //
00006 // This program is free software: you can redistribute it and/or modify
00007 // it under the terms of the GNU General Public License as published by
00008 // the Free Software Foundation, either version 3 of the License, or
00009 // (at your option) any later version.
00010 //
00011 // This program is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU General Public License
00017 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
00018 //
00019 
00020 #include "partdec.h"
00021 
00022 #include "record.h"
00023 #include "crypt.h"
00024 
00025 using namespace YAPET;
00026 
00027 PartDec::PartDec() {
00028     memset(name, 0, NAME_SIZE);
00029 }
00030 
00031 PartDec::PartDec(BDBuffer& bd, const Key& key)
00032     throw(YAPETException) : enc_data(bd) {
00033    
00034     Crypt crypt(key);
00035     Record<PasswordRecord>* dec_pw_rec = crypt.decrypt<PasswordRecord>(bd);
00036     PasswordRecord* ptr_dec_pw_rec = *dec_pw_rec;
00037 
00038     memcpy(name, ptr_dec_pw_rec->name, NAME_SIZE);
00039     delete dec_pw_rec;
00040 }
00041 
00042 PartDec::PartDec(Record<PasswordRecord>& pr, const Key& key) throw(YAPETException) {
00043     setRecord(pr, key);
00044 }
00045 
00046 PartDec::PartDec(const PartDec& pd) : enc_data(pd.enc_data) {
00047     memcpy(name, pd.name, NAME_SIZE);
00048 }
00049 
00050 PartDec::~PartDec() {
00051     memset(name, 0, NAME_SIZE);
00052 }
00053 
00054 void
00055 PartDec::setRecord(Record<PasswordRecord>& pr, const Key& key) throw(YAPETException) {
00056 
00057     PasswordRecord* ptr_pr = pr;
00058     memcpy(name, ptr_pr->name, NAME_SIZE);
00059 
00060     Crypt crypt(key);
00061     BDBuffer* enc_pr = crypt.encrypt(pr);
00062     enc_data = *enc_pr;
00063     delete enc_pr;
00064 }
00065 
00066 const PartDec&
00067 PartDec::operator=(const PartDec& pd) {
00068     if (this == &pd) return *this;
00069 
00070     memset(name, 0, NAME_SIZE);
00071     memcpy(name, pd.name, NAME_SIZE);
00072 
00073     enc_data = pd.enc_data;
00074 
00075     return *this;
00076 }

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