This commit is contained in:
junj2.liang 2022-08-05 10:47:09 +08:00
parent dd7bd5577a
commit f7e1103e93
3 changed files with 20 additions and 10 deletions

View File

@ -26,17 +26,11 @@ public interface SydApi {
static void SYD_SetLogConfig( static void SYD_SetLogConfig(
String pcLogPath, String pcLogPath,
int iLogLevel) { int iLogLevel) {
Logger log = LogFactory.getLogger(); if (pcLogPath==null||iLogLevel<0||iLogLevel>3){
try { throw new IllegalArgumentException("地址不能为空且等级范围为0到3");
if (iLogLevel<0||iLogLevel>3){
throw new IllegalArgumentException("IllegalArgumentException");
} }
Logger logger = LogFactory.createLogger(pcLogPath, iLogLevel); Logger logger = LogFactory.createLogger(pcLogPath, iLogLevel);
SydApi4j.setLogger( logger ); SydApi4j.setLogger( logger );
}
catch (IllegalArgumentException e){
log.error(e.getMessage());
}
} }
/** /**

View File

@ -52,6 +52,9 @@ public class SydApi4Database implements SydApi {
if (LogFactory.iLogLevel==3) { if (LogFactory.iLogLevel==3) {
log.debug("SYD_SM3_Hash_ShortData方法接收参数pcData{}", Arrays.toString(pcData)); log.debug("SYD_SM3_Hash_ShortData方法接收参数pcData{}", Arrays.toString(pcData));
} }
if (pcData.length==0){
throw new SydApiException(-19);
}
if (null == this.hsms || this.hsms.length < 1) { if (null == this.hsms || this.hsms.length < 1) {
throw new SydApiException(-1); throw new SydApiException(-1);
} }
@ -78,6 +81,7 @@ public class SydApi4Database implements SydApi {
if (LogFactory.iLogLevel==3) { if (LogFactory.iLogLevel==3) {
log.debug("SYD_SM3_Hash_LongData方法接收参数pcData{},iPkgNum{},pcProcData{}", Arrays.toString(pcData), iPkgNum, pcProcData); log.debug("SYD_SM3_Hash_LongData方法接收参数pcData{},iPkgNum{},pcProcData{}", Arrays.toString(pcData), iPkgNum, pcProcData);
} }
if (null == this.hsms || this.hsms.length < 1) { if (null == this.hsms || this.hsms.length < 1) {
throw new SydApiException(-1); throw new SydApiException(-1);
} }
@ -114,6 +118,9 @@ public class SydApi4Database implements SydApi {
if (LogFactory.iLogLevel==3) { if (LogFactory.iLogLevel==3) {
log.debug("SYD_SM4_ShortData方法接收参数iKeyIndex{},pcData{},iFlag{}", iKeyIndex, Arrays.toString(pcData), iFlag); log.debug("SYD_SM4_ShortData方法接收参数iKeyIndex{},pcData{},iFlag{}", iKeyIndex, Arrays.toString(pcData), iFlag);
} }
if (iFlag==Consts.ECB_DEC&&null==pcData||pcData.length==0){
throw new SydApiException(19);
}
if (null == this.hsms || this.hsms.length < 1) { if (null == this.hsms || this.hsms.length < 1) {
throw new SydApiException(-1); throw new SydApiException(-1);
} }
@ -152,6 +159,13 @@ public class SydApi4Database implements SydApi {
if (LogFactory.iLogLevel==3) { if (LogFactory.iLogLevel==3) {
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 (iFlag==Consts.ECB_DEC){
for (byte[] pcdata:pcData){
if (null==pcData||pcdata.length==0) {
throw new SydApiException(19);
}
}
}
if (null == this.hsms || this.hsms.length < 1) { if (null == this.hsms || this.hsms.length < 1) {
throw new SydApiException(-1); throw new SydApiException(-1);
} }
@ -186,10 +200,12 @@ public class SydApi4Database 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 (null == this.hsms || this.hsms.length < 1) { if (null == this.hsms || this.hsms.length < 1) {
throw new SydApiException(-1); throw new SydApiException(-1);
} }
String keyIndex = String.format("%08d", iKeyIndex); String keyIndex = String.format("%08d", iKeyIndex);
SydApiException le = null; SydApiException le = null;

View File

@ -16,7 +16,7 @@ public class Sample
public static void main(String[] args) { public static void main(String[] args) {
// 路径要以 / \\ 结尾表示目录 // 路径要以 / \\ 结尾表示目录
SydApi.SYD_SetLogConfig("./logs/",2); SydApi.SYD_SetLogConfig("./logs/",3);
Logger log = LogFactory.getLogger(); Logger log = LogFactory.getLogger();
log.info("start"); log.info("start");