入参检查

This commit is contained in:
cheney 2025-07-10 20:29:11 +08:00
parent 0e5fb0f56f
commit fdbcf5d43b

View File

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