aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpSignEncrypt.java
diff options
context:
space:
mode:
authorDominik Schürmann <dominik@dominikschuermann.de>2014-08-11 09:55:24 +0200
committerDominik Schürmann <dominik@dominikschuermann.de>2014-08-11 09:55:24 +0200
commit94b7b1b5d85339f38aff6a49535522af12213c75 (patch)
treebdde03c75d7d9e12d00dd0d95a67b900662de7e3 /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpSignEncrypt.java
parent867b89be0aff81781ccf15a172aae875fca9f940 (diff)
downloadopen-keychain-94b7b1b5d85339f38aff6a49535522af12213c75.tar.gz
open-keychain-94b7b1b5d85339f38aff6a49535522af12213c75.tar.bz2
open-keychain-94b7b1b5d85339f38aff6a49535522af12213c75.zip
progress for signing binary
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpSignEncrypt.java')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpSignEncrypt.java42
1 files changed, 27 insertions, 15 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpSignEncrypt.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpSignEncrypt.java
index b42e832fa..dda3f260c 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpSignEncrypt.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpSignEncrypt.java
@@ -37,6 +37,7 @@ import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
import org.sufficientlysecure.keychain.provider.ProviderHelper;
import org.sufficientlysecure.keychain.util.InputData;
import org.sufficientlysecure.keychain.util.Log;
+import org.sufficientlysecure.keychain.util.ProgressScaler;
import java.io.BufferedReader;
import java.io.IOException;
@@ -131,7 +132,7 @@ public class PgpSignEncrypt {
this.mOutStream = outStream;
}
- public Builder setProgressable(Progressable progressable) {
+ public Builder setProgressable(Progressable progressable) {
mProgressable = progressable;
return this;
}
@@ -277,7 +278,7 @@ public class PgpSignEncrypt {
}
try {
signingKey = signingKeyRing.getSigningSubKey();
- } catch(PgpGeneralException e) {
+ } catch (PgpGeneralException e) {
throw new NoSigningKeyException();
}
@@ -293,7 +294,7 @@ public class PgpSignEncrypt {
throw new KeyExtractionException();
}
}
- updateProgress(R.string.progress_preparing_streams, 5, 100);
+ updateProgress(R.string.progress_preparing_streams, 2, 100);
/* Initialize PGPEncryptedDataGenerator for later usage */
PGPEncryptedDataGenerator cPk = null;
@@ -334,13 +335,13 @@ public class PgpSignEncrypt {
PGPSignatureGenerator signatureGenerator = null;
PGPV3SignatureGenerator signatureV3Generator = null;
if (enableSignature) {
- updateProgress(R.string.progress_preparing_signature, 10, 100);
+ updateProgress(R.string.progress_preparing_signature, 4, 100);
try {
boolean cleartext = mCleartextInput && mEnableAsciiArmorOutput && !enableEncryption;
if (mSignatureForceV3) {
signatureV3Generator = signingKey.getV3SignatureGenerator(
- mSignatureHashAlgorithm,cleartext);
+ mSignatureHashAlgorithm, cleartext);
} else {
signatureGenerator = signingKey.getSignatureGenerator(
mSignatureHashAlgorithm, cleartext);
@@ -351,13 +352,15 @@ public class PgpSignEncrypt {
}
}
+ ProgressScaler progressScaler =
+ new ProgressScaler(mProgressable, 8, 95, 100);
PGPCompressedDataGenerator compressGen = null;
OutputStream pOut;
OutputStream encryptionOut = null;
BCPGOutputStream bcpgOut;
if (enableEncryption) {
/* actual encryption */
- updateProgress(R.string.progress_encrypting, 20, 100);
+ updateProgress(R.string.progress_encrypting, 8, 100);
encryptionOut = cPk.open(out, new byte[1 << 16]);
@@ -398,8 +401,9 @@ public class PgpSignEncrypt {
}
alreadyWritten += length;
- if (mData.getSize() != 0) {
- updateProgress((int) (20 + (95 - 20) * alreadyWritten / mData.getSize()), 100);
+ if (mData.getSize() > 0) {
+ long progress = 100 * alreadyWritten / mData.getSize();
+ progressScaler.setProgress((int) progress, 100);
}
}
@@ -407,7 +411,7 @@ public class PgpSignEncrypt {
} else if (enableSignature && mCleartextInput && mEnableAsciiArmorOutput) {
/* cleartext signature: sign-only of ascii text */
- updateProgress(R.string.progress_signing, 40, 100);
+ updateProgress(R.string.progress_signing, 8, 100);
// write -----BEGIN PGP SIGNED MESSAGE-----
armorOut.beginClearText(mSignatureHashAlgorithm);
@@ -422,6 +426,7 @@ public class PgpSignEncrypt {
processLine(reader.readLine(), armorOut, signatureGenerator);
}
+ // TODO: progress: fake annealing?
while (true) {
String line = reader.readLine();
@@ -449,7 +454,7 @@ public class PgpSignEncrypt {
} else if (enableSignature && !mCleartextInput) {
/* sign-only binary (files/data stream) */
- updateProgress(R.string.progress_signing, 40, 100);
+ updateProgress(R.string.progress_signing, 8, 100);
InputStream in = mData.getInputStream();
@@ -471,15 +476,22 @@ public class PgpSignEncrypt {
pOut = literalGen.open(bcpgOut, PGPLiteralData.BINARY, "", new Date(),
new byte[1 << 16]);
+ long alreadyWritten = 0;
+ int length;
byte[] buffer = new byte[1 << 16];
- int n;
- while ((n = in.read(buffer)) > 0) {
- pOut.write(buffer, 0, n);
+ while ((length = in.read(buffer)) > 0) {
+ pOut.write(buffer, 0, length);
if (mSignatureForceV3) {
- signatureV3Generator.update(buffer, 0, n);
+ signatureV3Generator.update(buffer, 0, length);
} else {
- signatureGenerator.update(buffer, 0, n);
+ signatureGenerator.update(buffer, 0, length);
+ }
+
+ alreadyWritten += length;
+ if (mData.getSize() > 0) {
+ long progress = 100 * alreadyWritten / mData.getSize();
+ progressScaler.setProgress((int) progress, 100);
}
}