consolidate: add key import routines with consolidation

This commit is contained in:
Vincent Breitmoser
2014-06-18 19:39:16 +02:00
parent f80228a08d
commit 134f8471c0
7 changed files with 199 additions and 54 deletions

View File

@@ -149,7 +149,8 @@ public class PgpImportExport {
SaveKeyringResult result;
if (key.isSecret()) {
result = mProviderHelper.saveSecretKeyRing(key);
result = mProviderHelper.saveSecretKeyRing(key,
new ProgressScaler(mProgressable, position, (position+1)*progSteps, 100));
} else {
result = mProviderHelper.savePublicKeyRing(key,
new ProgressScaler(mProgressable, position, (position+1)*progSteps, 100));

View File

@@ -58,10 +58,18 @@ public class UncachedKeyRing {
final PGPKeyRing mRing;
final boolean mIsSecret;
final boolean mIsCanonicalized;
UncachedKeyRing(PGPKeyRing ring) {
mRing = ring;
mIsSecret = ring instanceof PGPSecretKeyRing;
mIsCanonicalized = false;
}
private UncachedKeyRing(PGPKeyRing ring, boolean canonicalized) {
mRing = ring;
mIsSecret = ring instanceof PGPSecretKeyRing;
mIsCanonicalized = canonicalized;
}
public long getMasterKeyId() {
@@ -92,6 +100,10 @@ public class UncachedKeyRing {
return mIsSecret;
}
public boolean isCanonicalized() {
return mIsCanonicalized;
}
public byte[] getEncoded() throws IOException {
return mRing.getEncoded();
}
@@ -606,7 +618,7 @@ public class UncachedKeyRing {
log.add(LogLevel.OK, LogType.MSG_KC_SUCCESS, null, indent);
}
return new UncachedKeyRing(ring);
return new UncachedKeyRing(ring, true);
}
/** This operation merges information from a different keyring, returning a combined
@@ -688,6 +700,11 @@ public class UncachedKeyRing {
continue;
}
// Don't merge foreign stuff into secret keys
if (cert.getKeyID() != masterKeyId && isSecret()) {
continue;
}
byte[] encoded = cert.getEncoded();
// Known cert, skip it
if (certs.contains(encoded)) {
@@ -709,6 +726,10 @@ public class UncachedKeyRing {
// Copy over all user id certificates
for (String userId : new IterableIterator<String>(key.getUserIDs())) {
for (PGPSignature cert : new IterableIterator<PGPSignature>(key.getSignaturesForID(userId))) {
// Don't merge foreign stuff into secret keys
if (cert.getKeyID() != masterKeyId && isSecret()) {
continue;
}
byte[] encoded = cert.getEncoded();
// Known cert, skip it
if (certs.contains(encoded)) {

View File

@@ -101,4 +101,8 @@ public abstract class WrappedKeyRing extends KeyRing {
abstract public IterableIterator<WrappedPublicKey> publicKeyIterator();
public UncachedKeyRing getUncached() {
return new UncachedKeyRing(getRing());
}
}

View File

@@ -154,8 +154,4 @@ public class WrappedSecretKeyRing extends WrappedKeyRing {
});
}
public UncachedKeyRing getUncached() {
return new UncachedKeyRing(mRing);
}
}