Split PGPEncryptedDataGenerator creation out into a utility method

Split the creation of PGPEncryptedDataGenerator out into a utility
method.  Inline the call to the open() method on the returned generator
rather than storing the generator in a temporary variable.

Suppress deprecation warnings caused by using methods that have been
deprecated in the new version of Bouncycastle that was introduced
recently.  We cannot yet replace the calls with the newer versions
because some Gerrit sites still use the older version of Bouncycastle.

Change-Id: I98f4b7c7bf8ab1ee74eb8bbc86b673d057d98e46
This commit is contained in:
David Pursehouse
2013-12-06 14:05:45 +09:00
parent 8e19090765
commit 1caca85b93

View File

@@ -173,17 +173,23 @@ class EncryptedContactStore implements ContactStore {
}
}
@SuppressWarnings("deprecation")
private final PGPEncryptedDataGenerator cpk()
throws NoSuchProviderException, PGPException {
PGPEncryptedDataGenerator cpk =
new PGPEncryptedDataGenerator(PGPEncryptedData.CAST5, true, prng, "BC");
cpk.addMethod(dest);
return cpk;
}
private byte[] encrypt(final String name, final Date date,
final byte[] rawText) throws NoSuchProviderException, PGPException,
IOException {
final byte[] zText = compress(name, date, rawText);
final PGPEncryptedDataGenerator cpk =
new PGPEncryptedDataGenerator(PGPEncryptedData.CAST5, true, prng, "BC");
cpk.addMethod(dest);
final ByteArrayOutputStream buf = new ByteArrayOutputStream();
final ArmoredOutputStream aout = new ArmoredOutputStream(buf);
final OutputStream cout = cpk.open(aout, zText.length);
final OutputStream cout = cpk().open(aout, zText.length);
cout.write(zText);
cout.close();
aout.close();