修改日志

This commit is contained in:
junj2.liang 2022-09-15 13:51:51 +08:00
parent 4e2f6b3ac4
commit f735244799
3 changed files with 99 additions and 14 deletions

View File

@ -1,8 +1,6 @@
package com.sunyard.sge.database; package com.sunyard.sge.database;
import com.sunyard.sge.database.pool.HsmLinkInfo; import com.sunyard.sge.database.pool.HsmLinkInfo;
import com.sunyard.sge.log.LogFactory;
import com.sunyard.sge.pool.CommWorker;
import racal.sunyard.main.SydApi4j; import racal.sunyard.main.SydApi4j;
import java.util.ArrayList; import java.util.ArrayList;
@ -61,13 +59,14 @@ public class SydApi4Database extends SydApiBaseFunction {
curDataGroup = new ArrayList<>(); curDataGroup = new ArrayList<>();
curKeyGroup = new ArrayList<>(); curKeyGroup = new ArrayList<>();
totalLen = 0;
} }
curDataGroup.add(data); curDataGroup.add(data);
curKeyGroup.add(iKeyIndex[i]); curKeyGroup.add(iKeyIndex[i]);
totalLen = data.length; totalLen += data.length;
} }
@ -120,12 +119,13 @@ public class SydApi4Database extends SydApiBaseFunction {
curDataGroup = new ArrayList<>(); curDataGroup = new ArrayList<>();
curKeyGroup = new ArrayList<>(); curKeyGroup = new ArrayList<>();
totalLen = 0;
} }
curDataGroup.add(data); curDataGroup.add(data);
curKeyGroup.add(iKeyIndex[i]); curKeyGroup.add(iKeyIndex[i]);
totalLen = data.length; totalLen += data.length;
} }
dataGroups.add(curDataGroup); dataGroups.add(curDataGroup);
@ -182,13 +182,14 @@ public class SydApi4Database extends SydApiBaseFunction {
curDataGroup = new ArrayList<>(); curDataGroup = new ArrayList<>();
curKeyGroup = new ArrayList<>(); curKeyGroup = new ArrayList<>();
curMacGroup = new ArrayList<>(); curMacGroup = new ArrayList<>();
totalLen = 0;
} }
curDataGroup.add(data); curDataGroup.add(data);
curKeyGroup.add(iKeyIndex[i]); curKeyGroup.add(iKeyIndex[i]);
curMacGroup.add(pcMac[i]); curMacGroup.add(pcMac[i]);
totalLen = data.length; totalLen += data.length;
} }
dataGroups.add(curDataGroup); dataGroups.add(curDataGroup);

View File

@ -183,7 +183,6 @@ public class SydApiLongLinkWrap implements SydApi {
if ( 0 == iKeyIndex.length ) { if ( 0 == iKeyIndex.length ) {
return new ArrayList<>(); return new ArrayList<>();
} }
// 将数据进行分组防止超长 // 将数据进行分组防止超长
List<List<byte[]>> dataGroups = new ArrayList<>(); List<List<byte[]>> dataGroups = new ArrayList<>();
List<List<Integer>> keyGroups = new ArrayList<>(); List<List<Integer>> keyGroups = new ArrayList<>();
@ -206,13 +205,14 @@ public class SydApiLongLinkWrap implements SydApi {
curDataGroup = new ArrayList<>(); curDataGroup = new ArrayList<>();
curKeyGroup = new ArrayList<>(); curKeyGroup = new ArrayList<>();
totalLen = 0;
} }
curDataGroup.add(data); curDataGroup.add(data);
curKeyGroup.add(iKeyIndex[i]); curKeyGroup.add(iKeyIndex[i]);
totalLen = data.length; totalLen += data.length;
} }
@ -259,7 +259,6 @@ public class SydApiLongLinkWrap implements SydApi {
if ( 0 == iKeyIndex.length ) { if ( 0 == iKeyIndex.length ) {
return new String[0]; return new String[0];
} }
// 将数据进行分组防止超长 // 将数据进行分组防止超长
List<List<byte[]>> dataGroups = new ArrayList<>(); List<List<byte[]>> dataGroups = new ArrayList<>();
List<List<Integer>> keyGroups = new ArrayList<>(); List<List<Integer>> keyGroups = new ArrayList<>();
@ -282,12 +281,13 @@ public class SydApiLongLinkWrap implements SydApi {
curDataGroup = new ArrayList<>(); curDataGroup = new ArrayList<>();
curKeyGroup = new ArrayList<>(); curKeyGroup = new ArrayList<>();
totalLen = 0;
} }
curDataGroup.add(data); curDataGroup.add(data);
curKeyGroup.add(iKeyIndex[i]); curKeyGroup.add(iKeyIndex[i]);
totalLen = data.length; totalLen += data.length;
} }
dataGroups.add(curDataGroup); dataGroups.add(curDataGroup);
@ -323,7 +323,6 @@ public class SydApiLongLinkWrap implements SydApi {
@Override @Override
public boolean[] SYD_SM4Mac_BatchData(int[] iKeyIndex, List<byte[]> pcData, String[] pcMac) { public boolean[] SYD_SM4Mac_BatchData(int[] iKeyIndex, List<byte[]> pcData, String[] pcMac) {
if ( null == iKeyIndex || null == pcData ) { if ( null == iKeyIndex || null == pcData ) {
throw new IllegalArgumentException("批量输入数据为 null"); throw new IllegalArgumentException("批量输入数据为 null");
} }
@ -336,7 +335,6 @@ public class SydApiLongLinkWrap implements SydApi {
return new boolean[0]; return new boolean[0];
} }
// 将数据进行分组防止超长 // 将数据进行分组防止超长
List<List<byte[]>> dataGroups = new ArrayList<>(); List<List<byte[]>> dataGroups = new ArrayList<>();
List<List<Integer>> keyGroups = new ArrayList<>(); List<List<Integer>> keyGroups = new ArrayList<>();
@ -364,13 +362,14 @@ public class SydApiLongLinkWrap implements SydApi {
curDataGroup = new ArrayList<>(); curDataGroup = new ArrayList<>();
curKeyGroup = new ArrayList<>(); curKeyGroup = new ArrayList<>();
curMacGroup = new ArrayList<>(); curMacGroup = new ArrayList<>();
totalLen = 0;
} }
curDataGroup.add(data); curDataGroup.add(data);
curKeyGroup.add(iKeyIndex[i]); curKeyGroup.add(iKeyIndex[i]);
curMacGroup.add(pcMac[i]); curMacGroup.add(pcMac[i]);
totalLen = data.length; totalLen += data.length;
} }
dataGroups.add(curDataGroup); dataGroups.add(curDataGroup);

View File

@ -63,8 +63,8 @@ public class BatchDataTest {
SydApiBuilder builder = new SydApiBuilder( SydApiBuilder builder = new SydApiBuilder(
new String[]{"192.168.1.129"}, new String[]{"192.168.1.129"},
new int[]{8889}, new int[]{8889},
10, 20,
15 30
); );
api = builder.build(); api = builder.build();
@ -104,6 +104,8 @@ public class BatchDataTest {
} }
} }
@Test @Test
public void batchSM4Case2() { public void batchSM4Case2() {
// 测试数据 // 测试数据
@ -117,6 +119,34 @@ public class BatchDataTest {
} }
} }
@Test
public void batchSM4Case3() {
// 密钥索引
int[] keyIdx = new int[]{0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2}; // 12
// 测试数据
List<byte[]> data = new ArrayList<>();
data.add(new byte[1024]);
data.add(new byte[1024]);
data.add(new byte[1024]);
data.add(new byte[1024]);
data.add(new byte[1024]);
data.add(new byte[1024]);
data.add(new byte[1024]);
data.add(new byte[1024]);
data.add(new byte[1024]);
data.add(new byte[1024]);
data.add(new byte[1024]);
data.add(new byte[1024]);
List<byte[]> encData = api.SYD_SM4_BatchData(keyIdx, data, Consts.ECB_ENC);
List<byte[]> orgData = api.SYD_SM4_BatchData(keyIdx, encData, Consts.ECB_DEC);
for (int i = 0; i < data.size(); i++) {
Assert.assertArrayEquals(orgData.get(i), data.get(i));
}
}
@Test @Test
public void batchSM4CaseZero() { public void batchSM4CaseZero() {
// 测试数据 // 测试数据
@ -157,6 +187,60 @@ public class BatchDataTest {
} }
} }
@Test
public void batchMACDataCase2() {
// 密钥索引
int[] keyIdx = new int[]{0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2}; // 12
// 测试数据
List<byte[]> data = new ArrayList<>();
data.add(new byte[1024]);
data.add(new byte[1024]);
data.add(new byte[1024]);
data.add(new byte[1024]);
data.add(new byte[1024]);
data.add(new byte[1024]);
data.add(new byte[1024]);
data.add(new byte[1024]);
data.add(new byte[1024]);
data.add(new byte[1024]);
data.add(new byte[1024]);
data.add(new byte[1024]);
String[] macs = api.SYD_SM4Mac_BatchData(keyIdx, data);
boolean[] checks = api.SYD_SM4Mac_BatchData(keyIdx, data, macs);
for (int i = 0; i < data.size(); i++) {
Assert.assertTrue(checks[i]);
}
}
@Test
public void batchMACData3() {
// 密钥索引
int[] keyIdx = new int[]{0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2}; // 12
// 测试数据
List<byte[]> data = new ArrayList<>();
data.add(new byte[1024]);
data.add(new byte[1024]);
data.add(new byte[1024]);
data.add(new byte[1024]);
data.add(new byte[1024]);
data.add(new byte[1024]);
data.add(new byte[1024]);
data.add(new byte[1024]);
data.add(new byte[1024]);
data.add(new byte[1024]);
data.add(new byte[1024]);
data.add(new byte[1024]);
String[] macs = api.SYD_SM4Mac_BatchData(keyIdx, data);
boolean[] checks = api.SYD_SM4Mac_BatchData(keyIdx, data, macs);
for (int i = 0; i < data.size(); i++) {
Assert.assertTrue(checks[i]);
}
}
@Test @Test
public void batchMACData() { public void batchMACData() {
// 测试数据 // 测试数据
@ -170,6 +254,7 @@ public class BatchDataTest {
} }
} }
@Test @Test
public void batchMACDataZero() { public void batchMACDataZero() {
// 测试数据 // 测试数据