properly import keys from streams that may contain multiple blocks of ASCII armour or binary data, also small adjustment in strings

This commit is contained in:
Thialfihar 2010-05-20 22:03:41 +00:00
parent 6d107f3498
commit 260946009a
5 changed files with 49 additions and 49 deletions

View file

@ -166,9 +166,9 @@
<string name="specifyFileToExportSecretKeysTo">Please specify which file to export to.\nWARNING! You are about to export SECRET keys.\nWARNING! File will be overwritten if it exists.</string> <string name="specifyFileToExportSecretKeysTo">Please specify which file to export to.\nWARNING! You are about to export SECRET keys.\nWARNING! File will be overwritten if it exists.</string>
<string name="keyDeletionConfirmation">Do you really want to delete the key '%s'?\nYou can't undo this!</string> <string name="keyDeletionConfirmation">Do you really want to delete the key '%s'?\nYou can't undo this!</string>
<string name="secretKeyDeletionConfirmation">Do you really want to delete the SECRET key '%s'?\nYou can't undo this!</string> <string name="secretKeyDeletionConfirmation">Do you really want to delete the SECRET key '%s'?\nYou can't undo this!</string>
<string name="keysAddedAndUpdated">Succssfully added %s keys and updated %s keys."</string> <string name="keysAddedAndUpdated">Succssfully added %s key(s) and updated %s key(s)."</string>
<string name="keysAdded">Succssfully added %s keys.</string> <string name="keysAdded">Succssfully added %s key(s).</string>
<string name="keysUpdated">Succssfully updated %s keys.</string> <string name="keysUpdated">Succssfully updated %s key(s).</string>
<string name="noKeysAddedOrUpdated">No keys added or updated.</string> <string name="noKeysAddedOrUpdated">No keys added or updated.</string>
<string name="keyExported">Succssfully exported 1 key.</string> <string name="keyExported">Succssfully exported 1 key.</string>
<string name="keysExported">Succssfully exported %s keys.</string> <string name="keysExported">Succssfully exported %s keys.</string>

View file

@ -166,9 +166,9 @@
<string name="specifyFileToExportSecretKeysTo">Please specify which file to export to.\nWARNING! You are about to export SECRET keys.\nWARNING! File will be overwritten if it exists.</string> <string name="specifyFileToExportSecretKeysTo">Please specify which file to export to.\nWARNING! You are about to export SECRET keys.\nWARNING! File will be overwritten if it exists.</string>
<string name="keyDeletionConfirmation">Do you really want to delete the key '%s'?\nYou can't undo this!</string> <string name="keyDeletionConfirmation">Do you really want to delete the key '%s'?\nYou can't undo this!</string>
<string name="secretKeyDeletionConfirmation">Do you really want to delete the SECRET key '%s'?\nYou can't undo this!</string> <string name="secretKeyDeletionConfirmation">Do you really want to delete the SECRET key '%s'?\nYou can't undo this!</string>
<string name="keysAddedAndUpdated">Succssfully added %s keys and updated %s keys."</string> <string name="keysAddedAndUpdated">Succssfully added %s key(s) and updated %s key(s)."</string>
<string name="keysAdded">Succssfully added %s keys.</string> <string name="keysAdded">Succssfully added %s key(s).</string>
<string name="keysUpdated">Succssfully updated %s keys.</string> <string name="keysUpdated">Succssfully updated %s key(s).</string>
<string name="noKeysAddedOrUpdated">No keys added or updated.</string> <string name="noKeysAddedOrUpdated">No keys added or updated.</string>
<string name="keyExported">Succssfully exported 1 key.</string> <string name="keyExported">Succssfully exported 1 key.</string>
<string name="keysExported">Succssfully exported %s keys.</string> <string name="keysExported">Succssfully exported %s keys.</string>

View file

@ -166,9 +166,9 @@
<string name="specifyFileToExportSecretKeysTo">Please specify which file to export to.\nWARNING! You are about to export SECRET keys.\nWARNING! File will be overwritten if it exists.</string> <string name="specifyFileToExportSecretKeysTo">Please specify which file to export to.\nWARNING! You are about to export SECRET keys.\nWARNING! File will be overwritten if it exists.</string>
<string name="keyDeletionConfirmation">Do you really want to delete the key '%s'?\nYou can't undo this!</string> <string name="keyDeletionConfirmation">Do you really want to delete the key '%s'?\nYou can't undo this!</string>
<string name="secretKeyDeletionConfirmation">Do you really want to delete the SECRET key '%s'?\nYou can't undo this!</string> <string name="secretKeyDeletionConfirmation">Do you really want to delete the SECRET key '%s'?\nYou can't undo this!</string>
<string name="keysAddedAndUpdated">Succssfully added %s keys and updated %s keys."</string> <string name="keysAddedAndUpdated">Succssfully added %s key(s) and updated %s key(s)."</string>
<string name="keysAdded">Succssfully added %s keys.</string> <string name="keysAdded">Succssfully added %s key(s).</string>
<string name="keysUpdated">Succssfully updated %s keys.</string> <string name="keysUpdated">Succssfully updated %s key(s).</string>
<string name="noKeysAddedOrUpdated">No keys added or updated.</string> <string name="noKeysAddedOrUpdated">No keys added or updated.</string>
<string name="keyExported">Succssfully exported 1 key.</string> <string name="keyExported">Succssfully exported 1 key.</string>
<string name="keysExported">Succssfully exported %s keys.</string> <string name="keysExported">Succssfully exported %s keys.</string>

View file

@ -166,9 +166,9 @@
<string name="specifyFileToExportSecretKeysTo">Please specify which file to export to.\nWARNING! You are about to export SECRET keys.\nWARNING! File will be overwritten if it exists.</string> <string name="specifyFileToExportSecretKeysTo">Please specify which file to export to.\nWARNING! You are about to export SECRET keys.\nWARNING! File will be overwritten if it exists.</string>
<string name="keyDeletionConfirmation">Do you really want to delete the key '%s'?\nYou can't undo this!</string> <string name="keyDeletionConfirmation">Do you really want to delete the key '%s'?\nYou can't undo this!</string>
<string name="secretKeyDeletionConfirmation">Do you really want to delete the SECRET key '%s'?\nYou can't undo this!</string> <string name="secretKeyDeletionConfirmation">Do you really want to delete the SECRET key '%s'?\nYou can't undo this!</string>
<string name="keysAddedAndUpdated">Succssfully added %s keys and updated %s keys."</string> <string name="keysAddedAndUpdated">Succssfully added %s key(s) and updated %s key(s)."</string>
<string name="keysAdded">Succssfully added %s keys.</string> <string name="keysAdded">Succssfully added %s key(s).</string>
<string name="keysUpdated">Succssfully updated %s keys.</string> <string name="keysUpdated">Succssfully updated %s key(s).</string>
<string name="noKeysAddedOrUpdated">No keys added or updated.</string> <string name="noKeysAddedOrUpdated">No keys added or updated.</string>
<string name="keyExported">Succssfully exported 1 key.</string> <string name="keyExported">Succssfully exported 1 key.</string>
<string name="keysExported">Succssfully exported %s keys.</string> <string name="keysExported">Succssfully exported %s keys.</string>

View file

@ -691,7 +691,6 @@ public class Apg {
ProgressDialogUpdater progress) ProgressDialogUpdater progress)
throws GeneralException, FileNotFoundException, PGPException, IOException { throws GeneralException, FileNotFoundException, PGPException, IOException {
Bundle returnData = new Bundle(); Bundle returnData = new Bundle();
PGPObjectFactory objectFactory = null;
if (type == Id.type.secret_key) { if (type == Id.type.secret_key) {
progress.setProgress(R.string.progress_importingSecretKeys, 0, 100); progress.setProgress(R.string.progress_importingSecretKeys, 0, 100);
@ -704,47 +703,48 @@ public class Apg {
} }
FileInputStream fileIn = new FileInputStream(filename); FileInputStream fileIn = new FileInputStream(filename);
InputStream in = PGPUtil.getDecoderStream(fileIn); long fileSize = new File(filename).length();
objectFactory = new PGPObjectFactory(in); PositionAwareInputStream progressIn = new PositionAwareInputStream(fileIn);
// need to have access to the bufferedInput, so we can reuse it for the possible
Vector<Object> objects = new Vector<Object>(); // PGPObject chunks after the first one, e.g. files with several consecutive ASCII
Object obj = objectFactory.nextObject(); // armour blocks
while (obj != null) { BufferedInputStream bufferedInput = new BufferedInputStream(progressIn);
objects.add(obj);
obj = objectFactory.nextObject();
}
int newKeys = 0; int newKeys = 0;
int oldKeys = 0; int oldKeys = 0;
for (int i = 0; i < objects.size(); ++i) { while (true) {
progress.setProgress(i * 100 / objects.size(), 100); InputStream in = PGPUtil.getDecoderStream(bufferedInput);
obj = objects.get(i); PGPObjectFactory objectFactory = new PGPObjectFactory(in);
PGPPublicKeyRing publicKeyRing; Object obj = objectFactory.nextObject();
PGPSecretKeyRing secretKeyRing; // if the first is already a null object, then we can stop trying
int retValue; if (obj == null) {
break;
if (type == Id.type.secret_key) {
if (!(obj instanceof PGPSecretKeyRing)) {
continue;
}
secretKeyRing = (PGPSecretKeyRing) obj;
retValue = saveKeyRing(context, secretKeyRing);
} else {
if (!(obj instanceof PGPPublicKeyRing)) {
continue;
}
publicKeyRing = (PGPPublicKeyRing) obj;
retValue = saveKeyRing(context, publicKeyRing);
} }
while (obj != null) {
PGPPublicKeyRing publicKeyRing;
PGPSecretKeyRing secretKeyRing;
// a return value that doesn't match any Id.return_value.* values, in case
// saveKeyRing is never called
int retValue = 2107;
if (retValue == Id.return_value.error) { if (type == Id.type.secret_key && obj instanceof PGPSecretKeyRing) {
throw new GeneralException(context.getString(R.string.error_savingKeys)); secretKeyRing = (PGPSecretKeyRing) obj;
} retValue = saveKeyRing(context, secretKeyRing);
} else if (type == Id.type.public_key && obj instanceof PGPPublicKeyRing) {
publicKeyRing = (PGPPublicKeyRing) obj;
retValue = saveKeyRing(context, publicKeyRing);
}
if (retValue == Id.return_value.updated) { if (retValue == Id.return_value.error) {
++oldKeys; throw new GeneralException(context.getString(R.string.error_savingKeys));
} else if (retValue == Id.return_value.ok) { }
++newKeys;
if (retValue == Id.return_value.updated) {
++oldKeys;
} else if (retValue == Id.return_value.ok) {
++newKeys;
}
progress.setProgress((int)(100 * progressIn.position() / fileSize), 100);
obj = objectFactory.nextObject();
} }
} }