给验签函数增加布尔类型返回值

This commit is contained in:
free will
2021-08-05 11:57:46 +08:00
parent a6cd910d00
commit cefa3f431a
2 changed files with 17 additions and 8 deletions
+8 -8
View File
@@ -265,7 +265,7 @@ public class KeyChain {
* @param minPacket
* @throws Exception
*/
public void verify(MINPacket minPacket) throws Exception{
public boolean verify(MINPacket minPacket) throws Exception{
// 提取签名区的第一个签名进行验证(认为签名区的第一个签名为包的签名,包含标识区和只读区签名)
Signature signature = minPacket.signatureField.getSignature(0);
// TODO 使用临时方法,待更新
@@ -277,7 +277,7 @@ public class KeyChain {
}
byte[] rawData = getIdentifierAndReadOnlyValueFromPacket(minPacket);
identity.verify(rawData, signature.getSigValue().getValue());
return identity.verify(rawData, signature.getSigValue().getValue());
}
/**
@@ -285,9 +285,9 @@ public class KeyChain {
* @param packet
* @throws Exception
*/
public void verifyCPacket(CPacket packet) throws Exception{
public boolean verifyCPacket(CPacket packet) throws Exception{
packet.fillDataToFields();
verify(packet.minPacket);
return verify(packet.minPacket);
}
/**
@@ -295,9 +295,9 @@ public class KeyChain {
* @param interest
* @throws Exception
*/
public void verifyInterest(Interest interest) throws Exception{
public boolean verifyInterest(Interest interest) throws Exception{
interest.fillDataToFields();
verify(interest.minPacket);
return verify(interest.minPacket);
}
/**
@@ -305,9 +305,9 @@ public class KeyChain {
* @param data
* @throws Exception
*/
public void verifyData(Data data) throws Exception{
public boolean verifyData(Data data) throws Exception{
data.fillDataToFields();
verify(data.minPacket);
return verify(data.minPacket);
}
/**
+9
View File
@@ -21,6 +21,7 @@ import packet.Data;
import packet.Interest;
import packet.MINPacket;
import java.util.Arrays;
import java.util.HashMap;
import java.util.concurrent.ConcurrentHashMap;
@@ -163,7 +164,15 @@ public class KeyChainTest {
// 正常测试签名与验签
System.out.println("raw interest: "+ Arrays.toString(interest.minPacket.signatureField
.getSignature(0).getSigValue().getValue()));
System.out.println("raw interest: "+ new String(interest.minPacket.signatureField
.getSignature(0).getSigValue().getValue()));
keyChain.signInterest(interest);
System.out.println("signed interest: "+ Arrays.toString(interest.minPacket.signatureField
.getSignature(0).getSigValue().getValue()));
System.out.println("signed interest: "+ new String(interest.minPacket.signatureField
.getSignature(0).getSigValue().getValue()));
keyChain.verifyInterest(interest);
}catch (Exception ex){
LoggerHelper.info(ex.getMessage());