📄 pgpcontext.c
字号:
err = PGPReallocData( context->memoryMgr,
allocation, requestSize, flags );
return( err );
}
/*____________________________________________________________________________
Free a block of memory using the deallocator stored in a PGPContext.
____________________________________________________________________________*/
PGPError
pgpContextMemFree(
PGPContextRef context,
void * allocation)
{
PGPError err;
PGPValidateContext( context );
(void)context;
err = PGPFreeData( allocation );
return( err );
}
PGPError
PGPGetContextUserValue(
PGPContextRef context,
PGPUserValue *userValue)
{
PGPError err = kPGPError_NoErr;
PGPValidatePtr( userValue );
*userValue = NULL;
PGPValidateContext( context );
*userValue = context->userValue;
return( err );
}
PGPMemoryMgrRef
PGPGetContextMemoryMgr( PGPContextRef context )
{
if ( ! pgpContextIsValid( context ) )
return( NULL );
return( context->memoryMgr );
}
PGPError
PGPSetContextUserValue(
PGPContextRef context,
PGPUserValue userValue)
{
PGPError err = kPGPError_NoErr;
PGPValidateContext( context );
context->userValue = userValue;
return( err );
}
PGPEnv *
pgpContextGetEnvironment(PGPContextRef context)
{
pgpAssert( pgpContextIsValid( context ) );
return( context->pgpEnvironment );
}
static PGPError
sCreateRandomContext(
PGPContextRef context,
PGPRandomVTBL const * vtbl,
PGPRandomContext ** outRandom )
{
PGPError err = kPGPError_NoErr;
PGPRandomContext * newRandom = NULL;
pgpAssert( pgpContextIsValid( context ) );
newRandom = (PGPRandomContext *)
pgpContextMemAlloc( context, sizeof( *newRandom ),
kPGPMemoryMgrFlags_Clear );
if ( IsntNull( newRandom ) )
{
newRandom->context = context;
newRandom->vtbl = vtbl;
newRandom->priv = NULL;
newRandom->destroy = NULL;
}
else
{
err = kPGPError_OutOfMemory;
}
*outRandom = newRandom;
return( err );
}
PGPRandomContext *
pgpContextGetGlobalPoolRandomContext(PGPContextRef context)
{
pgpAssert( pgpContextIsValid( context ) );
if ( IsNull( context->randomPoolContext ) )
{
PGPRandomContext * randomContext = NULL;
(void)sCreateRandomContext( context,
pgpGetGlobalRandomPoolVTBL(), &randomContext );
context->randomPoolContext = randomContext;
if ( IsntNull( context->randomPoolContext ) )
{
/*
* in case there is a problem in reading the random pool,
* feed in some amount of "random" data to avoid a totally
* predictible pool
*/
pgpRandomCollectEntropy( randomContext );
pgpRandomCollectEntropy( randomContext );
pgpRandomCollectEntropy( randomContext );
pgpRandomCollectEntropy( randomContext );
}
}
/* NOTE: someone must still call pgpSeedGlobalRandomPool() */
return( context->randomPoolContext );
}
PGPRandomContext *
pgpContextGetDummyRandomContext(PGPContextRef context)
{
pgpAssert( pgpContextIsValid( context ) );
if ( IsNull( context->dummyRandomContext ) )
{
(void)sCreateRandomContext( context,
pgpGetGlobalDummyRandomPoolVTBL(),
&context->dummyRandomContext );
}
return( context->dummyRandomContext );
}
PGPRandomContext *
pgpContextGetX9_17RandomContext(PGPContextRef context)
{
pgpAssert( pgpContextIsValid( context ) );
if ( IsNull( context->randomPoolX9_17 ) )
{
context->randomPoolX9_17 = pgpRandomCreate( context );
}
return( context->randomPoolX9_17 );
}
/*____________________________________________________________________________
Fill the user-specified buffer with random values from the global
random pool. If we were not able to initialize the random pool
we return kPGPError_OutOfEntropy.
____________________________________________________________________________*/
PGPError
PGPContextGetRandomBytes(
PGPContextRef context,
void * buf,
PGPSize len
)
{
PGPRandomContext * randomContext;
PGPValidatePtr( buf );
PGPValidateParam( pgpContextIsValid( context ) );
randomContext = pgpContextGetX9_17RandomContext( context );
if( IsNull( randomContext )
|| !PGPGlobalRandomPoolHasMinimumEntropy() )
{
return kPGPError_OutOfEntropy;
}
pgpRandomGetBytes( randomContext, buf, len );
return kPGPError_NoErr;
}
RingPool *
pgpContextGetRingPool(PGPContextRef context)
{
pgpAssert( pgpContextIsValid( context ) );
return( context->ringPool );
}
void
pgpContextSetRingPool(
PGPContextRef context,
RingPool *ringPool)
{
pgpAssert( pgpContextIsValid( context ) );
context->ringPool = ringPool;
}
PGPKeySetRef
pgpContextGetDefaultKeySet(PGPContextRef context)
{
pgpAssert( pgpContextIsValid( context ) );
return( context->defaultKeySet );
}
/* We may retire the prefs stuff, but this is for transition at least */
void
pgpContextSetPrefsChanged(
PGPContextRef context,
PGPBoolean prefsChanged
)
{
context->prefsChanged = prefsChanged;
}
PGPBoolean
pgpContextArePrefsChanged(
PGPContextRef context
)
{
return context->prefsChanged;
}
PGPPrefRef
pgpContextGetPrefs( PGPContextRef context)
{
return( context->prefsRef );
}
void
pgpContextSetPrefs(
PGPContextRef context,
PGPPrefRef prefs )
{
context->prefsRef = prefs;
}
static PGPUInt32 sInitedCount = 0;
static PGPBoolean sFreeMemoryMgrList = FALSE;
PGPError
PGPsdkInit( void )
{
PGPError err = kPGPError_NoErr;
if ( sInitedCount == 0 )
{
pgpLeaksBeginSession( "PGPsdk" );
if( IsNull( PGPGetDefaultMemoryMgr() ) )
{
PGPMemoryMgrRef memoryMgr;
sFreeMemoryMgrList = TRUE;
err = PGPNewMemoryMgr( 0, &memoryMgr );
pgpAssertNoErr( err );
if( IsntPGPError( err ) )
{
err = PGPSetDefaultMemoryMgr( memoryMgr );
pgpAssertNoErr( err );
}
}
if( IsntPGPError( err ) )
{
err = pgpInitMacBinaryMappings();
pgpAssertNoErr( err );
}
if( IsntPGPError( err ) )
{
bnInit();
}
}
if ( IsntPGPError( err ) )
{
++sInitedCount;
}
return( err );
}
PGPBoolean
pgpsdkIsInited( void )
{
return( sInitedCount != 0 );
}
PGPError
pgpForceSDKCleanup( void )
{
PGPError err = kPGPError_NoErr;
if ( sInitedCount != 0 )
{
sInitedCount = 1;
}
err = PGPsdkCleanup();
return( err );
}
PGPError
PGPsdkCleanup( void )
{
PGPError err = kPGPError_NoErr;
pgpAssert( sInitedCount != 0 );
if ( sInitedCount != 0 )
{
--sInitedCount;
if ( sInitedCount == 0 )
{
pgpDisposeMacBinaryMappings();
if( sFreeMemoryMgrList )
pgpFreeDefaultMemoryMgrList();
pgpLeaksEndSession();
}
}
else
{
err = kPGPError_BadParams;
}
return( err );
}
/*__Editor_settings____
Local Variables:
tab-width: 4
End:
vi: ts=4 sw=4
vim: si
_____________________*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -