mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-27 11:12:15 -05:00
code cleanup in ProviderHelper and UncachedKeyRing
This commit is contained in:
parent
d8b0015d25
commit
1e45e5cd9a
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ import java.util.Set;
|
||||
* name, it is not only a helper but actually the main interface for all
|
||||
* synchronous database operations.
|
||||
*
|
||||
* Operations in this class write logs (TODO). These can be obtained from the
|
||||
* Operations in this class write logs. These can be obtained from the
|
||||
* OperationResultParcel return values directly, but are also accumulated over
|
||||
* the lifetime of the executing ProviderHelper object unless the resetLog()
|
||||
* method is called to start a new one specifically.
|
||||
@ -284,16 +284,8 @@ public class ProviderHelper {
|
||||
new String[]{ PgpKeyHelper.convertKeyIdToHex(masterKeyId) });
|
||||
mIndent += 1;
|
||||
|
||||
try {
|
||||
WrappedPublicKeyRing ring = getWrappedPublicKeyRing(KeyRings.buildUnifiedKeyRingUri(masterKeyId));
|
||||
// ring.get
|
||||
|
||||
} catch(NotFoundException e) {
|
||||
// no biggie
|
||||
}
|
||||
|
||||
// Canonicalize this key, to assert a number of assumptions made about it.
|
||||
keyRing = keyRing.canonicalizePublic(mLog, mIndent);
|
||||
keyRing = keyRing.canonicalize(mLog, mIndent);
|
||||
if (keyRing == null) {
|
||||
return SaveKeyringResult.RESULT_ERROR;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user