more robust implementation and better interface to engine registrator; refs #11
This commit is contained in:
@@ -180,33 +180,40 @@ namespace openssl {
|
||||
}
|
||||
static int init(ENGINE* e) {
|
||||
OPENSSL_LOG("log");
|
||||
return _map[e]->init();
|
||||
Map::iterator it(_map.find(e));
|
||||
return it!=_map.end()?it->second->init():0;
|
||||
}
|
||||
static int finish(ENGINE* e) {
|
||||
OPENSSL_LOG("log");
|
||||
return _map[e]->finish();
|
||||
Map::iterator it(_map.find(e));
|
||||
return it!=_map.end()?it->second->finish():0;
|
||||
}
|
||||
static int ctrl(ENGINE* e, int cmd, long i, void* p, void(*f)()) {
|
||||
OPENSSL_LOG("log");
|
||||
return _map[e]->ctrl(cmd, i, p, f);
|
||||
Map::iterator it(_map.find(e));
|
||||
return it!=_map.end()?it->second->ctrl(cmd, i, p, f):0;
|
||||
}
|
||||
static EVP_PKEY* pubkey(ENGINE* e, const char* c, UI_METHOD* u, void* d) {
|
||||
OPENSSL_LOG("log");
|
||||
return _map[e]->pubkey(c, u, d);
|
||||
Map::iterator it(_map.find(e));
|
||||
return it!=_map.end()?it->second->pubkey(c, u, d):0;
|
||||
}
|
||||
static EVP_PKEY* privkey(ENGINE* e, const char* c, UI_METHOD* u, void* d) {
|
||||
OPENSSL_LOG("log");
|
||||
return _map[e]->privkey(c, u, d);
|
||||
Map::iterator it(_map.find(e));
|
||||
return it!=_map.end()?it->second->privkey(c, u, d):0;
|
||||
}
|
||||
static int rsaEncrypt(int flen,const unsigned char *from,
|
||||
unsigned char *to,
|
||||
RSA *rsa, int padding) {
|
||||
OPENSSL_LOG("log");
|
||||
return _map[rsa->engine]->rsaEncrypt();
|
||||
Map::iterator it(_map.find(rsa->engine));
|
||||
return it!=_map.end()?it->second->rsaEncrypt():0;
|
||||
}
|
||||
static int rsaDecrypt(int flen, const unsigned char *from, unsigned char *to, RSA *rsa, int padding) {
|
||||
OPENSSL_LOG("log");
|
||||
return _map[rsa->engine]->rsaDecrypt();
|
||||
Map::iterator it(_map.find(rsa->engine));
|
||||
return it!=_map.end()?it->second->rsaDecrypt():0;
|
||||
}
|
||||
static int rsaSign(int type, const unsigned char *from,
|
||||
unsigned int flen,
|
||||
@@ -214,9 +221,11 @@ namespace openssl {
|
||||
unsigned int*tlen,
|
||||
const RSA *rsa) {
|
||||
OPENSSL_LOG("log");
|
||||
Map::iterator it(_map.find(rsa->engine));
|
||||
if (it==_map.end()) return 0;
|
||||
try {
|
||||
std::string res(_map[rsa->engine]
|
||||
->rsaSign(std::string((const char*)from, flen),
|
||||
std::string res(it->second->rsaSign
|
||||
(std::string((const char*)from, flen),
|
||||
type));
|
||||
OPENSSL_LOG("to="<<(void*)to<<"; len="<<*tlen);
|
||||
OPENSSL_LOG("siglen="<<res.size());
|
||||
@@ -232,11 +241,13 @@ namespace openssl {
|
||||
unsigned int, OPENSSL_V0_CONST unsigned char*,
|
||||
unsigned int, const RSA* rsa) {
|
||||
OPENSSL_LOG("log");
|
||||
return _map[rsa->engine]->rsaVerify();
|
||||
Map::iterator it(_map.find(rsa->engine));
|
||||
return it!=_map.end()?it->second->rsaVerify():0;
|
||||
}
|
||||
static int rsaFinish(RSA *rsa) {
|
||||
OPENSSL_LOG("log");
|
||||
return _map[rsa->engine]->rsaFinish();
|
||||
Map::iterator it(_map.find(rsa->engine));
|
||||
return it!=_map.end()?it->second->rsaFinish():0;
|
||||
}
|
||||
|
||||
protected:
|
||||
@@ -261,7 +272,8 @@ namespace openssl {
|
||||
|
||||
private:
|
||||
|
||||
static std::map<ENGINE*, Engine*> _map;
|
||||
typedef std::map<ENGINE*, Engine*> Map;
|
||||
static Map _map;
|
||||
static std::map<std::string, Engine*> _prototypes;
|
||||
};
|
||||
|
||||
@@ -270,10 +282,19 @@ namespace openssl {
|
||||
class RegisterEngine {
|
||||
public:
|
||||
RegisterEngine(Engine* e): _e(e) {
|
||||
EngineMapper::add(_e);
|
||||
if (_e) EngineMapper::add(_e);
|
||||
}
|
||||
~RegisterEngine() {
|
||||
EngineMapper::remove(_e);
|
||||
if (_e) EngineMapper::remove(_e);
|
||||
}
|
||||
operator Engine*() {
|
||||
return _e;
|
||||
}
|
||||
Engine* operator->() {
|
||||
return _e;
|
||||
}
|
||||
Engine& operator*() {
|
||||
return *_e;
|
||||
}
|
||||
private:
|
||||
Engine* _e;
|
||||
|
Reference in New Issue
Block a user