mirror of
https://gitee.com/willfree/min-dev-java.git
synced 2026-10-04 19:42:01 +08:00
add test: SignatureTypeTest
This commit is contained in:
1 parent
fafde2b015
commit
025d2f1c62
2 files changed
+114
-47
No files matched your search
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user