getSignaturesForID can return null, check this

This commit is contained in:
Dominik Schürmann 2014-09-13 17:30:07 +02:00
parent 40c81c9429
commit aca9ecdb85
2 changed files with 146 additions and 127 deletions

View File

@ -375,9 +375,11 @@ public class UncachedKeyRing {
PGPSignature selfCert = null;
revocation = null;
// look through signatures for this specific key
for (PGPSignature zert : new IterableIterator<PGPSignature>(
masterKey.getSignaturesForID(userId))) {
// look through signatures for this specific user id
@SuppressWarnings("unchecked")
Iterator<PGPSignature> signaturesIt = masterKey.getSignaturesForID(userId);
if (signaturesIt != null) {
for (PGPSignature zert : new IterableIterator<PGPSignature>(signaturesIt)) {
WrappedSignature cert = new WrappedSignature(zert);
long certId = cert.getKeyId();
@ -496,9 +498,8 @@ public class UncachedKeyRing {
redundantCerts += 1;
}
break;
}
}
}
// If no valid certificate (if only a revocation) remains, drop it
@ -510,7 +511,7 @@ public class UncachedKeyRing {
}
// If NO user ids remain, error out!
if (!modified.getUserIDs().hasNext()) {
if (modified == null || !modified.getUserIDs().hasNext()) {
log.add(LogLevel.ERROR, LogType.MSG_KC_ERROR_NO_UID, indent);
return null;
}
@ -817,7 +818,13 @@ 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))) {
@SuppressWarnings("unchecked")
Iterator<PGPSignature> signaturesIt = key.getSignaturesForID(userId);
// no signatures for this User ID, skip it
if (signaturesIt == null) {
continue;
}
for (PGPSignature cert : new IterableIterator<PGPSignature>(signaturesIt)) {
// Don't merge foreign stuff into secret keys
if (cert.getKeyID() != masterKeyId && isSecret()) {
continue;

View File

@ -128,10 +128,18 @@ public class UncachedPublicKey {
public String getPrimaryUserId() {
String found = null;
PGPSignature foundSig = null;
// noinspection unchecked
for (String userId : new IterableIterator<String>(mPublicKey.getUserIDs())) {
PGPSignature revocation = null;
for (PGPSignature sig : new IterableIterator<PGPSignature>(mPublicKey.getSignaturesForID(userId))) {
@SuppressWarnings("unchecked")
Iterator<PGPSignature> signaturesIt = mPublicKey.getSignaturesForID(userId);
// no signatures for this User ID
if (signaturesIt == null) {
continue;
}
for (PGPSignature sig : new IterableIterator<PGPSignature>(signaturesIt)) {
try {
// if this is a revocation, this is not the user id
@ -314,6 +322,7 @@ public class UncachedPublicKey {
public Iterator<WrappedSignature> getSignaturesForId(String userId) {
final Iterator<PGPSignature> it = mPublicKey.getSignaturesForID(userId);
if (it != null) {
return new Iterator<WrappedSignature>() {
public void remove() {
it.remove();
@ -325,6 +334,9 @@ public class UncachedPublicKey {
return it.hasNext();
}
};
} else {
return null;
}
}
}