use of org.jcryptool.crypto.flexiprovider.integrator.IntegratorOperation in project core by jcryptool.
the class StartHandler method execute.
public IStatus execute(final ActionView view, final ActionItem startItem, final Shell shell, IProgressMonitor monitor) {
ActionCascade ac = view.getActionCascade();
final TableViewer viewer = view.getViewer();
// $NON-NLS-1$
LogUtil.logInfo("Running Action Cascade " + ac.getName());
boolean start = false;
for (final ActionItem a : ac.getAllItems()) {
int steps = ac.getSize();
// Start the execution at the first selected element
if (a == startItem) {
start = true;
monitor.beginTask(a.getActionName(), steps);
} else
steps--;
if (start) {
if (monitor.isCanceled()) {
return Status.CANCEL_STATUS;
}
try {
boolean executed = false;
// Set focus on moved row. Just look and feel ...
display.asyncExec(new Runnable() {
public void run() {
viewer.setSelection(new StructuredSelection(a), true);
}
});
OperationsPlugin op = OperationsPlugin.getDefault();
CommandInfo[] commands = op.getAlgorithmsManager().getShadowAlgorithmCommands();
// Try to find an CryptoAlgorithm-Plug-in (Classic or Modern)
for (int i = 0, length = commands.length; i < length; i++) {
if (commands[i].getHandler() != null && a.getPluginId().equals(commands[i].getCommandId())) {
((ShadowAlgorithmHandler) commands[i].getHandler()).run(convert(a));
executed = true;
}
}
// Try to find a FlexiProvider algorithm
if (!executed) {
// $NON-NLS-1$
LogUtil.logInfo("Trying to execute FlexiProvider algorithm");
for (RegistryType rt : RegistryType.values()) {
if (rt.getName().equals(a.getPluginId())) {
AlgorithmDescriptor descriptor = new AlgorithmDescriptor(a.getActionName(), rt, null);
if (a.getParam("algorithm type").equals(RegistryType.BLOCK_CIPHER.getName())) {
// $NON-NLS-1$
descriptor = new BlockCipherDescriptor(descriptor.getAlgorithmName(), a.getParam("mode"), a.getParam("padding scheme"), null, // $NON-NLS-1$ //$NON-NLS-2$
null);
} else if (a.getParam("algorithm type").equals(RegistryType.SECURE_RANDOM.getName())) {
// $NON-NLS-1$
// TODO Get property "alphabet" from item
byte[][] alphabet = null;
if (alphabet == null) {
descriptor = new SecureRandomDescriptor(descriptor.getAlgorithmName(), // $NON-NLS-1$
Integer.parseInt(a.getParam("random size")));
}
}
final IFlexiProviderOperation operation = new IntegratorOperation(descriptor);
operation.setInput(Messages.InputType);
operation.setOutput(Messages.StartHandler_6);
// $NON-NLS-1$
operation.setSignature(a.getParam("signature"));
if ("encrypt".equals(a.getActionType())) {
// $NON-NLS-1$
operation.setOperation(OperationType.ENCRYPT);
} else if ("decrypt".equals(a.getActionType())) {
// $NON-NLS-1$
operation.setOperation(OperationType.DECRYPT);
} else if ("sign".equals(a.getActionType())) {
// $NON-NLS-1$
operation.setOperation(OperationType.SIGN);
} else if ("verify".equals(a.getActionType())) {
// $NON-NLS-1$
operation.setOperation(OperationType.VERIFY);
} else {
operation.setOperation(OperationType.UNKNOWN);
}
// $NON-NLS-1$
String alias = a.getParam("key alias");
if (alias != null) {
operation.setKeyStoreAlias(new KeyStoreAlias(alias));
}
// $NON-NLS-1$
String password = a.getParam("key password");
if (password != null) {
operation.setPassword(password.toCharArray());
}
display.asyncExec(new Runnable() {
public void run() {
PerformOperationManager.getInstance().firePerformOperation(operation);
}
});
executed = true;
}
}
}
if (!executed) {
throw new Exception(Messages.StartHandler_2 + a.getPluginId());
}
} catch (final Exception e) {
if (ActionsUIPlugin.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.P_IGNORE_ERRORS)) {
// $NON-NLS-1$
LogUtil.logError(ActionsUIPlugin.PLUGIN_ID, a.getActionName() + ": " + e.getMessage(), e, false);
if (!ActionsUIPlugin.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.P_DONT_SHOW_MESSAGES)) {
display.syncExec(new Runnable() {
public void run() {
MessageDialog.openWarning(shell, Messages.StartHandler_3, e.getMessage());
}
});
}
} else {
display.asyncExec(new Runnable() {
public void run() {
MessageDialog.openError(shell, Messages.StartHandler_3, e.getMessage() + // $NON-NLS-1$
Messages.StartHandler_4);
}
});
return Status.CANCEL_STATUS;
}
} finally {
monitor.worked(ac.getSize() - steps);
}
}
}
monitor.done();
return Status.OK_STATUS;
}
Aggregations