入参检查
This commit is contained in:
parent
0e5fb0f56f
commit
fdbcf5d43b
@ -265,7 +265,7 @@ public class SydApiBaseFunction implements SydApi {
|
||||
}
|
||||
if (Consts.ECB_ENC == iFlag) {
|
||||
if ( 0 == pcData.length || pcData.length > 1024 ) {
|
||||
throw new SydApiException("输入内容超长",0x01000001);
|
||||
throw new SydApiException("输入内容长度错误",0x01000001);
|
||||
}
|
||||
} else {
|
||||
if ( 0 == pcData.length || pcData.length % 16 != 0 || pcData.length > 1040 ) {
|
||||
@ -342,15 +342,23 @@ public class SydApiBaseFunction implements SydApi {
|
||||
log.debug("SYD_SM4_BatchData方法接收参数:iKeyIndex:{},pcData元素个数为:{},iFlag:{}", iKeyIndex, pcData.size(), iFlag);
|
||||
}
|
||||
|
||||
if ( null == pcData ) {
|
||||
throw new SydApiException("输入参数错误", 0x01000001);
|
||||
}
|
||||
|
||||
if (pcData.isEmpty()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
if (iFlag == Consts.ECB_DEC) {
|
||||
for (byte[] pcdata : pcData) {
|
||||
if (null == pcData || pcdata.length == 0 || pcdata.length > 1040) {
|
||||
throw new SydApiException(19);
|
||||
if ( pcdata.length == 0 || pcdata.length % 16 != 0 || pcdata.length > 1040) {
|
||||
throw new SydApiException(0x01000015);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (byte[] pcdata : pcData) {
|
||||
if (null == pcData || pcdata.length > 1024) {
|
||||
if ( pcdata.length > 1024) {
|
||||
throw new SydApiException(19);
|
||||
}
|
||||
}
|
||||
@ -363,6 +371,9 @@ public class SydApiBaseFunction implements SydApi {
|
||||
String[] keys = new String[iKeyIndex.length];
|
||||
updateLastUseTime();
|
||||
for (int i = 0; i < iKeyIndex.length; i++) {
|
||||
if ( iKeyIndex[i] < 0 ) {
|
||||
throw new SydApiException(0x01000001);
|
||||
}
|
||||
keys[i] = "SK" + SYMUtil.genPrivateKeyMark("000000", "00A", String.format("%08d", iKeyIndex[i]));
|
||||
}
|
||||
|
||||
@ -419,8 +430,13 @@ public class SydApiBaseFunction implements SydApi {
|
||||
if (LogFactory.iLogLevel == 3) {
|
||||
log.debug("SYD_SM4_LongData方法接收参数:iKeyIndex:{},pcData:{},iPkgNum:{},iFlag:{}", iKeyIndex, Arrays.toString(pcData), iPkgNum, iFlag);
|
||||
}
|
||||
if (iFlag == Consts.ECB_DEC && (null == pcData || pcData.length == 0)) {
|
||||
throw new SydApiException(19);
|
||||
|
||||
if ( iKeyIndex < 0 ) {
|
||||
throw new SydApiException(0x01000001);
|
||||
}
|
||||
|
||||
if (iFlag == Consts.ECB_DEC && (null == pcData || pcData.length == 0 || pcData.length % 16 != 0)) {
|
||||
throw new SydApiException(0x01000015);
|
||||
}
|
||||
if (null == this.hsms || this.hsms.length < 1) {
|
||||
throw new SydApiException(-1);
|
||||
@ -504,6 +520,11 @@ public class SydApiBaseFunction implements SydApi {
|
||||
if (LogFactory.iLogLevel == 3) {
|
||||
log.debug("SYD_SM4Mac_BatchData:iKeyIndex:{},pcData元素个数为:{}", iKeyIndex, pcData.size());
|
||||
}
|
||||
|
||||
if (pcData.isEmpty()) {
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
if (null == this.hsms || this.hsms.length < 1) {
|
||||
throw new SydApiException(-1);
|
||||
}
|
||||
@ -511,6 +532,9 @@ public class SydApiBaseFunction implements SydApi {
|
||||
String[] keys = new String[iKeyIndex.length];
|
||||
updateLastUseTime();
|
||||
for (int i = 0; i < iKeyIndex.length; i++) {
|
||||
if ( iKeyIndex[i] < 0 ) {
|
||||
throw new SydApiException(0x01000001);
|
||||
}
|
||||
keys[i] = "SK" + SYMUtil.genPrivateKeyMark("000000", "00A", String.format("%08d", iKeyIndex[i]));
|
||||
}
|
||||
SydApiException le = new SydApiException(-1);
|
||||
@ -574,6 +598,11 @@ public class SydApiBaseFunction implements SydApi {
|
||||
if (LogFactory.iLogLevel == 3) {
|
||||
log.debug("SYD_SM4Mac_BatchData方法接收参数:iKeyIndex:{},pcData元素个数为:{},pcMac:{}", iKeyIndex, pcData.size(), Arrays.toString(pcMac));
|
||||
}
|
||||
|
||||
if (pcData.isEmpty()) {
|
||||
return new boolean[0];
|
||||
}
|
||||
|
||||
if (null == this.hsms || this.hsms.length < 1) {
|
||||
throw new SydApiException(-1);
|
||||
}
|
||||
@ -913,6 +942,15 @@ public class SydApiBaseFunction implements SydApi {
|
||||
|
||||
@Override
|
||||
public List<DataAndMac> SYD_SM4_EncryptAndMac_BatchData(int[] iEncKeyIndex, int[] iMacKeyIndex, List<byte[]> pcData) {
|
||||
|
||||
if (LogFactory.iLogLevel == 3) {
|
||||
log.debug("SYD_SM4_EncryptAndMac_BatchData");
|
||||
}
|
||||
|
||||
if (pcData.isEmpty()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
if (null == this.hsms || null == iMacKeyIndex || null == pcData) {
|
||||
throw new SydApiException("输入内容为空",15);
|
||||
}
|
||||
@ -932,6 +970,15 @@ public class SydApiBaseFunction implements SydApi {
|
||||
|
||||
@Override
|
||||
public List<DataAndMacCheck> SYD_SM4_CheckMacAndDecrypt_BatchData(int[] iEncKeyIndex, int[] iMacKeyIndex, List<DataAndMac> pcData) {
|
||||
|
||||
if (LogFactory.iLogLevel == 3) {
|
||||
log.debug("SYD_SM4_CheckMacAndDecrypt_BatchData");
|
||||
}
|
||||
|
||||
if (pcData.isEmpty()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
if (null == this.hsms || null == iMacKeyIndex || null == pcData) {
|
||||
throw new SydApiException("输入内容为空",15);
|
||||
}
|
||||
@ -977,7 +1024,7 @@ public class SydApiBaseFunction implements SydApi {
|
||||
|
||||
|
||||
protected static int[] toIntArray(List<Integer> list) {
|
||||
if (null == list || 0 == list.size()) {
|
||||
if (null == list || list.isEmpty()) {
|
||||
return new int[0];
|
||||
}
|
||||
int[] ia = new int[list.size()];
|
||||
@ -988,7 +1035,7 @@ public class SydApiBaseFunction implements SydApi {
|
||||
}
|
||||
|
||||
protected static boolean[] toBoolArray(List<Boolean> list) {
|
||||
if (null == list || 0 == list.size()) {
|
||||
if (null == list || list.isEmpty()) {
|
||||
return new boolean[0];
|
||||
}
|
||||
boolean[] ia = new boolean[list.size()];
|
||||
|
||||
Loading…
Reference in New Issue
Block a user