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 */ /* RSA is ECB mode */
if (cipherType == CipherType.WC_RSA) { if (cipherType == CipherType.WC_RSA) {
cipherMode = CipherMode.WC_ECB; cipherMode = CipherMode.WC_ECB;
supported = 1; supported = 1;
} }
break;
case "CBC": } else if (mode.equals("CBC")) {
/* AES and 3DES support CBC */ /* AES and 3DES support CBC */
if (cipherType == CipherType.WC_AES || if (cipherType == CipherType.WC_AES ||
cipherType == CipherType.WC_DES3 ) { cipherType == CipherType.WC_DES3 ) {
cipherMode = CipherMode.WC_CBC; cipherMode = CipherMode.WC_CBC;
supported = 1; supported = 1;
} }
break;
default:
break;
} }
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 || if (cipherType == CipherType.WC_AES ||
cipherType == CipherType.WC_DES3) { cipherType == CipherType.WC_DES3) {
paddingType = PaddingType.WC_NONE; paddingType = PaddingType.WC_NONE;
supported = 1; supported = 1;
} }
break;
case "PKCS1Padding": } else if (padding.equals("PKCS1Padding")) {
if (cipherType == CipherType.WC_RSA) { if (cipherType == CipherType.WC_RSA) {
paddingType = PaddingType.WC_PKCS1; paddingType = PaddingType.WC_PKCS1;
supported = 1; supported = 1;
} }
break;
default:
break;
} }
if (supported == 0) { if (supported == 0) {

View File

@ -285,13 +285,14 @@ 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 {
/* AES and default */
return new SecretKeySpec(secret, algorithm); return new SecretKeySpec(secret, algorithm);
} }
} }