Use PublicKeyAlgorithmTags instead of homebrew choices constants, fix expiry selection for adding new subkeys

This commit is contained in:
Dominik Schürmann
2014-08-05 20:52:29 +02:00
parent 39380a3617
commit f8a222983e
10 changed files with 102 additions and 78 deletions

View File

@@ -24,7 +24,7 @@ import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.style.ForegroundColorSpan;
import org.spongycastle.openpgp.PGPPublicKey;
import org.spongycastle.bcpg.PublicKeyAlgorithmTags;
import org.spongycastle.util.encoders.Hex;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R;
@@ -37,9 +37,6 @@ import java.util.Locale;
public class PgpKeyHelper {
/**
* TODO: Only used in HkpKeyServer. Get rid of this one!
*/
public static String getAlgorithmInfo(int algorithm) {
return getAlgorithmInfo(null, algorithm, 0);
}
@@ -55,25 +52,25 @@ public class PgpKeyHelper {
String algorithmStr;
switch (algorithm) {
case PGPPublicKey.RSA_ENCRYPT:
case PGPPublicKey.RSA_GENERAL:
case PGPPublicKey.RSA_SIGN: {
case PublicKeyAlgorithmTags.RSA_ENCRYPT:
case PublicKeyAlgorithmTags.RSA_GENERAL:
case PublicKeyAlgorithmTags.RSA_SIGN: {
algorithmStr = "RSA";
break;
}
case PGPPublicKey.DSA: {
case PublicKeyAlgorithmTags.DSA: {
algorithmStr = "DSA";
break;
}
case PGPPublicKey.ELGAMAL_ENCRYPT:
case PGPPublicKey.ELGAMAL_GENERAL: {
case PublicKeyAlgorithmTags.ELGAMAL_ENCRYPT:
case PublicKeyAlgorithmTags.ELGAMAL_GENERAL: {
algorithmStr = "ElGamal";
break;
}
case PGPPublicKey.ECDSA:
case PGPPublicKey.ECDH: {
case PublicKeyAlgorithmTags.ECDSA:
case PublicKeyAlgorithmTags.ECDH: {
algorithmStr = "ECC";
break;
}
@@ -82,7 +79,6 @@ public class PgpKeyHelper {
if (context != null) {
algorithmStr = context.getResources().getString(R.string.unknown_algorithm);
} else {
// TODO
algorithmStr = "unknown";
}
break;

View File

@@ -20,6 +20,7 @@ package org.sufficientlysecure.keychain.pgp;
import org.spongycastle.bcpg.CompressionAlgorithmTags;
import org.spongycastle.bcpg.HashAlgorithmTags;
import org.spongycastle.bcpg.PublicKeyAlgorithmTags;
import org.spongycastle.bcpg.SymmetricKeyAlgorithmTags;
import org.spongycastle.bcpg.sig.KeyFlags;
import org.spongycastle.jce.spec.ElGamalParameterSpec;
@@ -138,7 +139,7 @@ public class PgpKeyOperation {
KeyPairGenerator keyGen;
switch (algorithmChoice) {
case Constants.choice.algorithm.dsa: {
case PublicKeyAlgorithmTags.DSA: {
progress(R.string.progress_generating_dsa, 30);
keyGen = KeyPairGenerator.getInstance("DSA", Constants.BOUNCY_CASTLE_PROVIDER_NAME);
keyGen.initialize(keySize, new SecureRandom());
@@ -146,7 +147,7 @@ public class PgpKeyOperation {
break;
}
case Constants.choice.algorithm.elgamal: {
case PublicKeyAlgorithmTags.ELGAMAL_ENCRYPT: {
progress(R.string.progress_generating_elgamal, 30);
keyGen = KeyPairGenerator.getInstance("ElGamal", Constants.BOUNCY_CASTLE_PROVIDER_NAME);
BigInteger p = Primes.getBestPrime(keySize);
@@ -159,7 +160,7 @@ public class PgpKeyOperation {
break;
}
case Constants.choice.algorithm.rsa: {
case PublicKeyAlgorithmTags.RSA_GENERAL: {
progress(R.string.progress_generating_rsa, 30);
keyGen = KeyPairGenerator.getInstance("RSA", Constants.BOUNCY_CASTLE_PROVIDER_NAME);
keyGen.initialize(keySize, new SecureRandom());
@@ -217,7 +218,7 @@ public class PgpKeyOperation {
return new EditKeyResult(EditKeyResult.RESULT_ERROR, log, null);
}
if (add.mAlgorithm == Constants.choice.algorithm.elgamal) {
if (add.mAlgorithm == PublicKeyAlgorithmTags.ELGAMAL_ENCRYPT) {
log.add(LogLevel.ERROR, LogType.MSG_CR_ERROR_MASTER_ELGAMAL, indent);
return new EditKeyResult(EditKeyResult.RESULT_ERROR, log, null);
}