binder: CertificateFormat -> RpcCertificateFormat.

Fixes: 199553357
Test: TH

Change-Id: Ifaea4598f125ac5a8395ea30729a0059a792efbb
diff --git a/libs/binder/RpcCertificateUtils.cpp b/libs/binder/RpcCertificateUtils.cpp
index 2aec2f6..d91736c 100644
--- a/libs/binder/RpcCertificateUtils.cpp
+++ b/libs/binder/RpcCertificateUtils.cpp
@@ -46,23 +46,23 @@
 } // namespace
 
 bssl::UniquePtr<X509> deserializeCertificate(const std::vector<uint8_t>& cert,
-                                             CertificateFormat format) {
+                                             RpcCertificateFormat format) {
     switch (format) {
-        case CertificateFormat::PEM:
+        case RpcCertificateFormat::PEM:
             return fromPem(cert);
-        case CertificateFormat::DER:
+        case RpcCertificateFormat::DER:
             return fromDer(cert);
     }
     LOG_ALWAYS_FATAL("Unsupported format %d", static_cast<int>(format));
 }
 
-std::vector<uint8_t> serializeCertificate(X509* x509, CertificateFormat format) {
+std::vector<uint8_t> serializeCertificate(X509* x509, RpcCertificateFormat format) {
     bssl::UniquePtr<BIO> certBio(BIO_new(BIO_s_mem()));
     switch (format) {
-        case CertificateFormat::PEM: {
+        case RpcCertificateFormat::PEM: {
             TEST_AND_RETURN({}, PEM_write_bio_X509(certBio.get(), x509));
         } break;
-        case CertificateFormat::DER: {
+        case RpcCertificateFormat::DER: {
             TEST_AND_RETURN({}, i2d_X509_bio(certBio.get(), x509));
         } break;
         default: {
diff --git a/libs/binder/RpcServer.cpp b/libs/binder/RpcServer.cpp
index 1d42fc3..5733993 100644
--- a/libs/binder/RpcServer.cpp
+++ b/libs/binder/RpcServer.cpp
@@ -141,7 +141,7 @@
     return ret;
 }
 
-std::vector<uint8_t> RpcServer::getCertificate(CertificateFormat format) {
+std::vector<uint8_t> RpcServer::getCertificate(RpcCertificateFormat format) {
     std::lock_guard<std::mutex> _l(mLock);
     return mCtx->getCertificate(format);
 }
diff --git a/libs/binder/RpcSession.cpp b/libs/binder/RpcSession.cpp
index 8449b3c..9395b50 100644
--- a/libs/binder/RpcSession.cpp
+++ b/libs/binder/RpcSession.cpp
@@ -703,7 +703,7 @@
     return false;
 }
 
-std::vector<uint8_t> RpcSession::getCertificate(CertificateFormat format) {
+std::vector<uint8_t> RpcSession::getCertificate(RpcCertificateFormat format) {
     return mCtx->getCertificate(format);
 }
 
diff --git a/libs/binder/RpcTransportRaw.cpp b/libs/binder/RpcTransportRaw.cpp
index 827e518..c012df8 100644
--- a/libs/binder/RpcTransportRaw.cpp
+++ b/libs/binder/RpcTransportRaw.cpp
@@ -111,7 +111,7 @@
     std::unique_ptr<RpcTransport> newTransport(android::base::unique_fd fd, FdTrigger*) const {
         return std::make_unique<RpcTransportRaw>(std::move(fd));
     }
-    std::vector<uint8_t> getCertificate(CertificateFormat) const override { return {}; }
+    std::vector<uint8_t> getCertificate(RpcCertificateFormat) const override { return {}; }
 };
 
 } // namespace
diff --git a/libs/binder/RpcTransportTls.cpp b/libs/binder/RpcTransportTls.cpp
index 2a1dffd..d40cfc8 100644
--- a/libs/binder/RpcTransportTls.cpp
+++ b/libs/binder/RpcTransportTls.cpp
@@ -451,7 +451,7 @@
             std::shared_ptr<RpcCertificateVerifier> verifier);
     std::unique_ptr<RpcTransport> newTransport(android::base::unique_fd fd,
                                                FdTrigger* fdTrigger) const override;
-    std::vector<uint8_t> getCertificate(CertificateFormat) const override;
+    std::vector<uint8_t> getCertificate(RpcCertificateFormat) const override;
 
 protected:
     static ssl_verify_result_t sslCustomVerify(SSL* ssl, uint8_t* outAlert);
@@ -460,7 +460,7 @@
     std::shared_ptr<RpcCertificateVerifier> mCertVerifier;
 };
 
-std::vector<uint8_t> RpcTransportCtxTls::getCertificate(CertificateFormat format) const {
+std::vector<uint8_t> RpcTransportCtxTls::getCertificate(RpcCertificateFormat format) const {
     X509* x509 = SSL_CTX_get0_certificate(mCtx.get()); // does not own
     return serializeCertificate(x509, format);
 }
diff --git a/libs/binder/include/binder/CertificateFormat.h b/libs/binder/include/binder/RpcCertificateFormat.h
similarity index 83%
rename from libs/binder/include/binder/CertificateFormat.h
rename to libs/binder/include/binder/RpcCertificateFormat.h
index 22a8e47..bc9d814 100644
--- a/libs/binder/include/binder/CertificateFormat.h
+++ b/libs/binder/include/binder/RpcCertificateFormat.h
@@ -22,16 +22,16 @@
 
 namespace android {
 
-enum class CertificateFormat {
+enum class RpcCertificateFormat {
     PEM,
     DER,
 };
 
-static inline std::string PrintToString(CertificateFormat format) {
+static inline std::string PrintToString(RpcCertificateFormat format) {
     switch (format) {
-        case CertificateFormat::PEM:
+        case RpcCertificateFormat::PEM:
             return "PEM";
-        case CertificateFormat::DER:
+        case RpcCertificateFormat::DER:
             return "DER";
         default:
             return "<unknown>";
diff --git a/libs/binder/include/binder/RpcServer.h b/libs/binder/include/binder/RpcServer.h
index 9f92410..fb2cf23 100644
--- a/libs/binder/include/binder/RpcServer.h
+++ b/libs/binder/include/binder/RpcServer.h
@@ -135,7 +135,7 @@
     /**
      * See RpcTransportCtx::getCertificate
      */
-    std::vector<uint8_t> getCertificate(CertificateFormat);
+    std::vector<uint8_t> getCertificate(RpcCertificateFormat);
 
     /**
      * Runs join() in a background thread. Immediately returns.
diff --git a/libs/binder/include/binder/RpcSession.h b/libs/binder/include/binder/RpcSession.h
index 76ef9ff..71eb223 100644
--- a/libs/binder/include/binder/RpcSession.h
+++ b/libs/binder/include/binder/RpcSession.h
@@ -53,7 +53,7 @@
     // Create an RpcSession with default configuration (raw sockets).
     static sp<RpcSession> make();
 
-    // Create an RpcSession with the given configuration. |serverCertificateFormat| and
+    // Create an RpcSession with the given configuration. |serverRpcCertificateFormat| and
     // |serverCertificate| must have values or be nullopt simultaneously. If they have values, set
     // server certificate.
     static sp<RpcSession> make(std::unique_ptr<RpcTransportCtxFactory> rpcTransportCtxFactory);
@@ -131,7 +131,7 @@
     /**
      * See RpcTransportCtx::getCertificate
      */
-    std::vector<uint8_t> getCertificate(CertificateFormat);
+    std::vector<uint8_t> getCertificate(RpcCertificateFormat);
 
     /**
      * Shuts down the service.
diff --git a/libs/binder/include/binder/RpcTransport.h b/libs/binder/include/binder/RpcTransport.h
index 4ad7bf4..1c0bb18 100644
--- a/libs/binder/include/binder/RpcTransport.h
+++ b/libs/binder/include/binder/RpcTransport.h
@@ -25,7 +25,7 @@
 #include <android-base/unique_fd.h>
 #include <utils/Errors.h>
 
-#include <binder/CertificateFormat.h>
+#include <binder/RpcCertificateFormat.h>
 
 namespace android {
 
@@ -73,7 +73,8 @@
     // Implementation details:
     // - For raw sockets, this always returns empty string.
     // - For TLS, this returns the certificate. See RpcTransportTls for details.
-    [[nodiscard]] virtual std::vector<uint8_t> getCertificate(CertificateFormat format) const = 0;
+    [[nodiscard]] virtual std::vector<uint8_t> getCertificate(
+            RpcCertificateFormat format) const = 0;
 
 protected:
     RpcTransportCtx() = default;
diff --git a/libs/binder/include_tls/binder/RpcCertificateUtils.h b/libs/binder/include_tls/binder/RpcCertificateUtils.h
index b7c1849..8d07835 100644
--- a/libs/binder/include_tls/binder/RpcCertificateUtils.h
+++ b/libs/binder/include_tls/binder/RpcCertificateUtils.h
@@ -22,13 +22,13 @@
 
 #include <openssl/ssl.h>
 
-#include <binder/CertificateFormat.h>
+#include <binder/RpcCertificateFormat.h>
 
 namespace android {
 
 bssl::UniquePtr<X509> deserializeCertificate(const std::vector<uint8_t>& cert,
-                                             CertificateFormat format);
+                                             RpcCertificateFormat format);
 
-std::vector<uint8_t> serializeCertificate(X509* x509, CertificateFormat format);
+std::vector<uint8_t> serializeCertificate(X509* x509, RpcCertificateFormat format);
 
 } // namespace android
diff --git a/libs/binder/tests/RpcCertificateVerifierSimple.cpp b/libs/binder/tests/RpcCertificateVerifierSimple.cpp
index 0cf0e1c..4694d1b 100644
--- a/libs/binder/tests/RpcCertificateVerifierSimple.cpp
+++ b/libs/binder/tests/RpcCertificateVerifierSimple.cpp
@@ -33,7 +33,7 @@
     return PERMISSION_DENIED;
 }
 
-status_t RpcCertificateVerifierSimple::addTrustedPeerCertificate(CertificateFormat format,
+status_t RpcCertificateVerifierSimple::addTrustedPeerCertificate(RpcCertificateFormat format,
                                                                  const std::vector<uint8_t>& cert) {
     bssl::UniquePtr<X509> x509 = deserializeCertificate(cert, format);
     if (x509 == nullptr) {
diff --git a/libs/binder/tests/RpcCertificateVerifierSimple.h b/libs/binder/tests/RpcCertificateVerifierSimple.h
index 02aa3c6..1f2e531 100644
--- a/libs/binder/tests/RpcCertificateVerifierSimple.h
+++ b/libs/binder/tests/RpcCertificateVerifierSimple.h
@@ -22,7 +22,7 @@
 
 #include <openssl/ssl.h>
 
-#include <binder/CertificateFormat.h>
+#include <binder/RpcCertificateFormat.h>
 #include <binder/RpcCertificateVerifier.h>
 
 namespace android {
@@ -42,7 +42,7 @@
     // Caller must ensure that RpcTransportCtx::newTransport() are called after all trusted peer
     // certificates are added. Otherwise, RpcTransport-s created before may not trust peer
     // certificates added later.
-    [[nodiscard]] status_t addTrustedPeerCertificate(CertificateFormat format,
+    [[nodiscard]] status_t addTrustedPeerCertificate(RpcCertificateFormat format,
                                                      const std::vector<uint8_t>& cert);
 
 private:
diff --git a/libs/binder/tests/binderRpcTest.cpp b/libs/binder/tests/binderRpcTest.cpp
index 8ffd68d..a4e37ad 100644
--- a/libs/binder/tests/binderRpcTest.cpp
+++ b/libs/binder/tests/binderRpcTest.cpp
@@ -556,15 +556,16 @@
 
                     BinderRpcTestServerInfo serverInfo;
                     serverInfo.port = static_cast<int64_t>(outPort);
-                    serverInfo.cert.data = server->getCertificate(CertificateFormat::PEM);
+                    serverInfo.cert.data = server->getCertificate(RpcCertificateFormat::PEM);
                     writeToFd(writeEnd, serverInfo);
                     auto clientInfo = readFromFd<BinderRpcTestClientInfo>(readEnd);
 
                     if (rpcSecurity == RpcSecurity::TLS) {
                         for (const auto& clientCert : clientInfo.certs) {
                             CHECK_EQ(OK,
-                                     certVerifier->addTrustedPeerCertificate(CertificateFormat::PEM,
-                                                                             clientCert.data));
+                                     certVerifier
+                                             ->addTrustedPeerCertificate(RpcCertificateFormat::PEM,
+                                                                         clientCert.data));
                         }
                     }
 
@@ -587,7 +588,7 @@
         BinderRpcTestClientInfo clientInfo;
         for (const auto& session : sessions) {
             auto& parcelableCert = clientInfo.certs.emplace_back();
-            parcelableCert.data = session->getCertificate(CertificateFormat::PEM);
+            parcelableCert.data = session->getCertificate(RpcCertificateFormat::PEM);
         }
         writeToFd(ret.host.writeEnd(), clientInfo);
 
@@ -599,7 +600,8 @@
         if (rpcSecurity == RpcSecurity::TLS) {
             const auto& serverCert = serverInfo.cert.data;
             CHECK_EQ(OK,
-                     certVerifier->addTrustedPeerCertificate(CertificateFormat::PEM, serverCert));
+                     certVerifier->addTrustedPeerCertificate(RpcCertificateFormat::PEM,
+                                                             serverCert));
         }
 
         status_t status;
@@ -1433,7 +1435,7 @@
                         BinderRpcSimple::PrintTestParam);
 
 class RpcTransportTest
-      : public ::testing::TestWithParam<std::tuple<SocketType, RpcSecurity, CertificateFormat>> {
+      : public ::testing::TestWithParam<std::tuple<SocketType, RpcSecurity, RpcCertificateFormat>> {
 public:
     using ConnectToServer = std::function<base::unique_fd()>;
     static inline std::string PrintParamInfo(const testing::TestParamInfo<ParamType>& info) {
@@ -1727,17 +1729,17 @@
     maliciousClient.run(true, readOk);
 }
 
-std::vector<CertificateFormat> testCertificateFormats() {
+std::vector<RpcCertificateFormat> testRpcCertificateFormats() {
     return {
-            CertificateFormat::PEM,
-            CertificateFormat::DER,
+            RpcCertificateFormat::PEM,
+            RpcCertificateFormat::DER,
     };
 }
 
 INSTANTIATE_TEST_CASE_P(BinderRpc, RpcTransportTest,
                         ::testing::Combine(::testing::ValuesIn(testSocketTypes(false)),
                                            ::testing::ValuesIn(RpcSecurityValues()),
-                                           ::testing::ValuesIn(testCertificateFormats())),
+                                           ::testing::ValuesIn(testRpcCertificateFormats())),
                         RpcTransportTest::PrintParamInfo);
 
 } // namespace android