Skip to content

Commit 538fedd

Browse files
ryanofskyTheCharlatan
authored andcommitted
common: Add ECC_Context RAII wrapper for ECC_Start/ECC_Stop
1 parent 6f1d906 commit 538fedd

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/key.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,3 +457,13 @@ void ECC_Stop() {
457457
secp256k1_context_destroy(ctx);
458458
}
459459
}
460+
461+
ECC_Context::ECC_Context()
462+
{
463+
ECC_Start();
464+
}
465+
466+
ECC_Context::~ECC_Context()
467+
{
468+
ECC_Stop();
469+
}

src/key.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,4 +245,18 @@ void ECC_Stop();
245245
/** Check that required EC support is available at runtime. */
246246
bool ECC_InitSanityCheck();
247247

248+
/**
249+
* RAII class initializing and deinitializing global state for elliptic curve support.
250+
* Only one instance may be initialized at a time.
251+
*
252+
* In the future global ECC state could be removed, and this class could contain
253+
* state and be passed as an argument to ECC key functions.
254+
*/
255+
class ECC_Context
256+
{
257+
public:
258+
ECC_Context();
259+
~ECC_Context();
260+
};
261+
248262
#endif // BITCOIN_KEY_H

0 commit comments

Comments
 (0)