Refactored code to use functions already present in code, reduced liberties taken when modifying functions.

Todo:
Fix indentation for error messages
This commit is contained in:
Alex Fong
2016-03-15 20:59:42 +08:00
parent 525788359c
commit b490be9c1c
2 changed files with 29 additions and 28 deletions

View File

@@ -63,15 +63,6 @@ public class PassphraseChangeOperation extends BaseOperation<PassphraseChangePar
CanonicalizedSecretKeyRing secRing =
mProviderHelper.getCanonicalizedSecretKeyRing(passphraseParcel.mMasterKeyId);
CachedPublicKeyRing cachedRing =
mProviderHelper.getCachedPublicKeyRing(passphraseParcel.mMasterKeyId);
passphraseParcel.mValidSubkeyId = getFirstValidKeyId(secRing, cachedRing);
if(passphraseParcel.mValidSubkeyId == null) {
log.add(OperationResult.LogType.MSG_MF_ERROR_ALL_KEYS_STRIPPED, 0);
return new EditKeyResult(EditKeyResult.RESULT_ERROR, log, null);
}
modifyResult = keyOperations.modifyKeyRingPassword(secRing, cryptoInput, passphraseParcel);
@@ -119,23 +110,4 @@ public class PassphraseChangeOperation extends BaseOperation<PassphraseChangePar
}
private static Long getFirstValidKeyId (CanonicalizedSecretKeyRing secRing, CachedPublicKeyRing cachedRing) {
Iterator<CanonicalizedSecretKey> secretKeyIterator = secRing.secretKeyIterator().iterator();
while(secretKeyIterator.hasNext()) {
try {
long keyId = secretKeyIterator.next().getKeyId();
CanonicalizedSecretKey.SecretKeyType keyType = cachedRing.getSecretKeyType(keyId);
if( keyType == CanonicalizedSecretKey.SecretKeyType.PASSPHRASE
|| keyType == CanonicalizedSecretKey.SecretKeyType.PASSPHRASE_EMPTY) {
return keyId;
}
} catch (ProviderHelper.NotFoundException e) {
;
}
}
return null;
}
}