aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/UncachedKeyRing.java
diff options
context:
space:
mode:
authorVincent Breitmoser <valodim@mugenguild.com>2014-06-18 10:00:21 +0200
committerVincent Breitmoser <valodim@mugenguild.com>2014-06-18 10:00:21 +0200
commit1e45e5cd9ad4e38bcff347bc7d3b8f422a636519 (patch)
treee0e1e7d5fb28ae5156eda41e6cce3d477b58ac52 /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/UncachedKeyRing.java
parentd8b0015d25b12f1b82e1a044fb3b130844141fda (diff)
downloadopen-keychain-1e45e5cd9ad4e38bcff347bc7d3b8f422a636519.tar.gz
open-keychain-1e45e5cd9ad4e38bcff347bc7d3b8f422a636519.tar.bz2
open-keychain-1e45e5cd9ad4e38bcff347bc7d3b8f422a636519.zip
code cleanup in ProviderHelper and UncachedKeyRing
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/UncachedKeyRing.java')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/UncachedKeyRing.java46
1 files changed, 20 insertions, 26 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/UncachedKeyRing.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/UncachedKeyRing.java
index 5cd13c4a2..5b353efbf 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/UncachedKeyRing.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/UncachedKeyRing.java
@@ -51,6 +51,7 @@ import java.util.Vector;
* @see org.sufficientlysecure.keychain.pgp.UncachedSecretKey
*
*/
+@SuppressWarnings("unchecked")
public class UncachedKeyRing {
final PGPKeyRing mRing;
@@ -65,12 +66,6 @@ public class UncachedKeyRing {
return mRing.getPublicKey().getKeyID();
}
- /* TODO don't use this */
- @Deprecated
- public PGPKeyRing getRing() {
- return mRing;
- }
-
public UncachedPublicKey getPublicKey() {
return new UncachedPublicKey(mRing.getPublicKey());
}
@@ -103,15 +98,6 @@ public class UncachedKeyRing {
return mRing.getPublicKey().getFingerprint();
}
- public static UncachedKeyRing decodePublicFromData(byte[] data)
- throws PgpGeneralException, IOException {
- UncachedKeyRing ring = decodeFromData(data);
- if(ring.isSecret()) {
- throw new PgpGeneralException("Object not recognized as PGPPublicKeyRing!");
- }
- return ring;
- }
-
public static UncachedKeyRing decodeFromData(byte[] data)
throws PgpGeneralException, IOException {
BufferedInputStream bufferedInput =
@@ -202,7 +188,8 @@ public class UncachedKeyRing {
* @return A canonicalized key, or null on fatal error
*
*/
- public UncachedKeyRing canonicalizePublic(OperationLog log, int indent) {
+ @SuppressWarnings("ConstantConditions")
+ public UncachedKeyRing canonicalize(OperationLog log, int indent) {
if (isSecret()) {
throw new RuntimeException("Tried to public-canonicalize non-public keyring. " +
"This is a programming error and should never happen!");
@@ -624,16 +611,6 @@ public class UncachedKeyRing {
return new UncachedKeyRing(ring);
}
- private static PGPKeyRing replacePublicKey(PGPKeyRing ring, PGPPublicKey key) {
- if (ring instanceof PGPPublicKeyRing) {
- return PGPPublicKeyRing.insertPublicKey((PGPPublicKeyRing) ring, key);
- }
- PGPSecretKeyRing secRing = (PGPSecretKeyRing) ring;
- PGPSecretKey sKey = secRing.getSecretKey(key.getKeyID());
- sKey = PGPSecretKey.replacePublicKey(sKey, key);
- return PGPSecretKeyRing.insertSecretKey(secRing, sKey);
- }
-
/** This operation consolidates a list of UncachedKeyRings into a single, combined
* UncachedKeyRing.
*
@@ -759,4 +736,21 @@ public class UncachedKeyRing {
}
+ /** This method replaces a public key in a keyring.
+ *
+ * This method essentially wraps PGP*KeyRing.insertPublicKey, where the keyring may be of either
+ * the secret or public subclass.
+ *
+ * @return the resulting PGPKeyRing of the same type as the input
+ */
+ private static PGPKeyRing replacePublicKey(PGPKeyRing ring, PGPPublicKey key) {
+ if (ring instanceof PGPPublicKeyRing) {
+ return PGPPublicKeyRing.insertPublicKey((PGPPublicKeyRing) ring, key);
+ }
+ PGPSecretKeyRing secRing = (PGPSecretKeyRing) ring;
+ PGPSecretKey sKey = secRing.getSecretKey(key.getKeyID());
+ sKey = PGPSecretKey.replacePublicKey(sKey, key);
+ return PGPSecretKeyRing.insertSecretKey(secRing, sKey);
+ }
+
}