00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifdef HAVE_STRING_H
00020 # include<string.h>
00021 #endif
00022
00023 #include "partdec.h"
00024
00025 #include "record.h"
00026 #include "crypt.h"
00027
00028 using namespace YAPET;
00029
00030 PartDec::PartDec() {
00031 memset(name, 0, NAME_SIZE);
00032 }
00033
00034 PartDec::PartDec(BDBuffer& bd, const Key& key)
00035 throw(YAPETException) : enc_data(bd) {
00036
00037 Crypt crypt(key);
00038 Record<PasswordRecord>* dec_pw_rec = crypt.decrypt<PasswordRecord>(bd);
00039 PasswordRecord* ptr_dec_pw_rec = *dec_pw_rec;
00040
00041 memcpy(name, ptr_dec_pw_rec->name, NAME_SIZE);
00042 delete dec_pw_rec;
00043 }
00044
00045 PartDec::PartDec(Record<PasswordRecord>& pr, const Key& key) throw(YAPETException) {
00046 setRecord(pr, key);
00047 }
00048
00049 PartDec::PartDec(const PartDec& pd) : enc_data(pd.enc_data) {
00050 memcpy(name, pd.name, NAME_SIZE);
00051 }
00052
00053 PartDec::~PartDec() {
00054 memset(name, 0, NAME_SIZE);
00055 }
00056
00057 void
00058 PartDec::setRecord(Record<PasswordRecord>& pr, const Key& key) throw(YAPETException) {
00059
00060 PasswordRecord* ptr_pr = pr;
00061 memcpy(name, ptr_pr->name, NAME_SIZE);
00062
00063 Crypt crypt(key);
00064 BDBuffer* enc_pr = crypt.encrypt(pr);
00065 enc_data = *enc_pr;
00066 delete enc_pr;
00067 }
00068
00069 const PartDec&
00070 PartDec::operator=(const PartDec& pd) {
00071 if (this == &pd) return *this;
00072
00073 memset(name, 0, NAME_SIZE);
00074 memcpy(name, pd.name, NAME_SIZE);
00075
00076 enc_data = pd.enc_data;
00077
00078 return *this;
00079 }
00080
00084 bool
00085 PartDec::operator<(const PartDec& pd) const {
00086 if (this == &pd) return false;
00087
00088 if (strcmp((const char*)name, (const char*)pd.name) < 0)
00089 return true;
00090
00091 return false;
00092 }