added UUID class for a correct implementation of the entry uuids
git-svn-id: https://svn.code.sf.net/p/keepassx/code/trunk@96 b624d157-de02-0410-bad0-e51aec6abb33
This commit is contained in:
parent
f060033b14
commit
9b6f3c8fce
|
@ -19,6 +19,58 @@
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
#include "Database.h"
|
#include "Database.h"
|
||||||
|
#include "lib/random.h"
|
||||||
|
|
||||||
|
KpxUuid::KpxUuid(){
|
||||||
|
generate();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void KpxUuid::generate(){
|
||||||
|
char uuid[16];
|
||||||
|
getRandomBytes(uuid,16);
|
||||||
|
quint32 Secs=QDateTime::currentDateTime().toTime_t();
|
||||||
|
quint16 mSecs=QTime::currentTime().msec();
|
||||||
|
mSecs=(mSecs & 0x3FF) | (*((quint16*)(uuid+4)) & 0xFC00); //msec has only 10 Bits, filling the rest with random data
|
||||||
|
memcpy((void*)uuid,&Secs,4);
|
||||||
|
memcpy((void*)(uuid+4),&mSecs,2);
|
||||||
|
Data=QByteArray(uuid,16);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString KpxUuid::toString()const{
|
||||||
|
QString hex;
|
||||||
|
Q_ASSERT(Data.length()==16);
|
||||||
|
for(int i=0;i<16;i++){
|
||||||
|
QString HexByte;
|
||||||
|
HexByte.setNum((unsigned char)*(Data.data()+i),16);
|
||||||
|
if(HexByte.length()<2)HexByte="0"+HexByte;
|
||||||
|
hex+=HexByte;
|
||||||
|
}
|
||||||
|
return QString("{%1-%2-%3-%4-%5}")
|
||||||
|
.arg(hex.mid(0,8))
|
||||||
|
.arg(hex.mid(8,4))
|
||||||
|
.arg(hex.mid(12,4))
|
||||||
|
.arg(hex.mid(16,4))
|
||||||
|
.arg(hex.mid(20,12));
|
||||||
|
}
|
||||||
|
|
||||||
|
void KpxUuid::toRaw(void* dst){
|
||||||
|
memcpy(dst,Data.data(),16);
|
||||||
|
}
|
||||||
|
|
||||||
|
void KpxUuid::fromRaw(void* src){
|
||||||
|
Data=QByteArray((char*)src,16);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool KpxUuid::operator==(const KpxUuid& other)const{
|
||||||
|
return other.Data==Data;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool KpxUuid::operator!=(const KpxUuid& other)const{
|
||||||
|
return other.Data!=Data;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
QString KpxDateTime::toString(Qt::DateFormat format) const{
|
QString KpxDateTime::toString(Qt::DateFormat format) const{
|
||||||
if(*this==Date_Never)return QObject::tr("Never");
|
if(*this==Date_Never)return QObject::tr("Never");
|
||||||
|
|
|
@ -24,10 +24,27 @@
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
|
#include <QByteArray>
|
||||||
#include "lib/SecString.h"
|
#include "lib/SecString.h"
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
extern const QDateTime Date_Never;
|
extern const QDateTime Date_Never;
|
||||||
|
|
||||||
|
class KpxUuid{
|
||||||
|
public:
|
||||||
|
KpxUuid();
|
||||||
|
bool operator==(const KpxUuid&) const;
|
||||||
|
bool operator!=(const KpxUuid&) const;
|
||||||
|
QString toString() const;
|
||||||
|
const unsigned char* data()const
|
||||||
|
{return (const unsigned char*) Data.data();}
|
||||||
|
void toRaw(void* dst);
|
||||||
|
void fromRaw(void* src);
|
||||||
|
private:
|
||||||
|
void generate();
|
||||||
|
QByteArray Data;
|
||||||
|
};
|
||||||
|
|
||||||
class KpxDateTime:public QDateTime{
|
class KpxDateTime:public QDateTime{
|
||||||
public:
|
public:
|
||||||
KpxDateTime(){};
|
KpxDateTime(){};
|
||||||
|
|
|
@ -35,6 +35,7 @@
|
||||||
#include "PwmConfig.h"
|
#include "PwmConfig.h"
|
||||||
#include "PwManager.h"
|
#include "PwManager.h"
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
|
#include "Database.h"
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
#ifdef Q_WS_X11
|
#ifdef Q_WS_X11
|
||||||
|
@ -82,6 +83,12 @@ bool loadTranslation(QTranslator* tr,const QString& prefix,const QString& Locale
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
for(int i=0;i<100;i++){
|
||||||
|
KpxUuid id;
|
||||||
|
cout << (const char*)id.toString().toAscii() << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
QApplication* app=new QApplication(argc,argv);
|
QApplication* app=new QApplication(argc,argv);
|
||||||
QString ArgFile,ArgCfg,ArgLang,IniFilename;
|
QString ArgFile,ArgCfg,ArgLang,IniFilename;
|
||||||
|
|
Loading…
Reference in New Issue