git-svn-id: svn://db.shs.com.ru/pip@669 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
240
main.cpp
240
main.cpp
@@ -1,239 +1,13 @@
|
||||
#include "pip.h"
|
||||
#include "piauth.h"
|
||||
|
||||
/*
|
||||
class Obj : public PIObject {
|
||||
PIOBJECT(Obj)
|
||||
public:
|
||||
Obj() : PIObject() {}
|
||||
|
||||
EVENT_HANDLER2(void, authorizeServer, PIByteArray, info, bool *, ok) {
|
||||
piCout << "[authorizeServer]" << PIString(info);
|
||||
//*ok = true;
|
||||
}
|
||||
EVENT_HANDLER2(void, passwordCheck, PIByteArray, phash, bool *, ok) {
|
||||
piCout << "[passwordCheck]" << phash.toHex();
|
||||
PIByteArray ph = PICrypt::passwordHash("secret", PIByteArray::fromHex("AABBCCDD"));
|
||||
piCout << "[passwordCheck]" << ph.toHex();
|
||||
if (phash == ph) *ok = true;
|
||||
}
|
||||
EVENT_HANDLER1(void, userEnterPassword, PIString *, password) {
|
||||
*password = "secret";
|
||||
piCout << "[userEnterPassword]" << *password;
|
||||
}
|
||||
EVENT_HANDLER(void, clientConnect) {
|
||||
piCout << "clientConnect OK!";
|
||||
}
|
||||
EVENT_HANDLER(void, serverConnect) {
|
||||
piCout << "serverConnect OK!";
|
||||
}
|
||||
EVENT_HANDLER1(void, f, int, id) {
|
||||
piCout << "finished" << id;
|
||||
}
|
||||
};
|
||||
|
||||
class A: public PIObject {
|
||||
PIOBJECT(A)
|
||||
public:
|
||||
A() {}
|
||||
EVENT_HANDLER2(void, pcf, int, id, PIString*, buff) {
|
||||
piCout << "PICout(" << id << ") finished:" << (*buff);
|
||||
}
|
||||
};
|
||||
*/
|
||||
/*class O {
|
||||
public:
|
||||
O() {piCout << "O";}
|
||||
~O() {piCout << "~O";}
|
||||
};
|
||||
|
||||
class Buffer {
|
||||
public:
|
||||
Buffer() {}
|
||||
template<typename T>
|
||||
static Buffer create() {
|
||||
Buffer ret;
|
||||
ret.data = new T();
|
||||
ret.pdestroy = (void *)(T::~T);
|
||||
return ret;
|
||||
}
|
||||
void destroy() {}
|
||||
void * data;
|
||||
void * pdestroy;
|
||||
};
|
||||
|
||||
|
||||
class __BufferStorage {
|
||||
public:
|
||||
|
||||
};
|
||||
*/
|
||||
int main() {
|
||||
//Buffer b = Buffer::create<O>();
|
||||
|
||||
|
||||
// PIEvaluator eval, eval2;
|
||||
// eval.check("1-1*2");
|
||||
// piCout << eval.evaluate().real();
|
||||
/*eval.setVariable("t", complexd(1, 2));
|
||||
eval.check("(t*t*(t<8))+(72*(t>8)-8*(9-t)*(9-t)*(t>8)*(t<8.8))+(3*(t-8.8)*(t>8.8))");
|
||||
PIByteArray ba = eval.save();
|
||||
piCout << ba.size();
|
||||
PITimeMeasurer tm; double us = 0.;
|
||||
|
||||
tm.reset();
|
||||
PIEvaluator e1;
|
||||
piForTimes(100) {
|
||||
e1.setVariable("t", complexd(1, 2));
|
||||
e1.check("(t*t*(t<8))+(72*(t>8)-8*(9-t)*(9-t)*(t>8)*(t<8.8))+(3*(t-8.8)*(t>8.8))");
|
||||
complexd ret = e1.evaluate();
|
||||
}
|
||||
us = tm.elapsed_u(); piCout << "check" << us / 100.;
|
||||
|
||||
tm.reset();
|
||||
PIEvaluator e2;
|
||||
e2.load(ba);
|
||||
piForTimes(10000) {
|
||||
e2.setVariable("t", complexd(1, 2));
|
||||
complexd ret = e2.evaluate();
|
||||
}
|
||||
us = tm.elapsed_u(); piCout << " save" << us / 10000.;*/
|
||||
|
||||
|
||||
|
||||
/*A a;
|
||||
CONNECTU(PICout::Notifier::object(), finished, &a, pcf);
|
||||
PIString buffer = "my buff:";
|
||||
PICout(&buffer, 1) << "int 10 ->" << 10 << ", time ->" << PITime::current();*/
|
||||
/*PISerial ser(PISerial::availableDevices(false)[0], PISerial::S115200);
|
||||
piCout << ser.constructFullPath();
|
||||
piCout << ser.open();
|
||||
ser.startThreadedRead();
|
||||
FOREVER {
|
||||
piCout << ser.isOpened();
|
||||
piMSleep(200);
|
||||
}*/
|
||||
/*PIVector<PIFile::FileInfo> fl = PIDir::current().allEntries();
|
||||
PIFile out("out.txt", PIIODevice::ReadWrite);
|
||||
out.clear();
|
||||
piForeachC (PIFile::FileInfo & f, fl) {
|
||||
PIString e = f.extension();
|
||||
PIString comm;
|
||||
if (e == "h") comm = PIString::fromUTF8("Заголовочный файл");
|
||||
if (e == "cpp") comm = PIString::fromUTF8("Файл релизации");
|
||||
if (e == "ui") comm = PIString::fromUTF8("Форма");
|
||||
if (e == "qrc") comm = PIString::fromUTF8("Файл ресурсов");
|
||||
if (comm.isEmpty()) continue;
|
||||
out << "\n\n" << comm << ": " << f.name() << "\n";
|
||||
PIFile file(f.name(), PIIODevice::ReadOnly);
|
||||
while (!file.isEnd()) {
|
||||
PIString line = file.readLine(), tl = line.trimmed();
|
||||
if (tl.isEmpty() || tl.startsWith("//")) continue;
|
||||
out << line << "\n";
|
||||
}
|
||||
}*/
|
||||
|
||||
return 0;
|
||||
/*}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
Obj o;
|
||||
CONNECTU(PICout::Notifier::object(), finished, &o, f);
|
||||
PIString s = "!!!";
|
||||
piCout << s;
|
||||
PICout(&s, 1) << "now" << PIDateTime::current() << ", int 1 =" << 1;
|
||||
piCout << s;*/
|
||||
|
||||
/*piCout << "start";
|
||||
PICrypt crypt;
|
||||
PIByteArray skey1, pkey1;
|
||||
crypt.generateKeypair(pkey1, skey1);
|
||||
PIByteArray skey2, pkey2;
|
||||
crypt.generateKeypair(pkey2, skey2);
|
||||
PIByteArray sign = PIAuth::generateSign(PICrypt::generateKey());
|
||||
piCout << "sign" << sign.toHex();
|
||||
|
||||
piCout << "key1 " << pkey1.toHex() << skey1.toHex();
|
||||
piCout << "key2 " << pkey2.toHex() << skey2.toHex();
|
||||
PIString msg = "what the f*ck?";
|
||||
PIByteArray ba = msg.toUTF8();
|
||||
piCout << "source" << ba.toHex() << msg;
|
||||
PIByteArray cba = crypt.crypt(ba, pkey2, skey1);
|
||||
PIByteArray psign = crypt.extractSignPublicKey(sign);
|
||||
PIByteArray scba = crypt.signMessage(cba, sign);
|
||||
piCout << "crypted" << cba.toHex();
|
||||
piCout << "signed" << scba.toHex() << psign.toHex();
|
||||
PIByteArray dba = crypt.decrypt(cba, pkey1, skey2);
|
||||
piCout << "decrypted" << dba.toHex() << PIString(dba);
|
||||
piCout << "verify" << crypt.verifySign(cba, scba, psign);
|
||||
cba = crypt.crypt(ba, pkey1, skey2);
|
||||
piCout << "crypted" << cba.toHex();
|
||||
//cba[7] = 0;
|
||||
dba = crypt.decrypt(cba, pkey2, skey1);
|
||||
piCout << "decrypted" << dba.toHex() << PIString(dba);
|
||||
|
||||
|
||||
|
||||
|
||||
piCout << "=======================================";
|
||||
|
||||
PIAuth server(PIAuth::generateSign(pkey1));
|
||||
|
||||
msg = "This is Server with PIAuth";
|
||||
server.setInfoData(msg.toUTF8());
|
||||
|
||||
PIAuth client(PIAuth::generateSign(pkey2));
|
||||
|
||||
client.setAuthorizedPublicKeys(PIVector<PIByteArray>() << server.getSignPublicKey());
|
||||
// server.setAuthorizedPublicKeys(PIVector<PIByteArray>() << client.getSignPublicKey());
|
||||
Obj o;
|
||||
CONNECTU(&client, authorize, &o, authorizeServer);
|
||||
CONNECTU(&client, passwordRequest, &o, userEnterPassword);
|
||||
CONNECTU(&server, passwordCheck, &o, passwordCheck);
|
||||
CONNECTU(&client, connected, &o, clientConnect);
|
||||
CONNECTU(&server, connected, &o, serverConnect);
|
||||
client.startClient();
|
||||
ba = server.startServer();
|
||||
int st = PIAuth::AuthProbe;
|
||||
piCout << "server" << st << ba.toHex() << ba.size();*/
|
||||
|
||||
|
||||
|
||||
// ba[40] = 2;
|
||||
// {
|
||||
// int s;
|
||||
// ba >> s;
|
||||
// PIByteArray rinfo;
|
||||
// PIByteArray rsign;
|
||||
// PIByteArray rsign_pk;
|
||||
// PIByteArray box_pk;
|
||||
// PIByteArray noise;
|
||||
// ba >> rinfo >> rsign_pk >> box_pk >> noise >> rsign;
|
||||
// ba.clear();
|
||||
// PIByteArray sign2 = PIAuth::generateSign(PICrypt::generateRandomBuff(100));
|
||||
// msg = "Server";
|
||||
// ba << s << msg.toUTF8() << crypt.extractSignPublicKey(sign2) << box_pk << noise;
|
||||
// rsign = crypt.signMessage(ba, sign2);
|
||||
// ba << rsign;
|
||||
// }
|
||||
|
||||
|
||||
/*
|
||||
st = client.receive(ba);
|
||||
piCout << "client" << st << ba.toHex() << ba.size();
|
||||
st = server.receive(ba);
|
||||
piCout << "server" << st << ba.toHex() << ba.size();
|
||||
st = client.receive(ba);
|
||||
piCout << "client" << st << ba.toHex() << ba.size();
|
||||
st = server.receive(ba);
|
||||
piCout << "server" << st << ba.toHex() << ba.size();
|
||||
st = client.receive(ba);
|
||||
piCout << "client" << st << ba.toHex() << ba.size();
|
||||
st = server.receive(ba);
|
||||
piCout << "server" << st << ba.toHex() << ba.size();
|
||||
st = client.receive(ba);
|
||||
piCout << "client" << st << ba.toHex() << ba.size();
|
||||
st = server.receive(ba);
|
||||
piCout << "server" << st << ba.toHex() << ba.size();*/
|
||||
PIByteArray msg = PIByteArray::fromHex("0110f0f00001020001");
|
||||
PIByteArray src = PIByteArray::fromHex("836f");
|
||||
ushort s; memcpy(&s, src.data(), 2);
|
||||
//CRC_16 crc = standardCRC_16();
|
||||
CRC_16 crc = CRC_16(0x8005, 0xFFFF, 0xFFFF, false);
|
||||
piCout << PICoutManipulators::Hex << s;
|
||||
piCout << PICoutManipulators::Hex << crc.calculate(msg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user