Beispiel #1
0
func (codecType stringCodecType) NewCodec(r io.Reader, w io.Writer) Codec {
	return stringCodec{
		codecType.Spliter,
		binary.NewReader(r),
		binary.NewWriter(w),
	}
}
Beispiel #2
0
// Do DH64 key exchange and return a RC4 writer.
func conn_init(conn net.Conn) (*binary.Writer, *binary.Reader, error) {
	var (
		writer = binary.NewWriter(conn)
		reader = binary.NewReader(conn)
	)

	rand.Seed(time.Now().UnixNano())

	privateKey, publicKey := dh64.KeyPair()
	log.Print("client public key: ", publicKey)

	writer.WriteUint64LE(publicKey)
	if writer.Error() != nil {
		return nil, nil, writer.Error()
	}
	serverPublicKey := reader.ReadUint64LE()
	if reader.Error() != nil {
		return nil, nil, reader.Error()
	}
	log.Print("server public key: ", serverPublicKey)

	secert := dh64.Secret(privateKey, serverPublicKey)
	log.Print("secert: ", secert)

	key := make([]byte, 8)
	binary.PutUint64LE(key, secert)
	rc4stream, err := rc4.NewCipher(key)
	if err != nil {
		return nil, nil, err
	}
	log.Print("key: ", hex.EncodeToString(key))

	writer = binary.NewWriter(cipher.StreamWriter{
		W: conn,
		S: rc4stream,
	})
	return writer, reader, nil
}
Beispiel #3
0
func (codecType stringCodecType) NewEncoder(w io.Writer) Encoder {
	return stringEncoder{
		codecType.Spliter,
		binary.NewWriter(w),
	}
}
Beispiel #4
0
func (_ selfCodecType) NewEncoder(w io.Writer) Encoder {
	return selfEncoder{
		binary.NewWriter(w),
	}
}
Beispiel #5
0
func (codecType bytesCodecType) NewEncoder(w io.Writer) link.Encoder {
	return bytesEncoder{
		codecType.Spliter,
		binary.NewWriter(w),
	}
}
Beispiel #6
0
func (_ selfCodecType) NewCodec(r io.Reader, w io.Writer) Codec {
	return selfCodec{
		binary.NewReader(r),
		binary.NewWriter(w),
	}
}
Beispiel #7
0
func (_ selfCodecType) NewStreamCodec(r *bufio.Reader, w *bufio.Writer) StreamCodec {
	return selfStreamCodec{
		binary.NewReader(r),
		binary.NewWriter(w),
	}
}
Beispiel #8
0
func (_ selfCodecType) NewPacketCodec() PacketCodec {
	codec := &selfPacketCodec{}
	codec.r = binary.NewReader(&codec.rbuf)
	codec.w = binary.NewWriter(&codec.wbuf)
	return codec
}