Remove fillins/fillins_base64

Move these functions into the library bssl::string_util namespace

Bug: 668
Change-Id: I1665176217fb25164cb321a4092391bf60592a88
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/64187
Reviewed-by: Adam Langley <agl@google.com>
Commit-Queue: Bob Beck <bbe@google.com>
Auto-Submit: Bob Beck <bbe@google.com>
diff --git a/pki/fillins/fillins_base64.cc b/pki/fillins/fillins_base64.cc
deleted file mode 100644
index a692cb0..0000000
--- a/pki/fillins/fillins_base64.cc
+++ /dev/null
@@ -1,48 +0,0 @@
-// Copyright 2023 The Chromium Authors
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include <openssl/base64.h>
-
-#include "fillins_base64.h"
-
-#include <vector>
-
-namespace bssl {
-
-namespace fillins {
-
-bool Base64Encode(const std::string_view &input, std::string *output) {
-  size_t len;
-  if (!EVP_EncodedLength(&len, input.size())) {
-    return false;
-  }
-  std::vector<char> encoded(len);
-  len = EVP_EncodeBlock(reinterpret_cast<uint8_t *>(encoded.data()),
-                        reinterpret_cast<const uint8_t *>(input.data()),
-                        input.size());
-  if (!len) {
-    return false;
-  }
-  output->assign(encoded.data(), len);
-  return true;
-}
-
-bool Base64Decode(const std::string_view &input, std::string *output) {
-  size_t len;
-  if (!EVP_DecodedLength(&len, input.size())) {
-    return false;
-  }
-  std::vector<char> decoded(len);
-  if (!EVP_DecodeBase64(reinterpret_cast<uint8_t *>(decoded.data()), &len, len,
-                        reinterpret_cast<const uint8_t *>(input.data()),
-                        input.size())) {
-    return false;
-  }
-  output->assign(decoded.data(), len);
-  return true;
-}
-
-}  // namespace fillins
-
-}  // namespace bssl
diff --git a/pki/fillins/fillins_base64.h b/pki/fillins/fillins_base64.h
deleted file mode 100644
index 440138f..0000000
--- a/pki/fillins/fillins_base64.h
+++ /dev/null
@@ -1,27 +0,0 @@
-// Copyright 2023 The Chromium Authors
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef BSSL_FILLINS_BASE64_H
-#define BSSL_FILLINS_BASE64_H
-
-#include <openssl/base.h>
-
-#include <string>
-#include <string_view>
-
-namespace bssl {
-
-namespace fillins {
-
-OPENSSL_EXPORT bool Base64Encode(const std::string_view &input,
-                                 std::string *output);
-
-OPENSSL_EXPORT bool Base64Decode(const std::string_view &input,
-                                 std::string *output);
-
-}  // namespace fillins
-
-}  // namespace bssl
-
-#endif  // BSSL_FILLINS_BASE64_H
diff --git a/pki/pem.cc b/pki/pem.cc
index b92a0e2..63d7c45 100644
--- a/pki/pem.cc
+++ b/pki/pem.cc
@@ -6,7 +6,6 @@
 #include "string_util.h"
 
 #include <string_view>
-#include "fillins/fillins_base64.h"
 
 namespace {
 
@@ -63,7 +62,7 @@
 
       std::string_view encoded =
           str_.substr(data_begin, footer_pos - data_begin);
-      if (!fillins::Base64Decode(
+      if (!string_util::Base64Decode(
               string_util::CollapseWhitespaceASCII(encoded, true), &data_)) {
         // The most likely cause for a decode failure is a datatype that
         // includes PEM headers, which are not supported.
@@ -107,7 +106,7 @@
 
 std::string PEMEncode(std::string_view data, const std::string &type) {
   std::string b64_encoded;
-  fillins::Base64Encode(data, &b64_encoded);
+  string_util::Base64Encode(data, &b64_encoded);
 
   // Divide the Base-64 encoded data into 64-character chunks, as per
   // 4.3.2.4 of RFC 1421.
diff --git a/pki/string_util.cc b/pki/string_util.cc
index cbcba47..baebc7f 100644
--- a/pki/string_util.cc
+++ b/pki/string_util.cc
@@ -9,6 +9,7 @@
 #include <sstream>
 #include <string>
 
+#include <openssl/base64.h>
 #include <openssl/mem.h>
 
 namespace bssl::string_util {
@@ -158,4 +159,35 @@
   return result;
 }
 
+bool Base64Encode(const std::string_view &input, std::string *output) {
+  size_t len;
+  if (!EVP_EncodedLength(&len, input.size())) {
+    return false;
+  }
+  std::vector<char> encoded(len);
+  len = EVP_EncodeBlock(reinterpret_cast<uint8_t *>(encoded.data()),
+                        reinterpret_cast<const uint8_t *>(input.data()),
+                        input.size());
+  if (!len) {
+    return false;
+  }
+  output->assign(encoded.data(), len);
+  return true;
+}
+
+bool Base64Decode(const std::string_view &input, std::string *output) {
+  size_t len;
+  if (!EVP_DecodedLength(&len, input.size())) {
+    return false;
+  }
+  std::vector<char> decoded(len);
+  if (!EVP_DecodeBase64(reinterpret_cast<uint8_t *>(decoded.data()), &len, len,
+                        reinterpret_cast<const uint8_t *>(input.data()),
+                        input.size())) {
+    return false;
+  }
+  output->assign(decoded.data(), len);
+  return true;
+}
+
 }  // namespace bssl::string_util
diff --git a/pki/string_util.h b/pki/string_util.h
index ac0ac3f..c93beaa 100644
--- a/pki/string_util.h
+++ b/pki/string_util.h
@@ -61,6 +61,15 @@
 OPENSSL_EXPORT std::string CollapseWhitespaceASCII(
     std::string_view text, bool trim_sequences_with_line_breaks);
 
+// Base64 encodes |input| into |output| returning true on success,
+// false otherwise.
+OPENSSL_EXPORT bool Base64Encode(const std::string_view &input,
+                                 std::string *output);
+
+// Base64 decodes |input| into |output| returning true on success,
+// false otherwise.
+OPENSSL_EXPORT bool Base64Decode(const std::string_view &input,
+                                 std::string *output);
 
 }  // namespace bssl::string_util
 
diff --git a/sources.cmake b/sources.cmake
index 3b3b343..d12a8e6 100644
--- a/sources.cmake
+++ b/sources.cmake
@@ -358,7 +358,6 @@
   pki/crl.cc
   pki/encode_values.cc
   pki/extended_key_usage.cc
-  pki/fillins/fillins_base64.cc
   pki/fillins/openssl_util.cc
   pki/general_names.cc
   pki/input.cc