mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-23 17:22:16 -05:00
default message/file compression settings added, also a setting for file decryption to change the default when a file requires it
This commit is contained in:
parent
c7f0041751
commit
eb636fce47
@ -108,6 +108,29 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/label_fileCompression"
|
||||
android:text="@string/label_fileCompression"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="0dip"
|
||||
android:layout_weight="1"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:paddingRight="10dip"/>
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/fileCompression"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
@ -46,8 +46,8 @@
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/label_passPhraseCache"
|
||||
android:text="@string/label_passPhraseCache"
|
||||
android:id="@+id/label_passPhraseCacheTtl"
|
||||
android:text="@string/label_passPhraseCacheTtl"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="0dip"
|
||||
@ -56,7 +56,7 @@
|
||||
android:paddingRight="10dip"/>
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/passPhraseCache"
|
||||
android:id="@+id/passPhraseCacheTtl"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"/>
|
||||
@ -123,6 +123,52 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/label_messageCompression"
|
||||
android:text="@string/label_messageCompression"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="0dip"
|
||||
android:layout_weight="1"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:paddingRight="10dip"/>
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/messageCompression"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/label_fileCompression"
|
||||
android:text="@string/label_fileCompression"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="0dip"
|
||||
android:layout_weight="1"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:paddingRight="10dip"/>
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/fileCompression"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
@ -93,7 +93,9 @@
|
||||
<string name="label_hashAlgorithm">Hash Algorithm</string>
|
||||
<string name="label_asymmetric">Public Key</string>
|
||||
<string name="label_symmetric">Pass Phrase</string>
|
||||
<string name="label_passPhraseCache">Pass Phrase Cache</string>
|
||||
<string name="label_passPhraseCacheTtl">Pass Phrase Cache</string>
|
||||
<string name="label_messageCompression">Message Compression</string>
|
||||
<string name="label_fileCompression">File Compression</string>
|
||||
|
||||
<string name="noKeysSelected">Select</string>
|
||||
<string name="oneKeySelected">1 Selected</string>
|
||||
@ -110,6 +112,7 @@
|
||||
<string name="notValid">not valid</string>
|
||||
|
||||
<!-- choice_lowerCase: capitalized firwst word, no punctuation -->
|
||||
<string name="choice_none">None</string>
|
||||
<string name="choice_signOnly">Sign only</string>
|
||||
<string name="choice_encryptOnly">Encrypt only</string>
|
||||
<string name="choice_signAndEncrypt">Sign and Encrypt</string>
|
||||
|
@ -1248,7 +1248,7 @@ public class Apg {
|
||||
long encryptionKeyIds[], long signatureKeyId,
|
||||
String signaturePassPhrase,
|
||||
ProgressDialogUpdater progress,
|
||||
int symmetricAlgorithm, int hashAlgorithm,
|
||||
int symmetricAlgorithm, int hashAlgorithm, int compression,
|
||||
String passPhrase)
|
||||
throws IOException, GeneralException, PGPException, NoSuchProviderException,
|
||||
NoSuchAlgorithmException, SignatureException {
|
||||
@ -1324,9 +1324,14 @@ public class Apg {
|
||||
signatureGenerator.setHashedSubpackets(spGen.generate());
|
||||
}
|
||||
|
||||
PGPCompressedDataGenerator compressGen =
|
||||
new PGPCompressedDataGenerator(PGPCompressedDataGenerator.ZLIB);
|
||||
BCPGOutputStream bcpgOut = new BCPGOutputStream(compressGen.open(encryptOut));
|
||||
PGPCompressedDataGenerator compressGen = null;
|
||||
BCPGOutputStream bcpgOut = null;
|
||||
if (compression == Id.choice.compression.none) {
|
||||
bcpgOut = new BCPGOutputStream(encryptOut);
|
||||
} else {
|
||||
compressGen = new PGPCompressedDataGenerator(CompressionAlgorithmTags.ZLIB);
|
||||
bcpgOut = new BCPGOutputStream(compressGen.open(encryptOut));
|
||||
}
|
||||
if (signatureKeyId != 0) {
|
||||
signatureGenerator.generateOnePassVersion(false).encode(bcpgOut);
|
||||
}
|
||||
@ -1357,7 +1362,9 @@ public class Apg {
|
||||
progress.setProgress(R.string.progress_generatingSignature, 95, 100);
|
||||
signatureGenerator.generate().encode(pOut);
|
||||
}
|
||||
compressGen.close();
|
||||
if (compressGen != null) {
|
||||
compressGen.close();
|
||||
}
|
||||
encryptOut.close();
|
||||
if (armored) {
|
||||
armorOut.close();
|
||||
|
@ -20,6 +20,7 @@ import java.io.File;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
import org.bouncycastle2.bcpg.CompressionAlgorithmTags;
|
||||
import org.bouncycastle2.bcpg.HashAlgorithmTags;
|
||||
import org.bouncycastle2.openpgp.PGPEncryptedData;
|
||||
|
||||
@ -414,6 +415,28 @@ public class BaseActivity extends Activity
|
||||
editor.commit();
|
||||
}
|
||||
|
||||
public int getDefaultMessageCompression() {
|
||||
return mPreferences.getInt(Constants.pref.default_message_compression,
|
||||
CompressionAlgorithmTags.ZLIB);
|
||||
}
|
||||
|
||||
public void setDefaultMessageCompression(int value) {
|
||||
SharedPreferences.Editor editor = mPreferences.edit();
|
||||
editor.putInt(Constants.pref.default_message_compression, value);
|
||||
editor.commit();
|
||||
}
|
||||
|
||||
public int getDefaultFileCompression() {
|
||||
return mPreferences.getInt(Constants.pref.default_file_compression,
|
||||
CompressionAlgorithmTags.ZLIB);
|
||||
}
|
||||
|
||||
public void setDefaultFileCompression(int value) {
|
||||
SharedPreferences.Editor editor = mPreferences.edit();
|
||||
editor.putInt(Constants.pref.default_file_compression, value);
|
||||
editor.commit();
|
||||
}
|
||||
|
||||
public boolean getDefaultAsciiArmour() {
|
||||
return mPreferences.getBoolean(Constants.pref.default_ascii_armour, false);
|
||||
}
|
||||
|
@ -28,6 +28,8 @@ public final class Constants {
|
||||
public static final String default_encryption_algorithm = "defaultEncryptionAlgorithm";
|
||||
public static final String default_hash_algorithm = "defaultHashAlgorithm";
|
||||
public static final String default_ascii_armour = "defaultAsciiArmour";
|
||||
public static final String default_message_compression = "defaultMessageCompression";
|
||||
public static final String default_file_compression = "defaultFileCompression";
|
||||
public static final String pass_phrase_cache_ttl = "passPhraseCacheTtl";
|
||||
}
|
||||
}
|
||||
|
@ -37,6 +37,7 @@ import org.bouncycastle2.openpgp.PGPSecretKeyRing;
|
||||
import org.bouncycastle2.util.Strings;
|
||||
import org.openintents.intents.FileManager;
|
||||
import org.thialfihar.android.apg.Apg.GeneralException;
|
||||
import org.thialfihar.android.apg.utils.Choice;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.ActivityNotFoundException;
|
||||
@ -49,11 +50,13 @@ import android.text.ClipboardManager;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.animation.AnimationUtils;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import android.widget.ViewFlipper;
|
||||
@ -87,6 +90,7 @@ public class EncryptActivity extends BaseActivity {
|
||||
private EditText mPassPhrase = null;
|
||||
private EditText mPassPhraseAgain = null;
|
||||
private CheckBox mAsciiArmour = null;
|
||||
private Spinner mFileCompression = null;
|
||||
|
||||
private EditText mFilename = null;
|
||||
private CheckBox mDeleteAfter = null;
|
||||
@ -196,6 +200,26 @@ public class EncryptActivity extends BaseActivity {
|
||||
}
|
||||
});
|
||||
|
||||
mFileCompression = (Spinner) findViewById(R.id.fileCompression);
|
||||
Choice[] choices = new Choice[] {
|
||||
new Choice(Id.choice.compression.none, getString(R.string.choice_none)),
|
||||
new Choice(Id.choice.compression.zip, "ZIP"),
|
||||
new Choice(Id.choice.compression.bzip2, "BZIP2"),
|
||||
new Choice(Id.choice.compression.zlib, "ZLIB"),
|
||||
};
|
||||
ArrayAdapter<Choice> adapter =
|
||||
new ArrayAdapter<Choice>(this, android.R.layout.simple_spinner_item, choices);
|
||||
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
mFileCompression.setAdapter(adapter);
|
||||
|
||||
int defaultFileCompression = getDefaultFileCompression();
|
||||
for (int i = 0; i < choices.length; ++i) {
|
||||
if (choices[i].getId() == defaultFileCompression) {
|
||||
mFileCompression.setSelection(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
mDeleteAfter = (CheckBox) findViewById(R.id.deleteAfterEncryption);
|
||||
|
||||
mAsciiArmour = (CheckBox) findViewById(R.id.asciiArmour);
|
||||
@ -492,6 +516,7 @@ public class EncryptActivity extends BaseActivity {
|
||||
long encryptionKeyIds[] = null;
|
||||
long signatureKeyId = 0;
|
||||
boolean signOnly = false;
|
||||
int compressionId = 0;
|
||||
|
||||
String passPhrase = null;
|
||||
if (mMode.getCurrentView().getId() == R.id.modeSymmetric) {
|
||||
@ -519,6 +544,7 @@ public class EncryptActivity extends BaseActivity {
|
||||
File file = new File(mInputFilename);
|
||||
size = file.length();
|
||||
useAsciiArmour = mAsciiArmour.isChecked();
|
||||
compressionId = ((Choice) mFileCompression.getSelectedItem()).getId();
|
||||
} else {
|
||||
String message = mMessage.getText().toString();
|
||||
|
||||
@ -539,6 +565,7 @@ public class EncryptActivity extends BaseActivity {
|
||||
|
||||
size = byteData.length;
|
||||
useAsciiArmour = true;
|
||||
compressionId = getDefaultMessageCompression();
|
||||
}
|
||||
|
||||
if (signOnly) {
|
||||
@ -550,7 +577,7 @@ public class EncryptActivity extends BaseActivity {
|
||||
encryptionKeyIds, signatureKeyId,
|
||||
Apg.getCachedPassPhrase(signatureKeyId), this,
|
||||
getDefaultEncryptionAlgorithm(), getDefaultHashAlgorithm(),
|
||||
passPhrase);
|
||||
compressionId, passPhrase);
|
||||
}
|
||||
|
||||
out.close();
|
||||
|
@ -16,6 +16,8 @@
|
||||
|
||||
package org.thialfihar.android.apg;
|
||||
|
||||
import org.bouncycastle2.bcpg.CompressionAlgorithmTags;
|
||||
|
||||
public final class Id {
|
||||
public static final class menu {
|
||||
public static final int export = 0x21070001;
|
||||
@ -92,6 +94,13 @@ public final class Id {
|
||||
public static final int rsa = 0x21070003;
|
||||
}
|
||||
|
||||
public static final class compression {
|
||||
public static final int none = 0x21070001;
|
||||
public static final int zlib = CompressionAlgorithmTags.ZLIB;
|
||||
public static final int bzip2 = CompressionAlgorithmTags.BZIP2;
|
||||
public static final int zip = CompressionAlgorithmTags.ZIP;
|
||||
}
|
||||
|
||||
public static final class usage {
|
||||
public static final int sign_only = 0x21070001;
|
||||
public static final int encrypt_only = 0x21070002;
|
||||
|
@ -30,9 +30,11 @@ import android.widget.Spinner;
|
||||
import android.widget.AdapterView.OnItemSelectedListener;
|
||||
|
||||
public class PreferencesActivity extends BaseActivity {
|
||||
private Spinner mPassPhraseCache = null;
|
||||
private Spinner mPassPhraseCacheTtl = null;
|
||||
private Spinner mEncryptionAlgorithm = null;
|
||||
private Spinner mHashAlgorithm = null;
|
||||
private Spinner mMessageCompression = null;
|
||||
private Spinner mFileCompression = null;
|
||||
private CheckBox mAsciiArmour = null;
|
||||
|
||||
@Override
|
||||
@ -40,7 +42,7 @@ public class PreferencesActivity extends BaseActivity {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.preferences);
|
||||
|
||||
mPassPhraseCache = (Spinner) findViewById(R.id.passPhraseCache);
|
||||
mPassPhraseCacheTtl = (Spinner) findViewById(R.id.passPhraseCacheTtl);
|
||||
|
||||
Choice choices[] = {
|
||||
new Choice(15, getString(R.string.choice_15secs)),
|
||||
@ -53,20 +55,20 @@ public class PreferencesActivity extends BaseActivity {
|
||||
ArrayAdapter<Choice> adapter =
|
||||
new ArrayAdapter<Choice>(this, android.R.layout.simple_spinner_item, choices);
|
||||
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
mPassPhraseCache.setAdapter(adapter);
|
||||
mPassPhraseCacheTtl.setAdapter(adapter);
|
||||
|
||||
int passPhraseCache = getPassPhraseCacheTtl();
|
||||
for (int i = 0; i < choices.length; ++i) {
|
||||
if (choices[i].getId() == passPhraseCache) {
|
||||
mPassPhraseCache.setSelection(i);
|
||||
mPassPhraseCacheTtl.setSelection(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
mPassPhraseCache.setOnItemSelectedListener(new OnItemSelectedListener() {
|
||||
mPassPhraseCacheTtl.setOnItemSelectedListener(new OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> adapter, View view, int index, long id) {
|
||||
setPassPhraseCacheTtl(((Choice) mPassPhraseCache.getSelectedItem()).getId());
|
||||
setPassPhraseCacheTtl(((Choice) mPassPhraseCacheTtl.getSelectedItem()).getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -76,11 +78,6 @@ public class PreferencesActivity extends BaseActivity {
|
||||
});
|
||||
|
||||
mEncryptionAlgorithm = (Spinner) findViewById(R.id.encryptionAlgorithm);
|
||||
mHashAlgorithm = (Spinner) findViewById(R.id.hashAlgorithm);
|
||||
mAsciiArmour = (CheckBox) findViewById(R.id.asciiArmour);
|
||||
|
||||
mAsciiArmour.setChecked(getDefaultAsciiArmour());
|
||||
|
||||
choices = new Choice[] {
|
||||
new Choice(PGPEncryptedData.AES_128, "AES 128"),
|
||||
new Choice(PGPEncryptedData.AES_192, "AES 192"),
|
||||
@ -116,6 +113,7 @@ public class PreferencesActivity extends BaseActivity {
|
||||
}
|
||||
});
|
||||
|
||||
mHashAlgorithm = (Spinner) findViewById(R.id.hashAlgorithm);
|
||||
choices = new Choice[] {
|
||||
new Choice(HashAlgorithmTags.MD5, "MD5"),
|
||||
new Choice(HashAlgorithmTags.RIPEMD160, "RIPEMD160"),
|
||||
@ -149,6 +147,70 @@ public class PreferencesActivity extends BaseActivity {
|
||||
}
|
||||
});
|
||||
|
||||
mMessageCompression = (Spinner) findViewById(R.id.messageCompression);
|
||||
choices = new Choice[] {
|
||||
new Choice(Id.choice.compression.none, getString(R.string.choice_none)),
|
||||
new Choice(Id.choice.compression.zip, "ZIP"),
|
||||
new Choice(Id.choice.compression.bzip2, "BZIP2"),
|
||||
new Choice(Id.choice.compression.zlib, "ZLIB"),
|
||||
};
|
||||
adapter = new ArrayAdapter<Choice>(this, android.R.layout.simple_spinner_item, choices);
|
||||
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
mMessageCompression.setAdapter(adapter);
|
||||
|
||||
int defaultMessageCompression = getDefaultMessageCompression();
|
||||
for (int i = 0; i < choices.length; ++i) {
|
||||
if (choices[i].getId() == defaultMessageCompression) {
|
||||
mMessageCompression.setSelection(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
mMessageCompression.setOnItemSelectedListener(new OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> adapter, View view, int index, long id) {
|
||||
setDefaultMessageCompression(((Choice) mMessageCompression.getSelectedItem()).getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> adapter) {
|
||||
// nothing to do
|
||||
}
|
||||
});
|
||||
|
||||
mFileCompression = (Spinner) findViewById(R.id.fileCompression);
|
||||
choices = new Choice[] {
|
||||
new Choice(Id.choice.compression.none, getString(R.string.choice_none)),
|
||||
new Choice(Id.choice.compression.zip, "ZIP"),
|
||||
new Choice(Id.choice.compression.bzip2, "BZIP2"),
|
||||
new Choice(Id.choice.compression.zlib, "ZLIB"),
|
||||
};
|
||||
adapter = new ArrayAdapter<Choice>(this, android.R.layout.simple_spinner_item, choices);
|
||||
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
mFileCompression.setAdapter(adapter);
|
||||
|
||||
int defaultFileCompression = getDefaultFileCompression();
|
||||
for (int i = 0; i < choices.length; ++i) {
|
||||
if (choices[i].getId() == defaultFileCompression) {
|
||||
mFileCompression.setSelection(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
mFileCompression.setOnItemSelectedListener(new OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> adapter, View view, int index, long id) {
|
||||
setDefaultFileCompression(((Choice) mFileCompression.getSelectedItem()).getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> adapter) {
|
||||
// nothing to do
|
||||
}
|
||||
});
|
||||
|
||||
mAsciiArmour = (CheckBox) findViewById(R.id.asciiArmour);
|
||||
mAsciiArmour.setChecked(getDefaultAsciiArmour());
|
||||
mAsciiArmour.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
Loading…
Reference in New Issue
Block a user