00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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 }