JCE: remove switches on Strings for Android

pull/2/merge
Chris Conlon 2017-03-24 10:42:49 -06:00
parent 7036d06d19
commit b4be3b3655
2 changed files with 35 additions and 42 deletions

View File

@ -129,26 +129,22 @@ public class WolfCryptCipher extends CipherSpi {
int supported = 0; int supported = 0;
switch (mode) { if (mode.equals("ECB")) {
case "ECB":
/* RSA is ECB mode */
if (cipherType == CipherType.WC_RSA) {
cipherMode = CipherMode.WC_ECB;
supported = 1;
}
break;
case "CBC": /* RSA is ECB mode */
/* AES and 3DES support CBC */ if (cipherType == CipherType.WC_RSA) {
if (cipherType == CipherType.WC_AES || cipherMode = CipherMode.WC_ECB;
cipherType == CipherType.WC_DES3 ) { supported = 1;
cipherMode = CipherMode.WC_CBC; }
supported = 1;
}
break;
default: } else if (mode.equals("CBC")) {
break;
/* AES and 3DES support CBC */
if (cipherType == CipherType.WC_AES ||
cipherType == CipherType.WC_DES3 ) {
cipherMode = CipherMode.WC_CBC;
supported = 1;
}
} }
if (supported == 0) { if (supported == 0) {
@ -163,24 +159,20 @@ public class WolfCryptCipher extends CipherSpi {
int supported = 0; int supported = 0;
switch (padding) { if (padding.equals("NoPadding")) {
case "NoPadding":
if (cipherType == CipherType.WC_AES ||
cipherType == CipherType.WC_DES3) {
paddingType = PaddingType.WC_NONE;
supported = 1;
}
break;
case "PKCS1Padding": if (cipherType == CipherType.WC_AES ||
if (cipherType == CipherType.WC_RSA) { cipherType == CipherType.WC_DES3) {
paddingType = PaddingType.WC_PKCS1; paddingType = PaddingType.WC_NONE;
supported = 1; supported = 1;
} }
break;
default: } else if (padding.equals("PKCS1Padding")) {
break;
if (cipherType == CipherType.WC_RSA) {
paddingType = PaddingType.WC_PKCS1;
supported = 1;
}
} }
if (supported == 0) { if (supported == 0) {

View File

@ -285,14 +285,15 @@ public class WolfCryptKeyAgreement extends KeyAgreementSpi {
byte secret[] = engineGenerateSecret(); byte secret[] = engineGenerateSecret();
switch (algorithm) { if (algorithm.equals("DES")) {
case "DES": return (SecretKey)new DESKeySpec(secret);
return (SecretKey)new DESKeySpec(secret);
case "DESede": } else if (algorithm.equals("DESede")) {
return (SecretKey)new DESedeKeySpec(secret); return (SecretKey)new DESedeKeySpec(secret);
case "AES":
default: } else {
return new SecretKeySpec(secret, algorithm); /* AES and default */
return new SecretKeySpec(secret, algorithm);
} }
} }