mirror of
https://gitee.com/willfree/min-dev-java.git
synced 2026-10-04 19:42:01 +08:00
add test: SignatureValueTest
This commit is contained in:
1 parent
c45667cc8d
commit
deafbc7574
2 files changed
+108
-45
No files matched your search
@@ -19,8 +19,10 @@ public class SignatureValue implements TlvComponentBase, IEncodingAble {
|
||||
* 根据签名值字节数组创建一个 SignatureValue
|
||||
* @param value
|
||||
*/
|
||||
public SignatureValue(byte[] value){
|
||||
this.buildSignatureValueByByteArray(value);
|
||||
public SignatureValue(byte[] value) throws ComponentException {
|
||||
if(!this.buildSignatureValueByByteArray(value)){
|
||||
throw new ComponentException("Signature(byte[] value): value invalid");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -28,7 +30,9 @@ public class SignatureValue implements TlvComponentBase, IEncodingAble {
|
||||
* @param block
|
||||
*/
|
||||
public SignatureValue(Block block) throws ComponentException {
|
||||
this.buildSignatureValueByBlock(block);
|
||||
if(!this.buildSignatureValueByBlock(block)){
|
||||
throw new ComponentException("Signature(Block block): block invalid");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -66,42 +70,33 @@ public class SignatureValue implements TlvComponentBase, IEncodingAble {
|
||||
*/
|
||||
@Override
|
||||
public int wireEncode(Encoder encoder) throws ComponentException {
|
||||
int totalLength=0;
|
||||
// 编码 TLV-VALUE
|
||||
int tmplen= 0;
|
||||
try {
|
||||
tmplen = encoder.prependByteArray(this.value,new SizeT(this.value.length));
|
||||
int totalLength = 0;
|
||||
// 编码 TLV-VALUE
|
||||
int tmplen = encoder.prependByteArray(this.value, new SizeT(this.value.length));
|
||||
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.TlvSignatureValue));
|
||||
if (tmplen <= 0) {
|
||||
return -1;
|
||||
}
|
||||
totalLength += tmplen;
|
||||
|
||||
return totalLength;
|
||||
} catch (EncoderException e) {
|
||||
throw new ComponentException("SignatureValue.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("SignatureValue.wireEncode: "+e.getMessage());
|
||||
}
|
||||
if(tmplen<=0){
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
// 编码 TLV-TYPE
|
||||
try {
|
||||
tmplen=encoder.prependVarNumber(new VlInt(TLV.TlvSignatureValue));
|
||||
} catch (EncoderException e) {
|
||||
throw new ComponentException("SignatureValue.wireEncode: "+e.getMessage());
|
||||
}
|
||||
if(tmplen<=0){
|
||||
return -1;
|
||||
}
|
||||
totalLength+=tmplen;
|
||||
|
||||
return totalLength;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -111,19 +106,18 @@ public class SignatureValue implements TlvComponentBase, IEncodingAble {
|
||||
*/
|
||||
@Override
|
||||
public boolean wireDecode(Block block) throws ComponentException {
|
||||
// 检查 Type 是否正确
|
||||
if(!TLV.expectType(block.getType(),new VlInt(TLV.TlvSignatureValue))){
|
||||
return false;
|
||||
}
|
||||
|
||||
int len= 0;
|
||||
try {
|
||||
len = block.getLength().getVlIntValue2Int();
|
||||
// 检查 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;
|
||||
} catch (VlIntException e) {
|
||||
throw new ComponentException("SignatureValue.wireDecode: "+e.getMessage());
|
||||
}
|
||||
this.value=new byte[len];
|
||||
System.arraycopy(block.getValue(),0,this.value,0,len);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user