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 }
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]) }
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 }
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 }
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 }