1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369
|
diff --git a/BUILD.gn b/BUILD.gn
index 2f929064ff924..55152038d3c19 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -106,7 +106,6 @@ if (is_chromeos_ash) {
"src/prng/chacha_prng_util.cc",
"src/prng/single_thread_chacha_prng.cc",
"src/relinearization_key.cc",
- "src/statusor.cc",
]
public_deps = [
":serialization_proto",
@@ -163,7 +162,6 @@ if (is_chromeos_ash) {
"src/relinearization_key_test.cc",
"src/sample_error_test.cc",
"src/status_macros_test.cc",
- "src/statusor_test.cc",
"src/symmetric_encryption_test.cc",
"src/symmetric_encryption_with_prng_test.cc",
"src/testing/coefficient_polynomial_ciphertext_test.cc",
diff --git a/patches/0006-Quit-using-ValueOrDie.patch b/patches/0006-Quit-using-ValueOrDie.patch
new file mode 100644
index 0000000000000..e69de29bb2d1d
diff --git a/src/montgomery_test.cc b/src/montgomery_test.cc
index 2d952ddfbdad4..97444fc6c15c2 100644
--- a/src/montgomery_test.cc
+++ b/src/montgomery_test.cc
@@ -768,7 +768,7 @@ TYPED_TEST(MontgomeryTest, BatchOperations) {
std::vector<TypeParam> expected_add, expected_sub, expected_mul;
TypeParam scalar =
TypeParam::ImportRandom(prng.get(), modulus_params.get())
- .ValueOrDie();
+ .value();
auto scalar_constants_tuple = scalar.GetConstant(modulus_params.get());
auto scalar_constant = std::get<0>(scalar_constants_tuple);
auto scalar_constant_barrett = std::get<1>(scalar_constants_tuple);
@@ -776,9 +776,9 @@ TYPED_TEST(MontgomeryTest, BatchOperations) {
expected_mul_scalar;
for (size_t i = 0; i < length; i++) {
a.push_back(TypeParam::ImportRandom(prng.get(), modulus_params.get())
- .ValueOrDie());
+ .value());
b.push_back(TypeParam::ImportRandom(prng.get(), modulus_params.get())
- .ValueOrDie());
+ .value());
auto constants_tuple = b[i].GetConstant(modulus_params.get());
auto constant = std::get<0>(constants_tuple);
auto constant_barrett = std::get<1>(constants_tuple);
diff --git a/src/polynomial_test.cc b/src/polynomial_test.cc
index 6d5112e67c6b0..e246788d09bcc 100644
--- a/src/polynomial_test.cc
+++ b/src/polynomial_test.cc
@@ -55,7 +55,7 @@ template <typename Prng>
class PolynomialTest : public ::testing::Test {
protected:
PolynomialTest()
- : params14_(uint_m::Params::Create(rlwe::kNewhopeModulus).ValueOrDie()),
+ : params14_(uint_m::Params::Create(rlwe::kNewhopeModulus).value()),
zero_(uint_m::ImportZero(params14_.get())) {}
void SetUp() override { srand(0); }
@@ -98,7 +98,7 @@ class PolynomialTest : public ::testing::Test {
}
std::unique_ptr<Prng> MakePrng(absl::string_view seed) {
- auto prng = Prng::Create(seed.substr(0, Prng::SeedLength())).ValueOrDie();
+ auto prng = Prng::Create(seed.substr(0, Prng::SeedLength())).value();
return prng;
}
diff --git a/src/status_macros.h b/src/status_macros.h
index d297bfe0ed682..2622f6e544b8e 100644
--- a/src/status_macros.h
+++ b/src/status_macros.h
@@ -34,7 +34,7 @@
if (ABSL_PREDICT_FALSE(!statusor.ok())) { \
return std::move(statusor).status(); \
} \
- lhs = std::move(statusor).ValueOrDie()
+ lhs = std::move(statusor).value()
// Internal helper for concatenating macro values.
#define RLWE_STATUS_MACROS_IMPL_CONCAT_INNER_(x, y) x##y
diff --git a/src/status_macros_test.cc b/src/status_macros_test.cc
index d43b55c9bb800..1f96d59e5d3b7 100644
--- a/src/status_macros_test.cc
+++ b/src/status_macros_test.cc
@@ -27,8 +27,8 @@ namespace {
TEST(StatusMacrosTest, TestAssignOrReturn) {
StatusOr<StatusOr<int>> a(StatusOr<int>(2));
auto f = [&]() -> absl::Status {
- RLWE_ASSIGN_OR_RETURN(StatusOr<int> status_or_a, a.ValueOrDie());
- EXPECT_EQ(2, status_or_a.ValueOrDie());
+ RLWE_ASSIGN_OR_RETURN(StatusOr<int> status_or_a, a.value());
+ EXPECT_EQ(2, status_or_a.value());
return absl::OkStatus();
};
auto status = f();
diff --git a/src/statusor.h b/src/statusor.h
index b7ada09372c9f..2d3ecd810c49c 100644
--- a/src/statusor.h
+++ b/src/statusor.h
@@ -17,239 +17,13 @@
#ifndef RLWE_STATUSOR_H_
#define RLWE_STATUSOR_H_
-#include <cassert>
-
-#include "absl/base/attributes.h"
-#include "absl/status/status.h"
-#include "absl/types/optional.h"
+#include "absl/status/statusor.h"
#include "third_party/shell-encryption/base/shell_encryption_export.h"
namespace rlwe {
template <typename T>
-class SHELL_ENCRYPTION_EXPORT StatusOr {
- public:
- // Construct a new StatusOr with Status::UNKNOWN status
- StatusOr();
-
- // Construct a new StatusOr with the given non-ok status. After calling
- // this constructor, calls to value() will CHECK-fail.
- //
- // NOTE: Not explicit - we want to use StatusOr<T> as a return
- // value, so it is convenient and sensible to be able to do 'return
- // Status()' when the return type is StatusOr<T>.
- //
- // REQUIRES: status != Status::OK. This requirement is DCHECKed.
- // In optimized builds, passing Status::OK here will have the effect
- // of passing PosixErrorSpace::EINVAL as a fallback.
- StatusOr(const absl::Status& status);
-
- // Construct a new StatusOr with the given value. If T is a plain pointer,
- // value must not be NULL. After calling this constructor, calls to
- // value() will succeed, and calls to status() will return OK.
- //
- // NOTE: Not explicit - we want to use StatusOr<T> as a return type
- // so it is convenient and sensible to be able to do 'return T()'
- // when the return type is StatusOr<T>.
- //
- // REQUIRES: if T is a plain pointer, value != NULL. This requirement is
- // DCHECKed. In optimized builds, passing a NULL pointer here will have
- // the effect of passing absl::StatusCode::kInternal as a fallback.
- StatusOr(const T& value);
-
- // Copy constructor.
- StatusOr(const StatusOr& other);
-
- // Assignment operator.
- StatusOr& operator=(const StatusOr& other);
-
- // Move constructor and move-assignment operator.
- StatusOr(StatusOr&& other) = default;
- StatusOr& operator=(StatusOr&& other) = default;
-
- // Rvalue-reference overloads of the other constructors and assignment
- // operators, to support move-only types and avoid unnecessary copying.
- StatusOr(T&& value);
-
- // Returns a reference to our status. If this contains a T, then
- // returns Status::OK.
- const absl::Status& status() const;
-
- // Returns this->status().ok()
- bool ok() const;
-
- // Returns a reference to our current value, or CHECK-fails if !this->ok().
- const T& ValueOrDie() const&;
- T& ValueOrDie() &;
- const T&& ValueOrDie() const&&;
- T&& ValueOrDie() &&;
-
- // Returns a reference to our current value, or CHECK-fails if !this->ok().
- const T& value() const&;
- T& value() &;
- const T&& value() const&&;
- T&& value() &&;
-
- // Ignores any errors. This method does nothing except potentially suppress
- // complaints from any tools that are checking that errors are not dropped on
- // the floor.
- void IgnoreError() const {}
-
- operator absl::Status() const { return status(); }
-
- template <template <typename> class OtherStatusOrType>
- operator OtherStatusOrType<T>() {
- if (value_) {
- return OtherStatusOrType<T>(std::move(value_.value()));
- } else {
- return OtherStatusOrType<T>(status());
- }
- }
-
- private:
- absl::Status status_;
- absl::optional<T> value_;
-};
-
-namespace internal {
-
-class SHELL_ENCRYPTION_EXPORT StatusOrHelper {
- public:
- // Move type-agnostic error handling to the .cc.
- static SHELL_ENCRYPTION_EXPORT absl::Status HandleInvalidStatusCtorArg();
- static SHELL_ENCRYPTION_EXPORT absl::Status HandleNullObjectCtorArg();
- static SHELL_ENCRYPTION_EXPORT void Crash(const absl::Status& status);
-
- // Customized behavior for StatusOr<T> vs. StatusOr<T*>
- template <typename T>
- struct Specialize;
-};
-
-template <typename T>
-struct SHELL_ENCRYPTION_EXPORT StatusOrHelper::Specialize {
- // For non-pointer T, a reference can never be NULL.
- static inline bool IsValueNull(const T& t) { return false; }
-};
-
-template <typename T>
-struct SHELL_ENCRYPTION_EXPORT StatusOrHelper::Specialize<T*> {
- static inline bool IsValueNull(const T* t) { return t == nullptr; }
-};
-
-} // namespace internal
-
-template <typename T>
-inline StatusOr<T>::StatusOr()
- : status_(absl::UnknownError("")), value_(absl::nullopt) {}
-
-template <typename T>
-inline StatusOr<T>::StatusOr(const absl::Status& status)
- : status_(status), value_(absl::nullopt) {
- if (status.ok()) {
- status_ = internal::StatusOrHelper::HandleInvalidStatusCtorArg();
- }
-}
-
-template <typename T>
-inline StatusOr<T>::StatusOr(const T& value)
- : status_(absl::OkStatus()), value_(value) {
- if (internal::StatusOrHelper::Specialize<T>::IsValueNull(value)) {
- status_ = internal::StatusOrHelper::HandleNullObjectCtorArg();
- }
-}
-
-template <typename T>
-inline StatusOr<T>::StatusOr(const StatusOr& other)
- : status_(other.status_), value_(other.value_) {}
-
-template <typename T>
-inline StatusOr<T>& StatusOr<T>::operator=(const StatusOr<T>& other) {
- status_ = other.status_;
- value_.reset(other.value_);
- return *this;
-}
-
-template <typename T>
-inline StatusOr<T>::StatusOr(T&& value)
- : status_(absl::OkStatus()), value_(std::forward<T>(value)) {
- if (internal::StatusOrHelper::Specialize<T>::IsValueNull(value_.value())) {
- status_ = internal::StatusOrHelper::HandleNullObjectCtorArg();
- }
-}
-
-template <typename T>
-inline const absl::Status& StatusOr<T>::status() const {
- return status_;
-}
-
-template <typename T>
-inline bool StatusOr<T>::ok() const {
- return status_.ok();
-}
-
-template <typename T>
-inline const T& StatusOr<T>::ValueOrDie() const& {
- if (!value_) {
- internal::StatusOrHelper::Crash(status());
- }
- return value_.value();
-}
-
-template <typename T>
-inline T& StatusOr<T>::ValueOrDie() & {
- if (!value_) {
- internal::StatusOrHelper::Crash(status());
- }
- return value_.value();
-}
-
-template <typename T>
-inline const T&& StatusOr<T>::ValueOrDie() const&& {
- if (!value_) {
- internal::StatusOrHelper::Crash(status());
- }
- return std::move(value_.value());
-}
-
-template <typename T>
-inline T&& StatusOr<T>::ValueOrDie() && {
- if (!value_) {
- internal::StatusOrHelper::Crash(status());
- }
- return std::move(value_.value());
-}
-
-template <typename T>
-inline const T& StatusOr<T>::value() const& {
- if (!value_) {
- internal::StatusOrHelper::Crash(status());
- }
- return value_.value();
-}
-
-template <typename T>
-inline T& StatusOr<T>::value() & {
- if (!value_) {
- internal::StatusOrHelper::Crash(status());
- }
- return value_.value();
-}
-
-template <typename T>
-inline const T&& StatusOr<T>::value() const&& {
- if (!value_) {
- internal::StatusOrHelper::Crash(status());
- }
- return std::move(value_.value());
-}
-
-template <typename T>
-inline T&& StatusOr<T>::value() && {
- if (!value_) {
- internal::StatusOrHelper::Crash(status());
- }
- return std::move(value_.value());
-}
+using StatusOr = absl::StatusOr<T>;
} // namespace rlwe
diff --git a/src/testing/coefficient_polynomial_test.cc b/src/testing/coefficient_polynomial_test.cc
index bf43ee6f4ae02..e2a36c3d7d6bf 100644
--- a/src/testing/coefficient_polynomial_test.cc
+++ b/src/testing/coefficient_polynomial_test.cc
@@ -43,7 +43,7 @@ unsigned int seed = 0;
class PolynomialTest : public ::testing::Test {
protected:
PolynomialTest()
- : params14_(uint_m::Params::Create(rlwe::kNewhopeModulus).ValueOrDie()),
+ : params14_(uint_m::Params::Create(rlwe::kNewhopeModulus).value()),
one_(uint_m::ImportOne(params14_.get())),
zero_(uint_m::ImportZero(params14_.get())) {}
diff --git a/src/testing/status_testing.h b/src/testing/status_testing.h
index 27b8c0ed63073..6adc0278c98d2 100644
--- a/src/testing/status_testing.h
+++ b/src/testing/status_testing.h
@@ -43,6 +43,6 @@
#define RLWE_ASSERT_OK_AND_ASSIGN_IMPL_(statusor, lhs, rexpr) \
auto statusor = (rexpr); \
ASSERT_THAT(statusor.ok(), ::testing::Eq(true)); \
- lhs = std::move(statusor).ValueOrDie()
+ lhs = std::move(statusor).value()
#endif // RLWE_TESTING_STATUS_TESTING_H_
|