diff options
author | Karn Seth <karn@google.com> | 2021-05-13 20:13:40 +0000 |
---|---|---|
committer | Karn Seth <karn@google.com> | 2021-05-13 20:13:40 +0000 |
commit | 11cfedad51513688c421e86a77fe0e57399340f3 (patch) | |
tree | 7764b78aeab7b3284443d9007737f86c83acfd99 | |
parent | 89c8d0aae070b9c282043af419e47d7ef897f460 (diff) | |
download | private-join-and-compute-11cfedad51513688c421e86a77fe0e57399340f3.tar.gz |
push internal changes
-rw-r--r-- | WORKSPACE | 6 | ||||
-rw-r--r-- | crypto/context.cc | 6 | ||||
-rw-r--r-- | crypto/openssl_init.cc | 4 | ||||
-rw-r--r-- | util/BUILD | 3 | ||||
-rw-r--r-- | util/proto_util.h | 26 | ||||
-rw-r--r-- | util/proto_util_test.cc | 17 |
6 files changed, 49 insertions, 13 deletions
@@ -61,10 +61,10 @@ git_repository( # gRPC http_archive( name = "com_github_grpc_grpc", - strip_prefix = "grpc-1.35.0", - sha256 = "27dd2fc5c9809ddcde8eb6fa1fa278a3486566dfc28335fca13eb8df8bd3b958", + strip_prefix = "grpc-1.37.1", + sha256 = "acf247ec3a52edaee5dee28644a4e485c5e5badf46bdb24a80ca1d76cb8f1174", urls = [ - "https://github.com/grpc/grpc/archive/v1.35.0.tar.gz", + "https://github.com/grpc/grpc/archive/v1.37.1.tar.gz", ], ) diff --git a/crypto/context.cc b/crypto/context.cc index 5efc744..84f7170 100644 --- a/crypto/context.cc +++ b/crypto/context.cc @@ -25,9 +25,6 @@ #include "absl/strings/string_view.h" #include "crypto/openssl_init.h" #include "glog/logging.h" -#if defined(OS_NACL) -#include "privacy/blinders/cpp/nacl_context.h" -#endif namespace private_join_and_compute { @@ -44,9 +41,6 @@ Context::Context() one_bn_(CreateBigNum(1)), two_bn_(CreateBigNum(2)), three_bn_(CreateBigNum(3)) { -#if defined(OS_NACL) - nacl::SeedOpenSSLRand(); -#endif OpenSSLInit(); CHECK(RAND_status()) << "OpenSSL PRNG is not properly seeded."; HMAC_CTX_init(&hmac_ctx_); diff --git a/crypto/openssl_init.cc b/crypto/openssl_init.cc index 47895a1..a63ffaf 100644 --- a/crypto/openssl_init.cc +++ b/crypto/openssl_init.cc @@ -71,11 +71,7 @@ static std::once_flag init_flag; static OpenSSLInit openssl_init; void CryptoNewThreadID(CRYPTO_THREADID* tid) { -#if defined(OS_NACL) // pthread_t is a pointer type in native client. - CRYPTO_THREADID_set_pointer(tid, pthread_self()); -#else CRYPTO_THREADID_set_numeric(tid, static_cast<uint64_t>(pthread_self())); -#endif } // See crypto/threads/mmtest.c for usage in OpenSSL library. @@ -87,6 +87,8 @@ cc_library( name = "proto_util", hdrs = ["proto_util.h"], deps = [ + ":recordio", + ":status_includes", "@com_google_absl//absl/strings", "@com_google_protobuf//:protobuf_lite", ], @@ -99,6 +101,7 @@ cc_test( deps = [ ":file_test_proto", ":proto_util", + ":status_testing_includes", "@com_github_google_googletest//:gtest_main", ], ) diff --git a/util/proto_util.h b/util/proto_util.h index e262f69..5c79a5f 100644 --- a/util/proto_util.h +++ b/util/proto_util.h @@ -23,6 +23,8 @@ #include "absl/strings/string_view.h" #include "src/google/protobuf/message_lite.h" +#include "util/recordio.h" +#include "util/status.inc" namespace private_join_and_compute { @@ -32,6 +34,12 @@ class ProtoUtils { static ProtoType FromString(absl::string_view raw_data); static std::string ToString(const google::protobuf::MessageLite& record); + + template <typename ProtoType> + static StatusOr<ProtoType> ReadProtoFromFile(absl::string_view filename); + + static Status WriteProtoToFile(const google::protobuf::MessageLite& record, + absl::string_view filename); }; template <typename ProtoType> @@ -48,6 +56,24 @@ inline std::string ProtoUtils::ToString( return record_str_stream.str(); } +template <typename ProtoType> +inline StatusOr<ProtoType> ProtoUtils::ReadProtoFromFile( + absl::string_view filename) { + std::unique_ptr<RecordReader> reader(RecordReader::GetRecordReader()); + RETURN_IF_ERROR(reader->Open(filename)); + std::string raw_record; + RETURN_IF_ERROR(reader->Read(&raw_record)); + RETURN_IF_ERROR(reader->Close()); + return ProtoUtils::FromString<ProtoType>(raw_record); +} + +inline Status ProtoUtils::WriteProtoToFile( + const google::protobuf::MessageLite& record, absl::string_view filename) { + std::unique_ptr<RecordWriter> writer(RecordWriter::Get()); + RETURN_IF_ERROR(writer->Open(filename)); + RETURN_IF_ERROR(writer->Write(ProtoUtils::ToString(record))); + return writer->Close(); +} } // namespace private_join_and_compute #endif // INTERNAL_UTIL_PROTO_UTIL_H_ diff --git a/util/proto_util_test.cc b/util/proto_util_test.cc index be33fd9..43626d3 100644 --- a/util/proto_util_test.cc +++ b/util/proto_util_test.cc @@ -18,7 +18,10 @@ #include <gmock/gmock.h> #include <gtest/gtest.h> +#include <string> + #include "util/file_test.pb.h" +#include "util/status_testing.inc" namespace private_join_and_compute { @@ -35,6 +38,20 @@ TEST(ProtoUtilsTest, ConvertsToAndFrom) { EXPECT_EQ(actual_test_proto.dummy(), expected_test_proto.dummy()); } +TEST(ProtoUtilsTest, ReadWriteToFile) { + std::string filename = (::testing::TempDir() + "proto_file"); + + TestProto expected_test_proto; + expected_test_proto.set_record("data"); + expected_test_proto.set_dummy("dummy"); + + ASSERT_TRUE(ProtoUtils::WriteProtoToFile(expected_test_proto, filename).ok()); + ASSERT_OK_AND_ASSIGN(TestProto actual_test_proto, + ProtoUtils::ReadProtoFromFile<TestProto>(filename)); + EXPECT_EQ(actual_test_proto.record(), expected_test_proto.record()); + EXPECT_EQ(actual_test_proto.dummy(), expected_test_proto.dummy()); +} + } // namespace } // namespace private_join_and_compute |