xref: /aosp_15_r20/external/private-join-and-compute/private_join_and_compute/crypto/proto/proto_util.h (revision a6aa18fbfbf9cb5cd47356a9d1b057768998488c)
1 /*
2  * Copyright 2019 Google LLC.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     https://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef PRIVATE_JOIN_AND_COMPUTE_CRYPTO_PROTO_PROTO_UTIL_H_
17 #define PRIVATE_JOIN_AND_COMPUTE_CRYPTO_PROTO_PROTO_UTIL_H_
18 
19 #include <string>
20 #include <vector>
21 
22 #include "private_join_and_compute/crypto/context.h"
23 #include "private_join_and_compute/crypto/ec_group.h"
24 #include "private_join_and_compute/crypto/proto/big_num.pb.h"
25 #include "private_join_and_compute/crypto/proto/ec_point.pb.h"
26 
27 #include "src/google/protobuf/message_lite.h"
28 
29 namespace private_join_and_compute {
30 // Converts a std::vector<BigNum> into a protocol buffer BigNumVector.
31 proto::BigNumVector BigNumVectorToProto(
32     absl::Span<const BigNum> big_num_vector);
33 
34 // Converts a protocol buffer BigNumVector into a std::vector<BigNum>.
35 std::vector<BigNum> ParseBigNumVectorProto(
36     Context* context, const proto::BigNumVector& big_num_vector_proto);
37 
38 // Converts a std::vector<ECPoint> into a protocol buffer ECPointVector.
39 StatusOr<proto::ECPointVector> ECPointVectorToProto(
40     absl::Span<const ECPoint> ec_point_vector);
41 
42 // Converts a protocol buffer ECPointVector into a std::vector<ECPoint>.
43 StatusOr<std::vector<ECPoint>> ParseECPointVectorProto(
44     Context* context, ECGroup* ec_group,
45     const proto::ECPointVector& ec_point_vector_proto);
46 
47 // Serializes a proto to a string by serializing the fields in tag order. This
48 // will guarantee deterministic encoding, as long as there are no cross-language
49 // strings, and no unknown fields across different serializations.
50 std::string SerializeAsStringInOrder(const google::protobuf::MessageLite& proto);
51 
52 }  // namespace private_join_and_compute
53 
54 #endif  // PRIVATE_JOIN_AND_COMPUTE_CRYPTO_PROTO_PROTO_UTIL_H_
55