mirror of
https://gitee.com/willfree/min-dev-java.git
synced 2026-10-04 19:42:01 +08:00
finished component: SignatureValue & writing SignatureType
This commit is contained in:
1 parent
5d8bc3fd85
commit
0bd1715293
2 files changed
+155
No files matched your search
@@ -0,0 +1,44 @@
|
||||
package component;
|
||||
|
||||
import encoding.Block;
|
||||
import encoding.Encoder;
|
||||
import encoding.IEncodingAble;
|
||||
|
||||
/*
|
||||
* @Author: Wang Feng
|
||||
* @Description: 表示一个签名的类型
|
||||
// 1. 格式如下:
|
||||
// SignatureType = SIGNATURE-TYPE-TYPE TLV-LENGTH <NonNegativeInteger>
|
||||
// 2. 详情参见:http://gitea.qjm253.cn/PKUSZ-future-network-lab/minlib/src/branch/master/docs/PacketFormat.md#4-signature
|
||||
* @Version: 1.0.0
|
||||
* @Date: 21:38 2021/3/12
|
||||
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
|
||||
*/
|
||||
|
||||
class SignatureTypeValue{
|
||||
public long getSignatureTypeValue() {
|
||||
return signatureTypeValue;
|
||||
}
|
||||
|
||||
public void setSignatureTypeValue(long signatureTypeValue) {
|
||||
this.signatureTypeValue = signatureTypeValue;
|
||||
}
|
||||
|
||||
private long signatureTypeValue;
|
||||
public SignatureTypeValue(long signatureTypeValue){
|
||||
this.signatureTypeValue=signatureTypeValue;
|
||||
}
|
||||
}
|
||||
public class SignatureType implements TlvComponentBase, IEncodingAble {
|
||||
// private SignatureAlgorithm value;
|
||||
|
||||
@Override
|
||||
public int wireEncode(Encoder encoder) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean wireDecode(Block block) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
package component;
|
||||
|
||||
import encoding.*;
|
||||
|
||||
/*
|
||||
* @Author: Wang Feng
|
||||
* @Description: 表示一个签名值 TLV
|
||||
// 1. 格式如下:
|
||||
// SignatureValue = 200 TLV-LENGTH *OCTET
|
||||
// 2. 详情参见:http://gitea.qjm253.cn/PKUSZ-future-network-lab/minlib/src/branch/master/docs/PacketFormat.md#4-signature
|
||||
* @Version: 1.0.0
|
||||
* @Date: 21:45 2021/3/12
|
||||
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
|
||||
*/
|
||||
public class SignatureValue implements TlvComponentBase, IEncodingAble {
|
||||
private byte[] value;
|
||||
|
||||
/**
|
||||
* 根据签名值字节数组创建一个 SignatureValue
|
||||
* @param value
|
||||
*/
|
||||
public SignatureValue(byte[] value){
|
||||
this.buildSignatureValueByByteArray(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 TLV Block 创建一个 SignatureValue
|
||||
* @param block
|
||||
*/
|
||||
public SignatureValue(Block block){
|
||||
this.buildSignatureValueByBlock(block);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据签名值字节数组初始化一个 SignatureValue
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
public boolean buildSignatureValueByByteArray(byte[] value){
|
||||
this.value=new byte[value.length];
|
||||
System.arraycopy(value,0,this.value,0,value.length);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 TLV Block 初始化一个 SignatureValue
|
||||
* @param block
|
||||
* @return
|
||||
*/
|
||||
public boolean buildSignatureValueByBlock(Block block){
|
||||
return this.wireDecode(block);
|
||||
}
|
||||
|
||||
/**
|
||||
* 得到签名值的字节数组
|
||||
* @return
|
||||
*/
|
||||
public byte[] getValue(){
|
||||
return this.value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 对 SignatureValue 进行线速编码为TLV
|
||||
* @param encoder
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int wireEncode(Encoder encoder) {
|
||||
int totalLength=0;
|
||||
// 编码 TLV-VALUE
|
||||
int tmplen=encoder.prependByteArray(this.value,new SizeT(this.value.length));
|
||||
if(tmplen<=0){
|
||||
return 0;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
// 编码 TLV-LENGTH
|
||||
tmplen=encoder.prependVarNumber(new VlInt(totalLength));
|
||||
if(tmplen<=0){
|
||||
return 0;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
// 编码 TLV-TYPE
|
||||
tmplen=encoder.prependVarNumber(new VlInt(TLV.TlvSignatureValue));
|
||||
if(tmplen<=0){
|
||||
return 0;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
return totalLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从 TLV Block 中解码出一个 SignatureValue
|
||||
* @param block
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean wireDecode(Block block) {
|
||||
// 检查 Type 是否正确
|
||||
if(!TLV.expectType(block.getType(),new VlInt(TLV.TlvSignatureValue))){
|
||||
return false;
|
||||
}
|
||||
|
||||
int len=block.getLength().getVlIntValue2Int();
|
||||
this.value=new byte[len];
|
||||
System.arraycopy(block.getValue(),0,this.value,0,len);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user