From e7c5de0db8307dd7fe6c41625997fdfb01af6982 Mon Sep 17 00:00:00 2001 From: Wiktor Garbacz Date: Wed, 28 Feb 2024 06:00:44 -0800 Subject: [PATCH] Fix `sapi::v::Proto::FromMessage` PiperOrigin-RevId: 611076146 Change-Id: I60edf17b83e0ded8ed62aeebba45b6401bac8e53 --- sandboxed_api/var_proto.h | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/sandboxed_api/var_proto.h b/sandboxed_api/var_proto.h index 2f1d8aa8..0f86ca3d 100644 --- a/sandboxed_api/var_proto.h +++ b/sandboxed_api/var_proto.h @@ -42,16 +42,26 @@ namespace sapi::v { template class Proto : public Var { public: + class PrivateToken { + private: + explicit PrivateToken() = default; + friend class Proto; + }; + static_assert(std::is_base_of::value, "Template argument must be a proto message"); + Proto(PrivateToken, std::vector data) + : wrapped_var_(std::move(data)) {} + ABSL_DEPRECATED("Use Proto<>::FromMessage() instead") explicit Proto(const T& proto) : wrapped_var_(SerializeProto(proto).value()) {} static absl::StatusOr> FromMessage(const T& proto) { SAPI_ASSIGN_OR_RETURN(std::vector len_val, SerializeProto(proto)); - return absl::StatusOr>(absl::in_place, proto); + return absl::StatusOr>(absl::in_place, PrivateToken{}, + std::move(len_val)); } size_t GetSize() const final { return wrapped_var_.GetSize(); } @@ -105,10 +115,6 @@ class Proto : public Var { } private: - friend class absl::StatusOr>; - - explicit Proto(std::vector data) : wrapped_var_(std::move(data)) {} - // The management of reading/writing the data to the sandboxee is handled by // the LenVal class. LenVal wrapped_var_;