consolidate: add logging

This commit is contained in:
Vincent Breitmoser
2014-06-17 00:12:06 +02:00
parent b4974d922e
commit d8b0015d25
5 changed files with 61 additions and 8 deletions

View File

@@ -643,6 +643,7 @@ public class UncachedKeyRing {
*
* TODO work with secret keys
*
* @param list The list of UncachedKeyRings. Must not be empty, and all of the same masterKeyId
* @return A consolidated UncachedKeyRing with the data of all input keyrings.
*
*/
@@ -650,15 +651,12 @@ public class UncachedKeyRing {
OperationLog log, int indent) {
long masterKeyId = list.get(0).getMasterKeyId();
for (UncachedKeyRing ring : new IterableIterator<UncachedKeyRing>(list.iterator())) {
if (ring.getMasterKeyId() != masterKeyId) {
// log.add(LogLevel.ERROR, LogType.MSG_KO, null, indent);
return null;
}
}
// log.add(LogLevel.START, LogType.MSG_KO,
// new String[]{PgpKeyHelper.convertKeyIdToHex(masterKeyId)}, indent);
log.add(LogLevel.START, LogType.MSG_KO,
new String[]{
Integer.toString(list.size()),
PgpKeyHelper.convertKeyIdToHex(masterKeyId)
}, indent);
indent += 1;
// remember which certs we already added
@@ -666,13 +664,28 @@ public class UncachedKeyRing {
try {
PGPPublicKeyRing result = null;
int num = 1;
for (UncachedKeyRing uring : new IterableIterator<UncachedKeyRing>(list.iterator())) {
PGPPublicKeyRing ring = (PGPPublicKeyRing) uring.mRing;
if (uring.getMasterKeyId() != masterKeyId) {
log.add(LogLevel.ERROR, LogType.MSG_KO_HETEROGENEOUS, null, indent);
return null;
}
// If this is the first ring, just take it
if (result == null) {
result = ring;
continue;
}
log.add(LogLevel.DEBUG, LogType.MSG_KO_MERGING,
new String[] { Integer.toString(num++) }, indent);
indent += 1;
// keep track of the number of new certs we add
int newCerts = 0;
for (PGPPublicKey key : new IterableIterator<PGPPublicKey>(ring.getPublicKeys())) {
final PGPPublicKey resultkey = result.getPublicKey(key.getKeyID());
@@ -702,6 +715,7 @@ public class UncachedKeyRing {
}
certs.add(hash);
modified = PGPPublicKey.addCertification(modified, cert);
newCerts += 1;
}
// If this is a subkey, stop here
@@ -718,6 +732,7 @@ public class UncachedKeyRing {
if (certs.contains(hash)) {
continue;
}
newCerts += 1;
certs.add(hash);
modified = PGPPublicKey.addCertification(modified, userId, cert);
}
@@ -726,13 +741,19 @@ public class UncachedKeyRing {
if (modified != resultkey) {
result = PGPPublicKeyRing.insertPublicKey(result, modified);
}
}
log.add(LogLevel.DEBUG, LogType.MSG_KO_FOUND_NEW,
new String[] { Integer.toString(newCerts) }, indent);
}
return new UncachedKeyRing(result);
} catch (IOException e) {
log.add(LogLevel.ERROR, LogType.MSG_KO_FATAL_ENCODE, null, indent);
return null;
}

View File

@@ -91,6 +91,12 @@ public abstract class WrappedKeyRing extends KeyRing {
getRing().encode(stream);
}
/** Returns an UncachedKeyRing which wraps the same data as this ring. This method should
* only be used */
public UncachedKeyRing getUncachedKeyRing() {
return new UncachedKeyRing(getRing());
}
abstract PGPKeyRing getRing();
abstract public IterableIterator<WrappedPublicKey> publicKeyIterator();