⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pgprecipientdialogcommon.cpp

📁 PGP8.0源码 请认真阅读您的文件包然后写出其具体功能
💻 CPP
📖 第 1 页 / 共 5 页
字号:
		}
		
		if( IsntPGPError( err ) )
		{
			PGPBoolean	isAxiomaticKey;
			
			err = PGPGetKeyDBObjBooleanProperty( keyRef, kPGPKeyProperty_IsAxiomatic,
								&isAxiomaticKey );
								
			theKey->isAxiomaticKey = isAxiomaticKey;
		}

		if( IsntPGPError( err ) )
		{
			PGPBoolean	isSecretKey;
			
			err = PGPGetKeyDBObjBooleanProperty( keyRef, kPGPKeyProperty_IsSecret,
						&isSecretKey );
			
			theKey->isSecretKey = isSecretKey;
		}	
		
		if( IsntPGPError( err ) )
		{
			PGPBoolean	canEncrypt;
			
			err = PGPGetKeyDBObjBooleanProperty( keyRef, kPGPKeyProperty_CanEncrypt,
						&canEncrypt );
								
			theKey->canEncrypt = canEncrypt;
		}

		if( IsntPGPError( err ) )
		{
			PGPInt32	keyBits;
			
			err = PGPGetKeyDBObjNumericProperty( keyRef, kPGPKeyProperty_Bits, &keyBits );

			theKey->keyBits = (PGPUInt16) keyBits;
		}
			
		if( IsntPGPError( err ) )
		{
			// Iterate our one-key set to the first key
			
			if( theKey->algorithm == kPGPPublicKeyAlgorithm_DSA )
			{
				PGPKeyDBObjRef	subKey;

				// Get the subkey to determine the
				// encryption key bits.
					
				err = PGPKeyIterNextKeyDBObj( iterator, kPGPKeyDBObjType_SubKey, &subKey );
				if( IsntPGPError( err ) )
				{
					PGPInt32	keyBits;
					
					err = PGPGetKeyDBObjNumericProperty( subKey, kPGPSubKeyProperty_Bits,
								&keyBits );
					
					theKey->subKeyBits = (PGPUInt16) keyBits;
				}
				
				if( err == kPGPError_EndOfIteration )
					err = kPGPError_NoErr;
			}
			
			if( IsntPGPError( err ) )
			{
				err = UpdateKeyUserIDs( recipients, theKey, iterator, NULL );
			}
		}
		
		if( IsntPGPError( err ) )
		{
			pgpAssert( IsntNull( theKey->users ) );
			
			// Set the primary user to the first user in the list if
			// no explicit or visible primary user was found.
			
			if( IsNull( theKey->primaryUser ) )
				theKey->primaryUser = theKey->users;
				
			// Finally, link key into the list
			theKey->nextKey		= recipients->keys;
			recipients->keys	= theKey;
		}
		else
		{	
			FreeKey( theKey );
			theKey = NULL;
		}
	}
	
	*recipientKey = theKey;
	
	return( err );
}

	static PGPError
UpdateDynamicRecipientValues(PGPRecipientsList *recipients)
{
	PGPRecipientKey		*curKey;
	PGPRecipientUser	*curUser;
	PGPError			err = kPGPError_NoErr;
	
	curKey = recipients->keys;
	while( IsntNull( curKey ) && IsntPGPError( err ) )
	{
		curUser = curKey->users;
		while( IsntNull( curUser ) )
		{
			PGPInt32	userValidity;
							
			if( IsntPGPError( PGPGetKeyDBObjNumericProperty(
							curUser->userInfo.userID,
							kPGPUserIDProperty_Validity, &userValidity ) ) )
			{
				curUser->validity = (PGPValidity) userValidity;
			}
			else
			{
				curUser->validity = kPGPValidity_Invalid;
			}
								
			curUser = curUser->nextUser;
		}
		
		if( recipients->arrEnforcement != kPGPARREnforcement_None )
		{
			err = FindARRKeys( recipients, curKey );
			if( IsPGPError( err ) )
				break;
		}
		
		curKey = curKey->nextKey;
	}

	curUser = recipients->groups;
	while( IsntNull( curUser ) && IsntPGPError( err ) )
	{
		PGPUInt32	groupItemIndex;
		
		curUser->validity 					= kPGPValidity_Complete;
		curUser->groupInfo.numMissingKeys	= 0;
		curUser->groupInfo.haveMissingARRs 	= FALSE;
		curUser->groupInfo.numARRKeys		= 0;
		
		for( groupItemIndex = 0; groupItemIndex < curUser->groupInfo.numKeys;
					++groupItemIndex )
		{
			PGPGroupItem	item;
			
			err = PGPGetIndGroupItem( recipients->groupSet,
						curUser->groupInfo.groupID, groupItemIndex, &item );
			if( IsntPGPError( err ) )
			{
				PGPRecipientKey	*key = NULL;

				if( item.userValue == NULL )
				{
					PGPKeyDBObjRef	theKey;
					
					if( IsntPGPError( PGPFindKeyByKeyID( 
										PGPPeekKeySetKeyDB( recipients->keySet ),
										&item.u.keyID, &theKey ) ) )
					{
						err = PGPGetKeyDBObjUserValue( theKey,
									(PGPUserValue *) &key );
					}
					
					if( IsntPGPError( err ) && IsntNull( key ) )
					{
						err = PGPSetIndGroupItemUserValue( recipients->groupSet,
									curUser->groupInfo.groupID, groupItemIndex,
									(PGPUserValue) key );
					}
				}
				else
				{
					key = (PGPRecipientKey *) item.userValue;
				}
				
				if( IsntNull( key ) )
				{
					if( key->primaryUser->validity < curUser->validity )
						curUser->validity = key->primaryUser->validity;
						
					if( key->haveMissingARRs )
						curUser->groupInfo.haveMissingARRs = TRUE;
						
					curUser->groupInfo.numARRKeys += key->numARRKeys;
				}
				else
				{
					++curUser->groupInfo.numMissingKeys;
				}
			}
			
			if( IsPGPError( err ) )
				break;
		}
	
		curUser = curUser->nextUser;
	}
	
	return( err );
}

	static PGPError
UpdateNewKeys(
	PGPRecipientsList	*recipients,
	PGPBoolean			markAsNew)
{
	PGPError		err;
	PGPKeyListRef	keyList;

	err = PGPOrderKeySet( recipients->keySet, kPGPKeyOrdering_Any, FALSE, &keyList );
	if( IsntPGPError( err ) )
	{
		PGPKeyIterRef	iterator;
		
		err = PGPNewKeyIter( keyList, &iterator );
		if( IsntPGPError( err ) )
		{
			PGPKeyDBObjRef	theKey;
			
			err = PGPKeyIterNextKeyDBObj( iterator, kPGPKeyDBObjType_Key, &theKey );
			while( IsntPGPError( err ) )
			{
				PGPRecipientKey	*recipientKey;

				err = PGPGetKeyDBObjUserValue( theKey,
								(PGPUserValue *) &recipientKey );
				if( IsntPGPError( err ) )
				{
					if( IsNull( recipientKey ) )
					{
						PGPBoolean	isDefault = ( theKey == recipients->defaultKey );
					
						err = AddKey( recipients, iterator, theKey, isDefault,
									markAsNew, &recipientKey );
						if( IsntPGPError( err ) )
						{
							err = PGPSetKeyDBObjUserValue( theKey, recipientKey );
						}
					}
					else
					{
						PGPUInt32	newNewUserIDs;
						
						err = UpdateKeyUserIDs( recipients, recipientKey, iterator, &newNewUserIDs );
						if( IsntPGPError( err ) && newNewUserIDs != 0 )
						{
							recipientKey->isNewOrChangedKey = TRUE;
						}
					}
				}
				
				if( IsntPGPError( err ) )
				{
					err = PGPKeyIterNextKeyDBObj( iterator, kPGPKeyDBObjType_Key, &theKey );
				}
			}
			
			if( err == kPGPError_EndOfIteration )
				err = kPGPError_NoErr;
				
			PGPFreeKeyIter( iterator );
		}
		
		PGPFreeKeyList( keyList );
	}
	
	return( err );
}

	static PGPError
AddKeySet(
	PGPRecipientsList	*recipients,
	PGPKeySetRef		keySet)
{
	pgpAssert( ! PGPKeySetRefIsValid( recipients->keySet ) );
	
	recipients->keySet = keySet;
	
	return( UpdateNewKeys( recipients, FALSE ) );
}

	static PGPError
AddNewKeys(
	PGPRecipientsList	*recipients,
	PGPKeyDBRef			newKeysDB)
{
	PGPError		err;
	PGPKeySetRef	newKeysSet;
	
	err = PGPNewKeySet( newKeysDB, &newKeysSet );
	if( IsntPGPError( err ) )
	{
		PGPKeySetRef	destKeySet;
		
		err = PGPCopyKeys( newKeysSet, PGPPeekKeySetKeyDB( recipients->keySet ),
					&destKeySet );
		if( IsntPGPError( err ) )
		{
			err = PGPCheckKeyRingSigs( destKeySet, kInvalidPGPKeyDBRef,
					FALSE, NULL, 0 );
			if( IsntPGPError( err ) )
			{
				err = UpdateNewKeys( recipients, TRUE );
				if( IsntPGPError( err ) )
				{
					err = UpdateDynamicRecipientValues( recipients );
				}
			}
			
			PGPFreeKeySet( destKeySet );
		}
		
		PGPFreeKeySet( newKeysSet );
	}
	
	return( err );
}

	static PGPError
AddGroup(
	PGPRecipientsList	*recipients,
	PGPGroupSetRef		groupSet,
	PGPGroupID			groupID)
{
	PGPError			err;
	PGPRecipientUser	*user;
	
	err = NewUser( recipients, &user );
	if( IsntPGPError( err ) )
	{
		user->kind = kPGPRecipientUserKind_Group;
		
		err = PGPNewFlattenedGroupFromGroup( groupSet, groupID,
					recipients->groupSet, &user->groupInfo.groupID );
		if( IsntPGPError( err ) )
		{
			err = PGPCountGroupItems( recipients->groupSet,
						user->groupInfo.groupID, TRUE,
						&user->groupInfo.numKeys, NULL );
			if( IsntPGPError( err ) && user->groupInfo.numKeys > 0 )
			{
				PGPGroupInfo	info;
			
				err	= PGPGetGroupInfo( groupSet, groupID, &info );
				if( IsntPGPError( err ) )
				{
					err = RememberName( recipients, info.name,
								&user->nameOffset );
				}
			}
		}
		
		if( IsntPGPError( err ) )
		{
			if( user->groupInfo.numKeys > 0 )
			{
				user->location = kPGPRecipientUserLocation_UserList;
			}
			else
			{
				user->location = kPGPRecipientUserLocation_Hidden;
			}
			
			user->nextUser 		= recipients->groups;
			recipients->groups 	= user;
		}
	}
							
	return( err );
}

	static PGPError
AddGroupSet(
	PGPContextRef		context,
	PGPRecipientsList	*recipients,
	PGPGroupSetRef		groupSet)
{
	PGPUInt32	numGroups;
	PGPError	err;
	
	err = PGPNewGroupSet( context, &recipients->groupSet );
	if( IsntPGPError( err ) )
	{
		err	= PGPCountGroupsInSet( groupSet, &numGroups );
		if( IsntPGPError( err ) )
		{
			PGPUInt32	index;
			
			for( index = 0; index < numGroups; ++index )
			{
				PGPGroupID	groupID;
				
				err	= PGPGetIndGroupID( groupSet, index, &groupID );
				if ( IsntPGPError( err ) )
				{
					err = AddGroup( recipients, groupSet, groupID );
				}
				
				if ( IsPGPError( err ) )
					break;
			}
		}
	}
	
	return( err );
}

	static PGPRecipientKey *
FindKeyFromKeyRef(
	const PGPRecipientsList		*recipients,
	PGPKeyDBObjRef				searchKeyRef)
{
	PGPRecipientKey	*curKey;

	curKey = recipients->keys;
	while( IsntNull( curKey ) )
	{
		if( PGPCompareKeys( curKey->keyRef, searchKeyRef,
					kPGPKeyOrdering_KeyID ) == 0 )
			break;
		
		curKey = curKey->nextKey;
	}

	return( curKey );
}

/* Must use PGPFreeData to dispose of foundUsers */

	static PGPError
FindUsersFromUserID(
	PGPRecipientsList	*recipients,
	const char			*userID,
	PGPBoolean			matchBestSecretKey,
	PGPUInt32			*numFoundUsers,
	PGPRecipientUser	***foundUsers)
{
	PGPError			err = kPGPError_NoErr;
	PGPRecipientKey		*curKey;
	PGPRecipientKey		*bestSecretKey;
	PGPRecipientUser	*curUser;
	PGPUInt32			markValue;
	
	*numFoundUsers 	= 0;
	*foundUsers		= NULL;
	bestSecretKey	= NULL;
	markValue		= GetNextMarkValue();
	
	/* Tabulate and mark matches first */
	curKey = recipients->keys;
	while( IsntNull( curKey ) )
	{
		PGPRecipientUser	*foundUser = NULL;

		curUser = curKey->users;
		while( IsntNull( curUser ) )
		{
			if( UserIsVisible( curUser ) && 
				IsntNull( FindSubstring( PGPGetRecipientUserNamePtr( curUser ),
								userID ) ) )
			{
				if( curUser->userInfo.isPrimaryUser)
				{
					foundUser = curUser;
					break;
				}
				else if( IsNull( foundUser ) )
				{
					foundUser = curUser;
				}
			}
		
			curUser = curUser->nextUser;
		}
		
		if( IsntNull( foundUser ) )
		{
			if( curKey->isSecretKey && matchBestSecretKey )
			{
				// The best secret key is (1) the default key or
				// (2) a DH/DSA key instead of anything else
				
				if( IsNull( bestSecretKey ) )
				{
					bestSecretKey = curKey;
				}
				else
				{	
					PGPBoolean	switchBestKey = FALSE;
					
					if( curKey->isDefaultKey )
					{
						pgpAssert( ! bestSecretKey->isDefaultKey );
						
						switchBestKey = TRUE;
					}
					else if( curKey->algorithm ==
									kPGPPublicKeyAlgorithm_DSA &&
							 bestSecretKey->algorithm !=
							 		kPGPPublicKeyAlgorithm_DSA )
					{
						switchBestKey = TRUE;
					}
					
					if( switchBestKey )
					{
						bestSecretKey->markValue 	= 0;
						*numFoundUsers 				-= 1;
						
						bestSecretKey = curKey;
					}
					else
					{
						// bestSecretKey is a better match. Skip this one.
						foundUser = NULL;
					}
				}
			}
		}
		
		if( IsntNull( foundUser ) )
		{
			foundUser->markValue	= markValue;
			curKey->markValue 		= markValue;
		
			*numFoundUsers += 1;
		}
		
		curKey = curKey->nextKey;
	}

	curUser = recipients->groups;
	while( IsntNull( curUser ) )
	{
		if( UserIsVisible( curUser ) )
		{
			char	groupUserID[256];
			
			/* Surround the group name with "<>" to simulate an email address */
			
			strcpy( groupUserID, "<" );
			strcat( groupUserID, PGPGetRecipientUserNamePtr( curUser ) );
			strcat( groupUserID, ">" );
			
			if( IsntNull( FindSubstring( groupUserID, userID ) ) )
			{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -