3

Assume you have a function read_key and normally it does some stuff. You someone should be able to replace it with his function read_key_myfunction and it does other stuff. The general approach would of course be to build an array and register function pointers or using simple switch statements (or both).

But my target is a bit broader: People should be able to write their C-stuff and NOT interfere with my code and it should still register. Of course, I tell them which interface to implement.

彼らが現在基本的に行っていることは、構成オプションに基づいて動的にロードするソフトウェアのライブラリをプログラムすることです。OpenSSL エンジンのようなものと考えてください。誰でも独自のエンジンを作成し、それを dll/so としてコンパイルして配布できます。定義されたインターフェースに固執する限り、OpenSSL コードを変更する (または知る) 必要はありません。

私のプログラムには同じものが必要です(最終的にはOpenSSLエンジン関数のラッパーになります)。

同僚は、すべてのファイルで同じ関数を使用し、ライブラリを動的にロードする必要があると提案しました。これは私にとっては良い解決策のように思えますが、OpenSSL がエンジンコードで非エンジン固有の関数を使用しているのを見たことがないので、私は満足していません。

不明な点がある場合は、私の具体的な例を次に示します。

自動証明書更新用のプロトコルを実装する sscep というプログラムを拡張しています。将来的には、多くの暗号化が HSM で行われる必要があります (現在は、Windows キー管理 (OpenSSL の capi-engine によってアクセスされる) 内で行われる必要があります)。

OpenSSL は既に一般的なインターフェイスを提供していますが、事前にいくつかの作業を行う必要があり、使用するエンジンによって異なります。また、私のコードを掘り下げなくても (私の前の人から持っていたように)、他のすべての人がそれをすばやく拡張できるようにしたいと考えています。

誰かが何か考えを持っているなら、何らかのガイドラインを見ていただければ幸いです。前もって感謝します。

4

1 に答える 1

2

What you are describing is commonly called a plugin architecture/plugin framework. You need to combine cross-platform dlopen/LoadLibrary functionality with some logic for registering and performing lookup of exported functions. You should be able to find examples on how to do this on the internet.

于 2012-06-12T15:38:07.503 に答える