📄 pgpkeyserver.cpp
字号:
static const PGPOptionType sNewKeyServerOptionSet[] =
{
kPGPOptionType_URL,
kPGPOptionType_HostName,
kPGPOptionType_HostAddress,
kPGPOptionType_KeyServerProtocol,
kPGPOptionType_KeyServerKeySpace,
kPGPOptionType_KeyServerAccessType
};
static PGPError
pgpNewKeyServer(
PGPContextRef context,
PGPKeyServerClass serverClass,
PGPKeyServerRef *outKeyServerRef,
PGPOptionListRef optionList)
{
PGPError err;
pgpAssert( pgpContextIsValid( context ) );
pgpAssert( pgpOptionListIsValid( optionList ) );
pgpAssert( IsntNull( outKeyServerRef ) );
err = pgpGetOptionListError( optionList );
if( IsntPGPError( err ) )
{
err = pgpCheckOptionsInSet( optionList, sNewKeyServerOptionSet,
elemsof( sNewKeyServerOptionSet ) );
if( IsntPGPError( err ) )
{
KeyServerOptions options;
err = GatherKeyServerOptions( optionList, &options );
if( IsntPGPError( err ) )
{
switch (serverClass) {
case kPGPKeyServerClass_PGP:
{
if( IsntNull( options.url ) )
{
err = PGPNewKeyServerFromURL( context, options.url,
options.accessType, options.keySpace,
outKeyServerRef );
}
else if( IsntNull( options.hostName ) )
{
err = PGPNewKeyServerFromHostName( context, options.hostName,
options.hostPort, options.protocol,
options.accessType, options.keySpace,
outKeyServerRef );
}
else
{
err = PGPNewKeyServerFromHostAddress( context,
options.hostAddress, options.hostPort,
options.protocol, options.accessType,
options.keySpace, outKeyServerRef );
}
}
break;
case kPGPKeyServerClass_NetToolsCA:
case kPGPKeyServerClass_Verisign:
case kPGPKeyServerClass_Entrust:
{
err = pgpNewX509KeyServer(context, serverClass, &options, outKeyServerRef);
}
break;
default:
{
pgpDebugMsg( "Server class unimplemented" );
err = kPGPError_FeatureNotAvailable;
}
break;
}
}
}
}
return( err );
}
PGPError
PGPNewKeyServer(
PGPContextRef context,
PGPKeyServerClass serverClass,
PGPKeyServerRef *outKeyServerRef,
PGPOptionListRef firstOption,
... )
{
PGPError err = kPGPError_NoErr;
va_list args;
pgpAssert( pgpContextIsValid( context ) );
pgpAssert( serverClass >= kPGPKeyServerClass_PGP &&
serverClass <= kPGPKeyServerClass_Entrust );
pgpAssert( IsntNull( outKeyServerRef ) );
if( IsntNull( outKeyServerRef ) )
*outKeyServerRef = kInvalidPGPKeyServerRef;
if( pgpContextIsValid( context ) &&
( serverClass >= kPGPKeyServerClass_PGP &&
serverClass <= kPGPKeyServerClass_Entrust ) &&
IsntNull( outKeyServerRef ) )
{
PGPOptionListRef optionList;
va_start( args, firstOption );
optionList = pgpBuildOptionListArgs(context, FALSE, firstOption, args);
va_end( args );
err = pgpNewKeyServer( context, serverClass, outKeyServerRef, optionList );
PGPFreeOptionList( optionList );
}
else
{
va_start( args, firstOption );
pgpFreeVarArgOptionList( firstOption, args );
va_end( args );
err = kPGPError_BadParams;
}
return( err );
}
PGPError
PGPFreeKeyServer(
PGPKeyServerRef inKeyServerRef)
{
PGPError result = kPGPError_NoErr;
PGPBoolean freed = false;
try {
// Validation
PGPValidatePtr(inKeyServerRef);
if (((CKeyServer *) inKeyServerRef)->IsBusy()) {
ThrowPGPError_(kPGPError_ServerInProgress);
} else {
((CKeyServer *) inKeyServerRef)->SetBusy(true);
}
try {
freed = ((CKeyServer *) inKeyServerRef)->Free();
}
catch (...) {
#if PGP_WIN32
if (! freed) {
/* Server still refcounted. Clear busy flag */
((CKeyServer *) inKeyServerRef)->SetBusy(false);
}
throw;
#endif
}
if (! freed) {
/* Server still refcounted. Clear busy flag */
((CKeyServer *) inKeyServerRef)->SetBusy(false);
}
}
catch (PGPError exception) {
result = MapErrors(exception);
}
#if !PGP_WIN32
catch (...) {
result = kPGPError_UnknownError;
}
#endif
return result;
}
PGPError
PGPIncKeyServerRefCount(
PGPKeyServerRef inKeyServerRef)
{
PGPError result = kPGPError_NoErr;
try {
// Validation
PGPValidatePtr(inKeyServerRef);
((CKeyServer *) inKeyServerRef)->IncRefCount();
}
catch (PGPError exception) {
result = MapErrors(exception);
}
#if !PGP_WIN32
catch (...) {
result = kPGPError_UnknownError;
}
#endif
return result;
}
PGPError
PGPSetKeyServerEventHandler(
PGPKeyServerRef inKeyServerRef,
PGPEventHandlerProcPtr inCallback,
PGPUserValue inUserData)
{
PGPError result = kPGPError_NoErr;
try {
// Validation
PGPValidatePtr(inKeyServerRef);
StKeyServerBusy busyKeyServer((CKeyServer *) inKeyServerRef);
((CKeyServer *) inKeyServerRef)->SetEventHandler( inCallback,
inUserData);
}
catch (PGPError exception) {
result = MapErrors(exception);
}
#if !PGP_WIN32
catch (...) {
result = kPGPError_UnknownError;
}
#endif
return result;
}
PGPError
PGPGetKeyServerEventHandler(
PGPKeyServerRef inKeyServerRef,
PGPEventHandlerProcPtr * outCallback,
PGPUserValue * outUserData)
{
PGPError result = kPGPError_NoErr;
try {
// Validation
PGPValidatePtr(inKeyServerRef)
PGPValidatePtr(outCallback)
*outCallback = 0;
PGPValidatePtr(outUserData)
*outUserData = 0;
StKeyServerBusy busyKeyServer((CKeyServer *) inKeyServerRef);
((CKeyServer *) inKeyServerRef)->GetEventHandler( *outCallback,
*outUserData);
}
catch (PGPError exception) {
result = MapErrors(exception);
}
#if !PGP_WIN32
catch (...) {
result = kPGPError_UnknownError;
}
#endif
return result;
}
PGPError
PGPKeyServerOpen(
PGPKeyServerRef inKeyServerRef,
PGPtlsSessionRef inTLSSessionRef)
{
PGPError result = kPGPError_NoErr;
try {
// Validation
PGPValidatePtr(inKeyServerRef);
PGPValidateParam((inTLSSessionRef == kInvalidPGPtlsSessionRef)
|| PGPtlsSessionRefIsValid(inTLSSessionRef));
StKeyServerBusy busyKeyServer((CKeyServer *) inKeyServerRef);
((CKeyServer *) inKeyServerRef)->Open(inTLSSessionRef);
}
catch (PGPError exception) {
result = MapErrors(exception);
}
#if !PGP_WIN32
catch (...) {
result = kPGPError_UnknownError;
}
#endif
return result;
}
PGPError
PGPKeyServerClose(
PGPKeyServerRef inKeyServerRef)
{
PGPError result = kPGPError_NoErr;
try {
// Validation
PGPValidatePtr(inKeyServerRef);
StKeyServerBusy busyKeyServer((CKeyServer *) inKeyServerRef, true);
((CKeyServer *) inKeyServerRef)->Close();
}
catch (PGPError exception) {
result = MapErrors(exception);
}
#if !PGP_WIN32
catch (...) {
result = kPGPError_UnknownError;
}
#endif
return result;
}
PGPError
PGPGetKeyServerTLSSession(
PGPKeyServerRef inKeyServerRef,
PGPtlsSessionRef * outTLSSessionRef)
{
PGPError result = kPGPError_NoErr;
try {
// Validation
PGPValidatePtr(outTLSSessionRef);
*outTLSSessionRef = 0;
PGPValidatePtr(inKeyServerRef);
StKeyServerBusy busyKeyServer((CKeyServer *) inKeyServerRef);
((CKeyServer *) inKeyServerRef)->GetTLSSession(*outTLSSessionRef);
}
catch (PGPError exception) {
result = MapErrors(exception);
}
#if !PGP_WIN32
catch (...) {
result = kPGPError_UnknownError;
}
#endif
return result;
}
#if PGP_DEPRECATED /* [ */
PGPError
PGPGetKeyServerType(
PGPKeyServerRef inKeyServerRef,
PGPKeyServerType * outType)
{
return( PGPGetKeyServerProtocol( inKeyServerRef, outType ) );
}
#endif /* ] PGP_DEPRECATED */
PGPError
PGPGetKeyServerProtocol(
PGPKeyServerRef inKeyServerRef,
PGPKeyServerProtocol * outProtocol)
{
PGPError result = kPGPError_NoErr;
try {
// Validation
PGPValidatePtr(outProtocol);
PGPValidatePtr(inKeyServerRef);
StKeyServerBusy busyKeyServer((CKeyServer *) inKeyServerRef);
((CKeyServer *) inKeyServerRef)->GetProtocol(*outProtocol);
}
catch (PGPError exception) {
result = MapErrors(exception);
}
#if !PGP_WIN32
catch (...) {
result = kPGPError_UnknownError;
}
#endif
return result;
}
PGPError
PGPGetKeyServerAccessType(
PGPKeyServerRef inKeyServerRef,
PGPKeyServerAccessType * outAccessType)
{
PGPError result = kPGPError_NoErr;
try {
// Validation
PGPValidatePtr(outAccessType);
PGPValidatePtr(inKeyServerRef);
StKeyServerBusy busyKeyServer((CKeyServer *) inKeyServerRef);
((CKeyServer *) inKeyServerRef)->GetAccessType(*outAccessType);
}
catch (PGPError exception) {
result = MapErrors(exception);
}
#if !PGP_WIN32
catch (...) {
result = kPGPError_UnknownError;
}
#endif
return result;
}
PGPError
PGPGetKeyServerKeySpace(
PGPKeyServerRef inKeyServerRef,
PGPKeyServerKeySpace * outKeySpace)
{
PGPError result = kPGPError_NoErr;
try {
// Validation
PGPValidatePtr(outKeySpace);
PGPValidatePtr(inKeyServerRef);
StKeyServerBusy busyKeyServer((CKeyServer *) inKeyServerRef);
((CKeyServer *) inKeyServerRef)->GetKeySpace(*outKeySpace);
}
catch (PGPError exception) {
result = MapErrors(exception);
}
#if !PGP_WIN32
catch (...) {
result = kPGPError_UnknownError;
}
#endif
return result;
}
PGPError
PGPGetKeyServerPort(
PGPKeyServerRef inKeyServerRef,
PGPUInt16 * outPort)
{
PGPError result = kPGPError_NoErr;
try {
// Validation
PGPValidatePtr(outPort);
*outPort = 0;
PGPValidatePtr(inKeyServerRef);
StKeyServerBusy busyKeyServer((CKeyServer *) inKeyServerRef);
((CKeyServer *) inKeyServerRef)->GetPort(*outPort);
}
catch (PGPError exception) {
result = MapErrors(exception);
}
#if !PGP_WIN32
catch (...) {
result = kPGPError_UnknownError;
}
#endif
return result;
}
PGPError
PGPGetKeyServerHostName(
PGPKeyServerRef inKeyServerRef,
char ** outHostName)
{
PGPError result = kPGPError_NoErr;
try {
// Validation
PGPValidatePtr(outHostName);
*outHostName = 0;
PGPValidatePtr(inKeyServerRef);
StKeyServerBusy busyKeyServer((CKeyServer *) inKeyServerRef);
((CKeyServer *) inKeyServerRef)->GetHostName(outHostName);
}
catch (PGPError exception) {
result = MapErrors(exception);
}
#if !PGP_WIN32
catch (...) {
result = kPGPError_UnknownError;
}
#endif
return result;
}
PGPError
PGPGetKeyServerAddress(
PGPKeyServerRef inKeyServerRef,
PGPUInt32 * outAddress)
{
PGPError result = kPGPError_NoErr;
try {
// Validation
PGPValidatePtr(outAddress);
*outAddress = 0;
PGPValidatePtr(inKeyServerRef);
StKeyServerBusy busyKeyServer((CKeyServer *) inKeyServerRef);
((CKeyServer *) inKeyServerRef)->GetAddress(*outAddress);
}
catch (PGPError exception) {
result = MapErrors(exception);
}
#if !PGP_WIN32
catch (...) {
result = kPGPError_UnknownError;
}
#endif
return result;
}
PGPError
PGPGetKeyServerPath(
PGPKeyServerRef inKeyServerRef,
char ** outPath)
{
PGPError result = kPGPError_NoErr;
try {
// Validation
PGPValidatePtr(outPath);
*outPath = 0;
PGPValidatePtr(inKeyServerRef);
StKeyServerBusy busyKeyServer((CKeyServer *) inKeyServerRef);
((CKeyServer *) inKeyServerRef)->GetPath(outPath);
}
catch (PGPError exception) {
result = MapErrors(exception);
}
#if !PGP_WIN32
catch (...) {
result = kPGPError_UnknownError;
}
#endif
return result;
}
PGPError
PGPGetLastKeyServerErrorString(
PGPKeyServerRef inKeyServerRef,
char ** outErrorString)
{
PGPError result = kPGPError_NoErr;
try {
// Validation
PGPValidatePtr(outErrorString);
*outErrorString = 0;
PGPValidatePtr(inKeyServerRef);
StKeyServerBusy busyKeyServer((CKeyServer *) inKeyServerRef);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -