Go to the documentation of this file.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 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 }