more robust implementation and better interface to engine registrator; refs #11

master
Marc Wäckerlin 14 years ago
parent 980c9d0e09
commit 95efe61822
  1. 49
      src/openssl-engine.hxx

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

Loading…
Cancel
Save