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="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="keysAddedAndUpdated">Succssfully added %s keys and updated %s keys."</string>
<string name="keysAdded">Succssfully added %s keys.</string>
<string name="keysUpdated">Succssfully updated %s keys.</string>
<string name="keysAddedAndUpdated">Succssfully added %s key(s) and updated %s key(s)."</string>
<string name="keysAdded">Succssfully added %s key(s).</string>
<string name="keysUpdated">Succssfully updated %s key(s).</string>
<string name="noKeysAddedOrUpdated">No keys added or updated.</string>
<string name="keyExported">Succssfully exported 1 key.</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="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="keysAddedAndUpdated">Succssfully added %s keys and updated %s keys."</string>
<string name="keysAdded">Succssfully added %s keys.</string>
<string name="keysUpdated">Succssfully updated %s keys.</string>
<string name="keysAddedAndUpdated">Succssfully added %s key(s) and updated %s key(s)."</string>
<string name="keysAdded">Succssfully added %s key(s).</string>
<string name="keysUpdated">Succssfully updated %s key(s).</string>
<string name="noKeysAddedOrUpdated">No keys added or updated.</string>
<string name="keyExported">Succssfully exported 1 key.</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="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="keysAddedAndUpdated">Succssfully added %s keys and updated %s keys."</string>
<string name="keysAdded">Succssfully added %s keys.</string>
<string name="keysUpdated">Succssfully updated %s keys.</string>
<string name="keysAddedAndUpdated">Succssfully added %s key(s) and updated %s key(s)."</string>
<string name="keysAdded">Succssfully added %s key(s).</string>
<string name="keysUpdated">Succssfully updated %s key(s).</string>
<string name="noKeysAddedOrUpdated">No keys added or updated.</string>
<string name="keyExported">Succssfully exported 1 key.</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="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="keysAddedAndUpdated">Succssfully added %s keys and updated %s keys."</string>
<string name="keysAdded">Succssfully added %s keys.</string>
<string name="keysUpdated">Succssfully updated %s keys.</string>
<string name="keysAddedAndUpdated">Succssfully added %s key(s) and updated %s key(s)."</string>
<string name="keysAdded">Succssfully added %s key(s).</string>
<string name="keysUpdated">Succssfully updated %s key(s).</string>
<string name="noKeysAddedOrUpdated">No keys added or updated.</string>
<string name="keyExported">Succssfully exported 1 key.</string>
<string name="keysExported">Succssfully exported %s keys.</string>

View file

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