📄 pkmenu.c
字号:
case IDX_RSATOKDISKEY :
case IDX_RSAV4TOKKEY :
case IDX_RSAV4TOKDISKEY :
case IDX_ECSECKEY :
case IDX_ECSECDISKEY :
case IDX_ECSECSHRKEY :
PGPGetKeyDBObjBooleanProperty (obj,
kPGPKeyProperty_CanSign, &b);
if (b) return TRUE;
else return FALSE;
default :
return FALSE;
}
}
// set as primary
static BOOL
sIsSetAsPrimaryEnabled (PPGPKEYSSTRUCT ppks)
{
PGPUInt32 uSel, uFocus;
PGPKeyDBObjRef obj;
PGPBoolean bMul;
PGPclKeyListGetSelectionInfo (ppks->hKL, &uFocus, &obj, &bMul, &uSel);
if (ppks->bReadOnly) return FALSE;
if (sPromiscuousSelected (uSel)) return FALSE;
if (bMul) return FALSE;
switch (uFocus) {
case IDX_RSAUSERID :
case IDX_DSAUSERID :
return (!PKIsThisThePrimaryUserID (obj));
default :
return FALSE;
}
}
// import
static BOOL
sIsImportEnabled (PPGPKEYSSTRUCT ppks)
{
if (ppks->bReadOnly) return FALSE;
return TRUE;
}
// export
static BOOL
sIsExportEnabled (PPGPKEYSSTRUCT ppks)
{
PGPUInt32 uSel, uFocus;
PGPBoolean bMul;
PGPclKeyListGetSelectionInfo (ppks->hKL, &uFocus, NULL, &bMul, &uSel);
if (sPromiscuousSelected (uSel)) return FALSE;
if (uSel == kPGPclKeyList_Key) return TRUE;
if (uSel == kPGPclKeyList_Signature)
{
if (bMul) return FALSE;
if (uFocus == IDX_X509CERT) return TRUE;
if (uFocus == IDX_X509EXPCERT) return TRUE;
if (uFocus == IDX_X509REVCERT) return TRUE;
}
return FALSE;
}
// properties
static BOOL
sIsPropertiesEnabled (PPGPKEYSSTRUCT ppks)
{
PGPUInt32 uSel;
PGPclKeyListGetSelectionInfo (ppks->hKL, NULL, NULL, NULL, &uSel);
if (uSel == kPGPclKeyList_None) return FALSE;
return TRUE;
}
// send to keyserver
static BOOL
sIsSendToServerEnabled (PPGPKEYSSTRUCT ppks)
{
PGPUInt32 uSel;
PGPclKeyListGetSelectionInfo (ppks->hKL, NULL, NULL, NULL, &uSel);
if (sPromiscuousSelected (uSel)) return FALSE;
if (uSel != kPGPclKeyList_Key) return FALSE;
return TRUE;
}
// get from keyserver
static BOOL
sIsGetFromServerEnabled (PPGPKEYSSTRUCT ppks)
{
PGPUInt32 uSel, uFocus;
PGPclKeyListGetSelectionInfo (ppks->hKL, &uFocus, NULL, NULL, &uSel);
if (sPromiscuousSelected (uSel)) return FALSE;
if (uSel == kPGPclKeyList_None) return FALSE;
if (uSel == kPGPclKeyList_UserID) return FALSE;
switch (uFocus) {
case IDX_X509CERT :
case IDX_X509EXPCERT :
case IDX_X509REVCERT :
return FALSE;
default :
return TRUE;
}
}
// retrieve X509 certificate
static BOOL
sIsRetrieveCertificateEnabled (PPGPKEYSSTRUCT ppks)
{
PGPUInt32 uSel, uFocus;
PGPBoolean bMul;
PGPclKeyListGetSelectionInfo (ppks->hKL, &uFocus, NULL, &bMul, &uSel);
if (ppks->bReadOnly) return FALSE;
if (sPromiscuousSelected (uSel)) return FALSE;
if (bMul) return FALSE;
switch (uFocus) {
case IDX_RSASECKEY :
case IDX_RSASECDISKEY :
case IDX_RSASECSHRKEY :
case IDX_DSASECKEY :
case IDX_DSASECDISKEY :
case IDX_DSASECSHRKEY :
case IDX_RSAV4SECKEY :
case IDX_RSAV4SECDISKEY :
case IDX_RSAV4SECSHRKEY :
case IDX_RSATOKKEY :
case IDX_RSATOKDISKEY :
case IDX_RSAV4TOKKEY :
case IDX_RSAV4TOKDISKEY :
case IDX_ECSECKEY :
case IDX_ECSECDISKEY :
case IDX_ECSECSHRKEY :
return TRUE;
default :
return FALSE;
}
}
// unselect all
static BOOL
sIsUnselectAllEnabled (PPGPKEYSSTRUCT ppks)
{
return TRUE;
}
// add to main
static BOOL
sIsAddToMainEnabled (PPGPKEYSSTRUCT ppks)
{
PGPUInt32 uSel;
PGPclKeyListGetSelectionInfo (ppks->hKL, NULL, NULL, NULL, &uSel);
if (sPromiscuousSelected (uSel)) return FALSE;
if (uSel != kPGPclKeyList_Key) return FALSE;
return TRUE;
}
// reverify signatures
static BOOL
sIsReverifySigsEnabled (PPGPKEYSSTRUCT ppks)
{
PGPUInt32 uSel;
PGPclKeyListGetSelectionInfo (ppks->hKL, NULL, NULL, NULL, &uSel);
if (sPromiscuousSelected (uSel)) return FALSE;
if (uSel != kPGPclKeyList_Key) return FALSE;
return TRUE;
}
// split key for sharing
static BOOL
sIsSplitKeyEnabled (PPGPKEYSSTRUCT ppks)
{
PGPUInt32 uSel, uFocus;
PGPKeyDBObjRef obj;
PGPBoolean b, bMul;
PGPclKeyListGetSelectionInfo (ppks->hKL, &uFocus, &obj, &bMul, &uSel);
if (ppks->bReadOnly) return FALSE;
if (bMul) return FALSE;
switch (uFocus) {
case IDX_RSASECKEY :
case IDX_RSASECDISKEY :
case IDX_DSASECKEY :
case IDX_DSASECDISKEY :
case IDX_RSAV4SECKEY :
case IDX_RSAV4SECDISKEY :
case IDX_ECSECKEY :
case IDX_ECSECDISKEY :
PGPGetKeyDBObjBooleanProperty (obj,
kPGPKeyProperty_CanSign, &b);
if (!b) return FALSE;
PGPGetKeyDBObjBooleanProperty (obj,
kPGPKeyProperty_CanEncrypt, &b);
if (!b) return FALSE;
return TRUE;
default :
return FALSE;
}
}
// reconstruct key
static BOOL
sIsReconstructKeyEnabled (PPGPKEYSSTRUCT ppks)
{
PGPUInt32 uSel, uFocus;
PGPBoolean bMul;
PGPclKeyListGetSelectionInfo (ppks->hKL, &uFocus, NULL, &bMul, &uSel);
if (!g_bKeyReconstructionEnabled) return FALSE;
if (ppks->bReadOnly) return FALSE;
if (bMul) return FALSE;
if (uSel != kPGPclKeyList_Key) return FALSE;
return TRUE;
}
// send to reconstruction server
static BOOL
sIsSendToReconServerEnabled (PPGPKEYSSTRUCT ppks)
{
PGPUInt32 uFocus;
PGPBoolean bMul;
PGPclKeyListGetSelectionInfo (ppks->hKL, &uFocus, NULL, &bMul, NULL);
if (bMul) return FALSE;
switch (uFocus) {
case IDX_RSASECKEY :
case IDX_RSASECDISKEY :
case IDX_DSASECKEY :
case IDX_DSASECDISKEY :
case IDX_RSAV4SECKEY :
case IDX_RSAV4SECDISKEY :
case IDX_RSATOKKEY :
case IDX_RSATOKDISKEY :
case IDX_RSAV4TOKKEY :
case IDX_RSAV4TOKDISKEY :
case IDX_ECSECKEY :
case IDX_ECSECDISKEY :
return TRUE;
default :
return FALSE;
}
}
// send to token
static BOOL
sIsSendToTokenEnabled (PPGPKEYSSTRUCT ppks)
{
PGPUInt32 uFocus;
PGPBoolean bMul;
if (g_uNumTokens == 0) return FALSE;
PGPclKeyListGetSelectionInfo (ppks->hKL, &uFocus, NULL, &bMul, NULL);
if (bMul) return FALSE;
switch (uFocus) {
case IDX_RSASECKEY :
case IDX_RSASECDISKEY :
case IDX_RSAV4SECKEY :
case IDX_RSAV4SECDISKEY :
return TRUE;
default :
return FALSE;
}
}
// send via email
static BOOL
sIsSendViaEmailEnabled (PPGPKEYSSTRUCT ppks)
{
PGPUInt32 uSel;
PGPclKeyListGetSelectionInfo (ppks->hKL, NULL, NULL, NULL, &uSel);
if (sPromiscuousSelected (uSel)) return FALSE;
if (uSel != kPGPclKeyList_Key) return FALSE;
return TRUE;
}
// ___________________________________________________
//
// determine if action is enabled or not, based on
// flags passed in and current selection
BOOL
PKIsActionEnabled (
PGPKEYSSTRUCT* ppks,
ULONG ulAction)
{
if (!ppks) return FALSE;
switch (ulAction) {
case KM_COPY : return sIsCopyEnabled (ppks);
case KM_PASTE : return sIsPasteEnabled (ppks);
case KM_DELETEFROMSERVER : return sIsDeleteFromServerEnabled (ppks);
case KM_DELETE : return PKIsDeleteEnabled (ppks);
case KM_SELECTALL : return sIsSelectAllEnabled (ppks);
case KM_COLLAPSEALL : return sIsCollapseAllEnabled (ppks);
case KM_COLLAPSESEL : return sIsCollapseSelEnabled (ppks);
case KM_EXPANDALL : return sIsExpandAllEnabled (ppks);
case KM_EXPANDSEL : return sIsExpandSelEnabled (ppks);
case KM_CERTIFY : return sIsCertifyEnabled (ppks);
case KM_ENABLE : return sIsEnableEnabled (ppks);
case KM_DISABLEONSERVER : return sIsDisableOnServerEnabled (ppks);
case KM_DISABLE : return sIsDisableEnabled (ppks);
case KM_ADDUSERID : return sIsAddUserEnabled (ppks);
case KM_ADDPHOTOID : return sIsAddPhotoEnabled (ppks);
case KM_ADDREVOKER : return sIsAddRevokerEnabled (ppks);
case KM_ADDCERTIFICATE : return sIsAddCertificateEnabled (ppks);
case KM_REVOKE : return sIsRevokeEnabled (ppks);
case KM_SETASDEFAULT : return sIsSetAsDefaultEnabled (ppks);
case KM_SETASPRIMARY : return sIsSetAsPrimaryEnabled (ppks);
case KM_IMPORT : return sIsImportEnabled (ppks);
case KM_EXPORT : return sIsExportEnabled (ppks);
case KM_PROPERTIES : return sIsPropertiesEnabled (ppks);
case KM_SENDTOSERVER : return sIsSendToServerEnabled (ppks);
case KM_GETFROMSERVER : return sIsGetFromServerEnabled (ppks);
case KM_RETRIEVECERTIFICATE:return sIsRetrieveCertificateEnabled (ppks);
case KM_UNSELECTALL: return sIsUnselectAllEnabled (ppks);
case KM_ADDTOMAIN : return sIsAddToMainEnabled (ppks);
case KM_REVERIFYSIGS : return sIsReverifySigsEnabled (ppks);
case KM_SPLITKEY : return sIsSplitKeyEnabled (ppks);
case KM_RECONSTRUCTKEY : return sIsReconstructKeyEnabled (ppks);
case KM_SENDTORECONSERVER: return sIsSendToReconServerEnabled (ppks);
case KM_SENDTOTOKEN: return sIsSendToTokenEnabled (ppks);
case KM_SENDVIAEMAIL: return sIsSendViaEmailEnabled (ppks);
default : return FALSE;
}
}
// _______________________________________________
//
// Enable/Disable menu items on basis of currently
// focused key type
VOID
PKSetMainMenu (PGPKEYSSTRUCT* ppks)
{
HMENU hMP;
HKEYLIST hKL;
HGROUPMAN hGM;
ULONG ulColumns;
CHAR sz[64];
hKL = ppks->hKL;
hGM = ppks->hGM;
// "Edit" menu
hMP = GetSubMenu (ppks->hmenuKeyMan, MENU_EDIT);
sSetItem (hMP, IDM_COPYKEY, PKIsActionEnabled (ppks, KM_COPY));
if (ppks->bGroupsFocused)
{
sSetItem (hMP, IDM_PASTEKEY, PGPgmIsActionEnabled (hGM, GM_PASTE));
sSetItem (hMP, IDM_DELETEKEY, PGPgmIsActionEnabled (hGM, GM_DELETE));
sSetMenuAllOrSelected (hMP,
!PGPgmIsActionEnabled (hGM, GM_EXPANDSEL));
}
else
{
sSetItem (hMP, IDM_PASTEKEY, PKIsActionEnabled (ppks, KM_PASTE));
sSetItem (hMP, IDM_DELETEKEY, PKIsActionEnabled (ppks, KM_DELETE));
sSetMenuAllOrSelected (hMP,
!PKIsActionEnabled (ppks, KM_EXPANDSEL));
}
// "View" menu
hMP = GetSubMenu (ppks->hmenuKeyMan, MENU_VIEW);
PGPclKeyListGetSelectedColumns (hKL, &ulColumns);
if (ulColumns & kPGPclKeyList_ValidityColumn)
CheckMenuItem (hMP, IDM_VIEWVALIDITY, MF_BYCOMMAND|MF_CHECKED);
else
CheckMenuItem (hMP, IDM_VIEWVALIDITY, MF_BYCOMMAND|MF_UNCHECKED);
if (ulColumns & kPGPclKeyList_SizeColumn)
CheckMenuItem (hMP, IDM_VIEWSIZE, MF_BYCOMMAND|MF_CHECKED);
else
CheckMenuItem (hMP, IDM_VIEWSIZE, MF_BYCOMMAND|MF_UNCHECKED);
if (ulColumns & kPGPclKeyList_DescriptionColumn)
CheckMenuItem (hMP, IDM_VIEWDESC, MF_BYCOMMAND|MF_CHECKED);
else
CheckMenuItem (hMP, IDM_VIEWDESC, MF_BYCOMMAND|MF_UNCHECKED);
if (ulColumns & kPGPclKeyList_KeyIDColumn)
CheckMenuItem (hMP, IDM_VIEWKEYID, MF_BYCOMMAND|MF_CHECKED);
else
CheckMenuItem (hMP, IDM_VIEWKEYID, MF_BYCOMMAND|MF_UNCHECKED);
if (ulColumns & kPGPclKeyList_TrustColumn)
CheckMenuItem (hMP, IDM_VIEWTRUST, MF_BYCOMMAND|MF_CHECKED);
else
CheckMenuItem (hMP, IDM_VIEWTRUST, MF_BYCOMMAND|MF_UNCHECKED);
if (ulColumns & kPGPclKeyList_CreationColumn)
CheckMenuItem (hMP, IDM_VIEWCREATION, MF_BYCOMMAND|MF_CHECKED);
else
CheckMenuItem (hMP, IDM_VIEWCREATION, MF_BYCOMMAND|MF_UNCHECKED);
if (ulColumns & kPGPclKeyList_ExpirationColumn)
CheckMenuItem (hMP, IDM_VIEWEXPIRATION, MF_BYCOMMAND|MF_CHECKED);
else
CheckMenuItem (hMP, IDM_VIEWEXPIRATION, MF_BYCOMMAND|MF_UNCHECKED);
if (ulColumns & kPGPclKeyList_ADKColumn)
CheckMenuItem (hMP, IDM_VIEWADK, MF_BYCOMMAND|MF_CHECKED);
else
CheckMenuItem (hMP, IDM_VIEWADK, MF_BYCOMMAND|MF_UNCHECKED);
if (ppks->iToolHeight > 0)
CheckMenuItem (hMP, IDM_VIEWTOOLBAR, MF_BYCOMMAND|MF_CHECKED);
else
CheckMenuItem (hMP, IDM_VIEWTOOLBAR, MF_BYCOMMAND|MF_UNCHECKED);
sSetItem (hMP, IDM_VIEWTOKENPROPERTIES, (g_uNumTokens > 0));
// "Keys" menu
hMP = GetSubMenu (ppks->hmenuKeyMan, MENU_KEYS);
sSetItem (hMP, IDM_CERTIFYKEY, PKIsActionEnabled (ppks, KM_CERTIFY));
sSetItem (hMP, IDM_ENABLEKEY, PKIsActionEnabled (ppks, KM_ENABLE));
sSetItem (hMP, IDM_DISABLEKEY, PKIsActionEnabled (ppks, KM_DISABLE));
sSetItem (hMP, IDM_REVOKEKEY, PKIsActionEnabled (ppks, KM_REVOKE));
sSetItem (hMP, IDM_REVERIFY,
PKIsActionEnabled (ppks, KM_REVERIFYSIGS));
if (PKIsActionEnabled (ppks, KM_SETASPRIMARY))
{
sSetMenuDefaultOrPrimary (hMP, FALSE);
EnableMenuItem (hMP, IDM_SETASDEFAULT, MF_BYCOMMAND|MF_ENABLED);
}
else
{
sSetMenuDefaultOrPrimary (hMP, TRUE);
sSetItem (hMP, IDM_SETASDEFAULT,
PKIsActionEnabled (ppks, KM_SETASDEFAULT));
}
sSetItem (hMP, IDM_CREATEKEY, (!ppks->bReadOnly) && g_bKeyGenEnabled);
sSetItem (hMP, IDM_SPLITKEY, PKIsActionEnabled (ppks, KM_SPLITKEY));
sSetItem (hMP, IDM_RECONSTRUCTKEY,
PKIsActionEnabled (ppks, KM_RECONSTRUCTKEY));
sSetItem (hMP, IDM_IMPORTKEYS, PKIsActionEnabled (ppks, KM_IMPORT));
sSetItem (hMP, IDM_EXPORTKEYS, PKIsActionEnabled (ppks, KM_EXPORT));
sSetItem (hMP, IDM_PROPERTIES,
PKIsActionEnabled (ppks, KM_PROPERTIES));
// "Add" popup submenu
hMP = GetSubMenu (hMP, SUBMENU_ADD);
sSetItem (hMP, IDM_ADDUSERID,
PKIsActionEnabled (ppks, KM_ADDUSERID));
sSetItem (hMP, IDM_ADDPHOTOID,
PKIsActionEnabled (ppks, KM_ADDPHOTOID));
sSetItem (hMP, IDM_ADDREVOKER,
PKIsActionEnabled (ppks, KM_ADDREVOKER));
sSetItem (hMP, IDM_ADDCERTIFICATE,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -