Exemple #1
0
func TestPacketSizes(t *testing.T) {
	asnPacket := packet{
		testRawPacket.Timestamp,
		testRawPacket.Counter,
		testRawPacket.Chunk[:],
	}
	packet, err := asn1.Marshal(asnPacket)
	checkError(t, err)

	jpacket, err := json.Marshal(asnPacket)
	checkError(t, err)

	jout, err := crypt.Encrypt(jpacket, testPub, signer)
	checkError(t, err)

	buf := &bytes.Buffer{}
	enc := gob.NewEncoder(buf)
	err = enc.Encode(asnPacket)
	checkError(t, err)
	gpacket := buf.Bytes()

	gout, err := crypt.Encrypt(gpacket, testPub, signer)
	checkError(t, err)

	fmt.Println("              ASN.1 packet length:", len(packet))
	fmt.Println("               JSON packet length:", len(jpacket))
	fmt.Println("                Gob packet length:", len(gpacket))
	fmt.Println("Signed and encrypted ASN.1 length:", len(testPacket))
	fmt.Println(" Signed and encrypted JSON length:", len(jout))
	fmt.Println("  Signed and encrypted gob length:", len(gout))
}
Exemple #2
0
// SerialiseWire packs and encrypts a packet for transmission on the wire.
func SerialiseWire(p *Packet, peer []byte, signer *rsa.PrivateKey) ([]byte, error) {
	packet := packet{
		Timestamp: p.Timestamp,
		Counter:   p.Counter,
		Chunk:     p.Chunk[:],
	}
	out, err := asn1.Marshal(packet)
	if err != nil {
		return nil, err
	}

	return crypt.Encrypt(out, peer, signer)
}