00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
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
00049 Crypt crypt(key);
00050 Record<PasswordRecord>* dec_pw_rec = crypt.decrypt<PasswordRecord>(bd);
00051 PasswordRecord* ptr_dec_pw_rec = *dec_pw_rec;
00052
00053 memcpy(name, ptr_dec_pw_rec->name, NAME_SIZE);
00054 delete dec_pw_rec;
00055 }
00056
00057 PartDec::PartDec(Record<PasswordRecord>& pr, const Key& key) throw(YAPETException) {
00058 setRecord(pr, key);
00059 }
00060
00061 PartDec::PartDec(const PartDec& pd) : enc_data(pd.enc_data) {
00062 memcpy(name, pd.name, NAME_SIZE);
00063 }
00064
00065 PartDec::~PartDec() {
00066 memset(name, 0, NAME_SIZE);
00067 }
00068
00069 void
00070 PartDec::setRecord(Record<PasswordRecord>& pr, const Key& key) throw(YAPETException) {
00071
00072 PasswordRecord* ptr_pr = pr;
00073 memcpy(name, ptr_pr->name, NAME_SIZE);
00074
00075 Crypt crypt(key);
00076 BDBuffer* enc_pr = crypt.encrypt(pr);
00077 enc_data = *enc_pr;
00078 delete enc_pr;
00079 }
00080
00081 const PartDec&
00082 PartDec::operator=(const PartDec& pd) {
00083 if (this == &pd) return *this;
00084
00085 memset(name, 0, NAME_SIZE);
00086 memcpy(name, pd.name, NAME_SIZE);
00087
00088 enc_data = pd.enc_data;
00089
00090 return *this;
00091 }
00092
00096 bool
00097 PartDec::operator<(const PartDec& pd) const {
00098 if (this == &pd) return false;
00099
00100 if (strcmp((const char*)name, (const char*)pd.name) < 0)
00101 return true;
00102
00103 return false;
00104 }