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
@@ -0,0 +1,76 @@
|
||||
package component;
|
||||
|
||||
import encoding.*;
|
||||
import org.junit.Test;
|
||||
import packet.PacketException;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/*
|
||||
* @Author: Wang Feng
|
||||
* @Description:
|
||||
* @Version: 1.0.0
|
||||
* @Date: 10:48 2021/3/31
|
||||
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
|
||||
*/
|
||||
public class SignatureTypeTest {
|
||||
@Test
|
||||
public void TestCreateSignatureTypeByBlock() throws EncoderException, ComponentException, BlockException {
|
||||
Encoder encoder=new Encoder();
|
||||
encoder.encoderReset(new SizeT(Encoder.MaxPacketSize),new SizeT(0));
|
||||
String str="/min/pkusz";
|
||||
IdentifierWrapper got=new IdentifierWrapper().createCommonIdentifierByString(str);
|
||||
System.out.println("type: "+got.getTlvType().toString());
|
||||
got.wireEncode(encoder);
|
||||
byte[] rawBuf=encoder.getBuffer();
|
||||
System.out.println("buf: "+ Arrays.toString(rawBuf));
|
||||
byte[] buf2=new byte[4];
|
||||
System.arraycopy(rawBuf,14,buf2,0,4);
|
||||
Block block=new Block(new VlInt(202),new VlInt(4),buf2,true);
|
||||
System.out.println("block length: "+block.getLength());
|
||||
SignatureType gotContent=new SignatureType(block);
|
||||
System.out.println("sigtype: "+gotContent.getValue().getSignatureAlgorithm());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestCreateSignatureTypeByValue() throws PacketException, EncoderException, BlockException, ComponentException {
|
||||
SignatureAlgorithm value=new SignatureAlgorithm(0);
|
||||
SignatureType got=new SignatureType(value);
|
||||
System.out.println(got.getValue().getSignatureAlgorithm());
|
||||
Block rawBlock=new SelfEncodingBase().selfWireEncode(got);
|
||||
System.out.println(rawBlock.getType()+" "+rawBlock.getLength()+" "+Arrays.toString(rawBlock.getValue()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestSignatureType_WireEncode() throws PacketException, EncoderException, BlockException, ComponentException {
|
||||
SignatureAlgorithm value=new SignatureAlgorithm(0);
|
||||
SignatureType got=new SignatureType(value);
|
||||
System.out.println(got.getValue().getSignatureAlgorithm());
|
||||
Block rawBlock=new SelfEncodingBase().selfWireEncode(got);
|
||||
System.out.println(rawBlock.getType()+" "+rawBlock.getLength()+" "+Arrays.toString(rawBlock.getValue()));
|
||||
Encoder encoder=new Encoder();
|
||||
encoder.encoderReset(new SizeT(Encoder.MaxPacketSize),new SizeT(0));
|
||||
got.wireEncode(encoder);
|
||||
byte[] gotBuf=encoder.getBuffer();
|
||||
System.out.println(Arrays.toString(gotBuf));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestCreateSignatureTypeByValue2() throws PacketException, EncoderException, BlockException, ComponentException {
|
||||
SignatureAlgorithm value=new SignatureAlgorithm(0);
|
||||
SignatureType got=new SignatureType(value);
|
||||
System.out.println(got.getValue().getSignatureAlgorithm());
|
||||
Block rawBlock=new SelfEncodingBase().selfWireEncode(got);
|
||||
System.out.println(rawBlock.getType()+" "+rawBlock.getLength()+" "+Arrays.toString(rawBlock.getValue()));
|
||||
Encoder encoder=new Encoder();
|
||||
encoder.encoderReset(new SizeT(Encoder.MaxPacketSize),new SizeT(0));
|
||||
got.wireEncode(encoder);
|
||||
byte[] gotBuf=encoder.getBuffer();
|
||||
System.out.println(Arrays.toString(gotBuf));
|
||||
SignatureType newSig=new SignatureType();
|
||||
newSig.wireDecode(rawBlock);
|
||||
System.out.println(newSig.getValue().getSignatureAlgorithm());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user