mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-23 17:22:16 -05:00
progress for signing binary
This commit is contained in:
parent
867b89be0a
commit
94b7b1b5d8
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user