Exemplo n.º 1
0
func WriteProtobuf(conn *transport.Conn, message *proto.ClientToServer) error {
	unpadMsg, err := protobuf.Marshal(message)
	if err != nil {
		return err
	}
	_, err = conn.WriteFrame(proto.Pad(unpadMsg, proto.SERVER_MESSAGE_SIZE))
	return err
}
Exemplo n.º 2
0
func writeProtobuf(conn *transport.Conn, outBuf []byte, message *proto.ClientToServer, t *testing.T) {
	unpadMsg, err := protobuf.Marshal(message)
	handleError(err, t)

	padMsg := proto.Pad(unpadMsg, proto.SERVER_MESSAGE_SIZE)
	copy(outBuf, padMsg)

	conn.WriteFrame(outBuf[:proto.SERVER_MESSAGE_SIZE])
}
Exemplo n.º 3
0
func (server *Server) writeProtobuf(conn *transport.Conn, outBuf []byte, message *proto.ServerToClient) error {
	unpadMsg, err := protobuf.Marshal(message)
	if err != nil {
		return err
	}
	padMsg := proto.Pad(unpadMsg, proto.SERVER_MESSAGE_SIZE)
	copy(outBuf, padMsg)
	conn.WriteFrame(outBuf[:proto.SERVER_MESSAGE_SIZE])
	return nil
}
Exemplo n.º 4
0
func EncryptAuthFirst(message []byte, skAuth *[32]byte, userKey *[32]byte, prt ProfileRatchet) ([]byte, *ratchet.Ratchet, error) {
	ratch := &ratchet.Ratchet{
		FillAuth:  FillAuthWith(skAuth),
		CheckAuth: CheckAuthWith(prt),
	}

	out := append([]byte{}, (*userKey)[:]...)
	paddedMsg := proto.Pad(message, proto.MAX_MESSAGE_SIZE-ENCRYPT_FIRST_ADDED_LEN-len(out))
	out = ratch.EncryptFirst(out, paddedMsg, userKey)

	return out, ratch, nil
}
Exemplo n.º 5
0
func EncryptAuth(message []byte, ratch *ratchet.Ratchet) ([]byte, *ratchet.Ratchet, error) {
	paddedMsg := proto.Pad(message, proto.MAX_MESSAGE_SIZE-ENCRYPT_ADDED_LEN)
	out := ratch.Encrypt(nil, paddedMsg)

	return out, ratch, nil
}