Snake/SnakeServer/ClientProtocol/rsakeyspool.cpp

28 lines
617 B
C++
Raw Normal View History

2019-06-09 17:15:50 +03:00
#include "rsakeyspool.h"
#include <QMutexLocker>
namespace ClientProtocol {
bool RSAKeysPool::take(QRSAEncryption::Rsa rsa, RSAKeyPair& res) {
QMutexLocker locker(&multithread);
if (pool.value(rsa).isEmpty()) {
emit sigKeyTaked();
return false;
}
res = pool.value(rsa).begin().value();
return true;
}
void RSAKeysPool::addNewKey(QRSAEncryption::Rsa rsa, const RSAKeyPair& key) {
QMutexLocker locker(&multithread);
pool[rsa].insert(static_cast<int>(time(nullptr)), key);
}
int RSAKeysPool::size(QRSAEncryption::Rsa rsa) const {
return pool.value(rsa).size();
}
}