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
@@ -0,0 +1,69 @@
|
||||
package component;
|
||||
|
||||
import encoding.*;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/*
|
||||
* @Author: Wang Feng
|
||||
* @Description:
|
||||
* @Version: 1.0.0
|
||||
* @Date: 20:21 2021/4/1
|
||||
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
|
||||
*/
|
||||
public class SignatureValueTest {
|
||||
@Test
|
||||
public void TestCreateSignatureValueByByteArray() throws ComponentException {
|
||||
byte[] buf={(byte)1, (byte)2, (byte)3, (byte)4, (byte)5, (byte)6, (byte)7, (byte)8};
|
||||
SignatureValue got=new SignatureValue(buf);
|
||||
System.out.println(Arrays.toString(got.getValue()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestCreateSignatureValueByBlock() throws EncoderException, ComponentException, BlockException {
|
||||
Encoder encoder=new Encoder();
|
||||
encoder.encoderReset(new SizeT(Encoder.MaxPacketSize),new SizeT(0));
|
||||
String str="/min/pku";
|
||||
IdentifierWrapper got=new IdentifierWrapper().createCommonIdentifierByString(str);
|
||||
System.out.println("type: "+got.getTlvType());
|
||||
got.wireEncode(encoder);
|
||||
byte[] rawBuf=encoder.getBuffer();
|
||||
System.out.println("buf: "+Arrays.toString(rawBuf));
|
||||
|
||||
byte[] a=new byte[4];
|
||||
System.arraycopy(rawBuf,12,a,0,4);
|
||||
Block block=new Block(new VlInt(200),new VlInt(4),a,true);
|
||||
SignatureValue gotValue=new SignatureValue(block);
|
||||
System.out.println("sv value: "+Arrays.toString(gotValue.getValue()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestSignatureValue_WireEncode() throws BlockException, ComponentException, EncoderException {
|
||||
Encoder encoder=new Encoder();
|
||||
encoder.encoderReset(new SizeT(Encoder.MaxPacketSize),new SizeT(0));
|
||||
String str="/min/pku";
|
||||
IdentifierWrapper got=new IdentifierWrapper().createCommonIdentifierByString(str);
|
||||
System.out.println("type: "+got.getTlvType());
|
||||
got.wireEncode(encoder);
|
||||
byte[] rawBuf=encoder.getBuffer();
|
||||
System.out.println("buf: "+Arrays.toString(rawBuf));
|
||||
|
||||
byte[] a=new byte[4];
|
||||
System.arraycopy(rawBuf,12,a,0,4);
|
||||
Block block=new Block(new VlInt(200),new VlInt(4),a,true);
|
||||
SignatureValue gotValue=new SignatureValue(block);
|
||||
System.out.println("sv value: "+Arrays.toString(gotValue.getValue()));
|
||||
|
||||
encoder.encoderReset(new SizeT(Encoder.MaxPacketSize),new SizeT(0));
|
||||
gotValue.wireEncode(encoder);
|
||||
System.out.println("all: "+Arrays.toString(encoder.getBuffer()));
|
||||
byte[] bytes=encoder.getBuffer();
|
||||
Block block1=new Block(bytes,false);
|
||||
SignatureValue newSig=new SignatureValue(block1);
|
||||
System.out.println("new value: "+Arrays.toString(newSig.getValue()));
|
||||
encoder.encoderReset(new SizeT(Encoder.MaxPacketSize),new SizeT(0));
|
||||
newSig.wireEncode(encoder);
|
||||
System.out.println("new all: "+Arrays.toString(encoder.getBuffer()));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user