add test: SignatureTypeTest

This commit is contained in:
free will committed 2021-03-31 19:07:56 +08:00
1 parent fafde2b015
commit 025d2f1c62
2 files changed
+114 -47

No files matched your search

+38 -47
View File
@@ -108,43 +108,35 @@ public class SignatureType implements TlvComponentBase, IEncodingAble {
*/
@Override
public int wireEncode(Encoder encoder) throws ComponentException {
int totalLength=0;
// 编码 TLV-VALUE
int tmplen= 0;
try {
tmplen = encoder.prependNonNegativeInteger(this.value.getSignatureAlgorithm());
int totalLength = 0;
// 编码 TLV-VALUE
int tmplen = encoder.prependNonNegativeInteger(this.value.getSignatureAlgorithm());
if (tmplen <= 0) {
return -1;
}
totalLength += tmplen;
// 编码 TLV-LENGTH
tmplen = encoder.prependVarNumber(new VlInt(totalLength));
if (tmplen <= 0) {
return -1;
}
totalLength += tmplen;
// 编码 TLV-TYPE
tmplen = encoder.prependVarNumber(new VlInt(TLV.TlvSignatureType));
if (tmplen <= 0) {
return -1;
}
totalLength += tmplen;
return totalLength;
} catch (EncoderException e) {
throw new ComponentException("SignatureType.wireEncode: "+e.getMessage());
}
if(tmplen<=0){
return -1;
}
totalLength+=tmplen;
// 编码 TLV-LENGTH
try {
tmplen=encoder.prependVarNumber(new VlInt(totalLength));
} catch (EncoderException e) {
throw new ComponentException("SignatureType.wireEncode: "+e.getMessage());
}
if(tmplen<=0){
return -1;
}
totalLength+=tmplen;
// 编码 TLV-TYPE
try {
tmplen=encoder.prependVarNumber(new VlInt(TLV.TlvSignatureType));
} catch (EncoderException e) {
throw new ComponentException("SignatureType.wireEncode: "+e.getMessage());
}
if(tmplen<=0){
return -1;
}
totalLength+=tmplen;
return totalLength;
}
/**
@@ -154,23 +146,22 @@ public class SignatureType implements TlvComponentBase, IEncodingAble {
*/
@Override
public boolean wireDecode(Block block) throws ComponentException {
// 检查 Type 是否正确
if(!TLV.expectType(block.getType(),new VlInt(TLV.TlvSignatureType))){
return false;
}
// 尝试从 TLE-VALUE 中读取出一个非负整数
long result= 0;
try {
result = TLV.readNonNegativeInteger(block.getValue(),0,block.getLength().getVlIntValue2Int());
// 检查 Type 是否正确
if (!TLV.expectType(block.getType(), new VlInt(TLV.TlvSignatureType))) {
return false;
}
// 尝试从 TLE-VALUE 中读取出一个非负整数
long result = TLV.readNonNegativeInteger(block.getValue(), 0, block.getLength().getVlIntValue2Int());
if (result < 0) {
return false;
}
this.value = new SignatureAlgorithm((int) result);
return true;
} catch (TLVException | VlIntException e) {
throw new ComponentException("SignatureType.wireDecode: " + e.getMessage());
}
if(result<0){
return false;
}
this.value=new SignatureAlgorithm((int)result);
return true;
}
}