Merge remote-tracking branch 'cros/upstream/main'

Related changes:
70ef0c25 Rewrite most `Foo* field_` pointer fields to `raw_ptr<Foo> field_`.
701da4c2 cbor: Add allow_and_canonicalize_out_of_order_keys flag
6ab897e9 Remove unused "base/macros.h" in components/
fb311d5b Replace DISALLOW_COPY_AND_ASSIGN in components/
a063c268 Swap from base/stl_util.h to cxx17_backports.h in components/ .cc files.
9d6c30f5 Remove unneeded base/stl_util.h includes in components/ and ui/.
0f45c2c3 components: Replace base::Optional and friends with absl counterparts
9567ac5b Delete unused STL includes from components/ headers.
8370d502 [base] Remove base::StringPiece::as_string() usages.
9ebffe85 Added DIR_METADATA files to a batch of subfolders in //components/c...
         and also removed duplicated metadata from OWNERS files
da40ce6b Remove/replace unnecessary includes of logging.h (components/)

BUG=chromium:1271599
BUG=b:204698553
BUG=b:198296022
TEST=cros_run_unit_tests --board=${BOARD} --packages cbor

Change-Id: I8d2601b151ac76edef08c9813ffc79ae22c228ce
diff --git a/BUILD.gn b/BUILD.gn
index fcb4761..7c2015e 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -1,50 +1,102 @@
-# Copyright 2017 The Chromium Authors. All rights reserved.
+# Copyright 2017 The Chromium OS Authors. All rights reserved.
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 
-import("//testing/libfuzzer/fuzzer_test.gni")
+import("//common-mk/pkg_config.gni")
 
-component("cbor") {
+group("all") {
+  deps = [
+    ":libcbor_static",
+    ":libcbor_shared",
+    ":libcbor_pc",
+  ]
+  if (use.test) {
+    deps += [ ":cbor_unittests" ]
+  }
+  if (use.fuzzer) {
+    deps += [ ":reader_fuzzer" ]
+  }
+}
+
+pkg_config("target_defaults") {
+  pkg_deps = [
+    "libchrome",
+  ]
+}
+
+generate_pkg_config("libcbor_pc") {
+  deps = [
+    ":libcbor_static",
+  ]
+  output_name = "cbor"
+  description = "Concise Binary Object Representation library"
+  version = "0.1"
+}
+
+source_set("libcbor_source_set") {
+  configs += [
+    "//common-mk:pic",
+    ":target_defaults",
+  ]
+  defines = [
+    # Define COMPONENT_BUILD so that symbols are exported. See cbor_export.h
+    "COMPONENT_BUILD",
+    "CBOR_IMPLEMENTATION",
+  ]
   sources = [
-    "constants.h",
     "diagnostic_writer.cc",
-    "diagnostic_writer.h",
     "reader.cc",
-    "reader.h",
     "values.cc",
-    "values.h",
     "writer.cc",
-    "writer.h",
-  ]
-
-  defines = [ "CBOR_IMPLEMENTATION" ]
-
-  deps = [ "//base" ]
-}
-
-source_set("unit_tests") {
-  testonly = true
-  sources = [
-    "diagnostic_writer_unittest.cc",
-    "reader_unittest.cc",
-    "values_unittest.cc",
-    "writer_unittest.cc",
-  ]
-
-  deps = [
-    ":cbor",
-    "//base",
-    "//testing/gmock",
-    "//testing/gtest",
   ]
 }
 
-fuzzer_test("reader_fuzzer") {
-  sources = [ "reader_fuzzer.cc" ]
-  deps = [
-    ":cbor",
-    "//base",
-  ]
-  seed_corpus = "reader_fuzzer_corpus/"
-  libfuzzer_options = [ "max_len=65535" ]
+static_library("libcbor_static") {
+  output_name = "libcbor"
+  deps = [ ":libcbor_source_set" ]
+}
+
+shared_library("libcbor_shared") {
+  output_name = "libcbor"
+  deps = [ ":libcbor_source_set" ]
+}
+
+if (use.test) {
+  pkg_config("libchrome_test_config") {
+    pkg_deps = [ "libchrome-test" ]
+  }
+  executable("cbor_unittests") {
+    configs += [
+      "//common-mk:test",
+      ":libchrome_test_config",
+      ":target_defaults",
+    ]
+    sources = [
+      "diagnostic_writer_unittest.cc",
+      "reader_unittest.cc",
+      "values_unittest.cc",
+      "writer_unittest.cc",
+    ]
+    deps = [
+      ":libcbor_static",
+      "//common-mk/testrunner",
+    ]
+  }
+}
+
+if (use.fuzzer) {
+  pkg_config("libchrome_test_config") {
+    pkg_deps = [ "libchrome-test" ]
+  }
+  executable("reader_fuzzer") {
+    configs += [
+      "//common-mk/common_fuzzer",
+      ":libchrome_test_config",
+      ":target_defaults",
+    ]
+    sources = [ "reader_fuzzer.cc" ]
+    deps = [
+      ":libcbor_static",
+    ]
+  }
 }
diff --git a/OWNERS b/OWNERS
index c2ed450..055a336 100644
--- a/OWNERS
+++ b/OWNERS
@@ -1,3 +1 @@
-jochen@chromium.org
-engedy@chromium.org
-file://base/SECURITY_OWNERS
+include chromiumos/platform2:/biod/OWNERS
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..fe58a9a
--- /dev/null
+++ b/README.md
@@ -0,0 +1,30 @@
+# `cbor`: Concise Binary Object Representation
+
+This library is a partial implementation of the RFC 7049 Concise Binary Object
+Representation standard.
+
+The source code was fetched from `chromium/src`
+(https://chromium.googlesource.com/chromium/src/+/242df8b64d2a0ab5f057d1d4c76ea8537fdbb789)
+in order to avoid code duplication.
+
+The cros/upstream/master branch is a mirror of the components/cbor directory
+from upstream. It is automatically updated to reflect the latest changes
+in upstream.
+
+## How to update the source
+
+To pull in updates from `chromium/src`, do the following:
+
+*   `git checkout -b upstream cros/upstream/master`
+*   `git checkout master`
+*   `git merge --allow-unrelated-histories upstream`
+    *   Expect merge conflicts, because of the difference in header paths.
+    *	OWNERS should use the version from master.
+    *	BUILD.gn should mostly use the version from master, unless the upstream changes
+        the files to be built.
+    *	The #include paths should use the version from master (without "components/"). This
+        should be the majority of the merge conflicts.
+    *	In the commit message of the merge, list the changes from upstream that are merged,
+        with original commit hash from upstream.
+    *	Check the changes introduced by your merge by doing a diff against the commit
+        before the merge. The difference should be the same as the changes in the upstream.
diff --git a/cbor_export.h b/cbor_export.h
index 1b932e6..54398f0 100644
--- a/cbor_export.h
+++ b/cbor_export.h
@@ -1,9 +1,9 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
+// Copyright 2017 The Chromium OS Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#ifndef COMPONENTS_CBOR_CBOR_EXPORT_H_
-#define COMPONENTS_CBOR_CBOR_EXPORT_H_
+#ifndef CBOR_CBOR_EXPORT_H_
+#define CBOR_CBOR_EXPORT_H_
 
 #if defined(COMPONENT_BUILD)
 #if defined(WIN32)
@@ -26,4 +26,4 @@
 #define CBOR_EXPORT
 #endif
 
-#endif  // COMPONENTS_CBOR_CBOR_EXPORT_H_
+#endif  // CBOR_CBOR_EXPORT_H_
diff --git a/constants.h b/constants.h
index 2df971d..1d1ab97 100644
--- a/constants.h
+++ b/constants.h
@@ -1,9 +1,9 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
+// Copyright 2017 The Chromium OS Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#ifndef COMPONENTS_CBOR_CONSTANTS_H_
-#define COMPONENTS_CBOR_CONSTANTS_H_
+#ifndef CBOR_CONSTANTS_H_
+#define CBOR_CONSTANTS_H_
 
 #include <stdint.h>
 
@@ -34,4 +34,4 @@
 }  // namespace constants
 }  // namespace cbor
 
-#endif  // COMPONENTS_CBOR_CONSTANTS_H_
+#endif  // CBOR_CONSTANTS_H_
diff --git a/diagnostic_writer.cc b/diagnostic_writer.cc
index 074f4b8..1f1404c 100644
--- a/diagnostic_writer.cc
+++ b/diagnostic_writer.cc
@@ -1,8 +1,8 @@
-// Copyright 2019 The Chromium Authors. All rights reserved.
+// Copyright 2019 The Chromium OS Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include "components/cbor/diagnostic_writer.h"
+#include "cbor/diagnostic_writer.h"
 
 #include <string>
 
@@ -10,8 +10,8 @@
 #include "base/notreached.h"
 #include "base/numerics/clamped_math.h"
 #include "base/strings/string_number_conversions.h"
-#include "components/cbor/constants.h"
-#include "components/cbor/values.h"
+#include "cbor/constants.h"
+#include "cbor/values.h"
 
 using base::ClampAdd;
 using base::ClampMul;
diff --git a/diagnostic_writer.h b/diagnostic_writer.h
index 3106ee3..0b4a24b 100644
--- a/diagnostic_writer.h
+++ b/diagnostic_writer.h
@@ -1,13 +1,13 @@
-// Copyright 2019 The Chromium Authors. All rights reserved.
+// Copyright 2019 The Chromium OS Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#ifndef COMPONENTS_CBOR_DIAGNOSTIC_WRITER_H_
-#define COMPONENTS_CBOR_DIAGNOSTIC_WRITER_H_
+#ifndef CBOR_DIAGNOSTIC_WRITER_H_
+#define CBOR_DIAGNOSTIC_WRITER_H_
 
 #include <string>
 
-#include "components/cbor/cbor_export.h"
+#include "cbor/cbor_export.h"
 
 namespace cbor {
 
@@ -26,4 +26,4 @@
 
 }  // namespace cbor
 
-#endif  // COMPONENTS_CBOR_DIAGNOSTIC_WRITER_H_
+#endif  // CBOR_DIAGNOSTIC_WRITER_H_
diff --git a/diagnostic_writer_unittest.cc b/diagnostic_writer_unittest.cc
index a561275..8ae39ef 100644
--- a/diagnostic_writer_unittest.cc
+++ b/diagnostic_writer_unittest.cc
@@ -1,11 +1,11 @@
-// Copyright 2019 The Chromium Authors. All rights reserved.
+// Copyright 2019 The Chromium OS Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include "components/cbor/diagnostic_writer.h"
+#include "cbor/diagnostic_writer.h"
 
-#include "components/cbor/reader.h"
-#include "components/cbor/values.h"
+#include "cbor/reader.h"
+#include "cbor/values.h"
 
 #include "testing/gtest/include/gtest/gtest.h"
 
diff --git a/reader.cc b/reader.cc
index 9ff5385..dcfb217 100644
--- a/reader.cc
+++ b/reader.cc
@@ -1,8 +1,8 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
+// Copyright 2017 The Chromium OS Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include "components/cbor/reader.h"
+#include "cbor/reader.h"
 
 #include <math.h>
 
@@ -14,7 +14,7 @@
 #include "base/numerics/checked_math.h"
 #include "base/numerics/safe_conversions.h"
 #include "base/strings/string_util.h"
-#include "components/cbor/constants.h"
+#include "cbor/constants.h"
 
 namespace cbor {
 
diff --git a/reader.h b/reader.h
index e6f03a9..632039b 100644
--- a/reader.h
+++ b/reader.h
@@ -1,9 +1,9 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
+// Copyright 2017 The Chromium OS Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#ifndef COMPONENTS_CBOR_READER_H_
-#define COMPONENTS_CBOR_READER_H_
+#ifndef CBOR_READER_H_
+#define CBOR_READER_H_
 
 #include <stddef.h>
 
@@ -11,8 +11,8 @@
 
 #include "base/containers/span.h"
 #include "base/memory/raw_ptr.h"
-#include "components/cbor/cbor_export.h"
-#include "components/cbor/values.h"
+#include "cbor/cbor_export.h"
+#include "cbor/values.h"
 #include "third_party/abseil-cpp/absl/types/optional.h"
 
 // Concise Binary Object Representation (CBOR) decoder as defined by
@@ -215,4 +215,4 @@
 
 }  // namespace cbor
 
-#endif  // COMPONENTS_CBOR_READER_H_
+#endif  // CBOR_READER_H_
diff --git a/reader_fuzzer.cc b/reader_fuzzer.cc
index a513c20..ae12767 100644
--- a/reader_fuzzer.cc
+++ b/reader_fuzzer.cc
@@ -1,12 +1,12 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
+// Copyright 2017 The Chromium OS Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
 #include <stdint.h>
 #include <algorithm>
 
-#include "components/cbor/reader.h"  // nogncheck
-#include "components/cbor/writer.h"  // nogncheck
+#include "cbor/reader.h"  // nogncheck
+#include "cbor/writer.h"  // nogncheck
 
 namespace cbor {
 
diff --git a/reader_unittest.cc b/reader_unittest.cc
index 926f803..285c48a 100644
--- a/reader_unittest.cc
+++ b/reader_unittest.cc
@@ -1,11 +1,11 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
+// Copyright 2017 The Chromium OS Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
 #include <limits>
 #include <utility>
 
-#include "components/cbor/reader.h"
+#include "cbor/reader.h"
 
 #include "base/containers/span.h"
 #include "base/cxx17_backports.h"
diff --git a/values.cc b/values.cc
index be88f50..32d6b11 100644
--- a/values.cc
+++ b/values.cc
@@ -1,8 +1,8 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
+// Copyright 2017 The Chromium OS Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include "components/cbor/values.h"
+#include "cbor/values.h"
 
 #include <new>
 #include <utility>
@@ -12,7 +12,7 @@
 #include "base/numerics/safe_conversions.h"
 #include "base/strings/string_piece.h"
 #include "base/strings/string_util.h"
-#include "components/cbor/constants.h"
+#include "cbor/constants.h"
 
 namespace cbor {
 
diff --git a/values.h b/values.h
index b118201..46bcb81 100644
--- a/values.h
+++ b/values.h
@@ -1,9 +1,9 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
+// Copyright 2017 The Chromium OS Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#ifndef COMPONENTS_CBOR_VALUES_H_
-#define COMPONENTS_CBOR_VALUES_H_
+#ifndef CBOR_VALUES_H_
+#define CBOR_VALUES_H_
 
 #include <stdint.h>
 
@@ -15,8 +15,9 @@
 #include "base/containers/flat_map.h"
 #include "base/containers/span.h"
 #include "base/notreached.h"
+#include "base/notreached.h"
 #include "base/strings/string_piece.h"
-#include "components/cbor/cbor_export.h"
+#include "cbor/cbor_export.h"
 
 namespace cbor {
 
@@ -212,4 +213,4 @@
 
 }  // namespace cbor
 
-#endif  // COMPONENTS_CBOR_VALUES_H_
+#endif  // CBOR_VALUES_H_
diff --git a/values_unittest.cc b/values_unittest.cc
index 1276b99..8e68053 100644
--- a/values_unittest.cc
+++ b/values_unittest.cc
@@ -1,8 +1,8 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
+// Copyright 2017 The Chromium OS Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include "components/cbor/values.h"
+#include "cbor/values.h"
 
 #include <string>
 #include <utility>
diff --git a/writer.cc b/writer.cc
index 0e27a0f..2762bb3 100644
--- a/writer.cc
+++ b/writer.cc
@@ -1,8 +1,8 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
+// Copyright 2017 The Chromium OS Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include "components/cbor/writer.h"
+#include "cbor/writer.h"
 
 #include <string>
 
@@ -10,7 +10,7 @@
 #include "base/notreached.h"
 #include "base/numerics/safe_conversions.h"
 #include "base/strings/string_piece.h"
-#include "components/cbor/constants.h"
+#include "cbor/constants.h"
 
 namespace cbor {
 
diff --git a/writer.h b/writer.h
index ada13b1..b2d9ef1 100644
--- a/writer.h
+++ b/writer.h
@@ -1,9 +1,9 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
+// Copyright 2017 The Chromium OS Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#ifndef COMPONENTS_CBOR_WRITER_H_
-#define COMPONENTS_CBOR_WRITER_H_
+#ifndef CBOR_WRITER_H_
+#define CBOR_WRITER_H_
 
 #include <stddef.h>
 #include <stdint.h>
@@ -11,8 +11,8 @@
 #include <vector>
 
 #include "base/memory/raw_ptr.h"
-#include "components/cbor/cbor_export.h"
-#include "components/cbor/values.h"
+#include "cbor/cbor_export.h"
+#include "cbor/values.h"
 #include "third_party/abseil-cpp/absl/types/optional.h"
 
 // A basic Concise Binary Object Representation (CBOR) encoder as defined by
@@ -117,4 +117,4 @@
 
 }  // namespace cbor
 
-#endif  // COMPONENTS_CBOR_WRITER_H_
+#endif  // CBOR_WRITER_H_
diff --git a/writer_unittest.cc b/writer_unittest.cc
index ca6db6f..b3348a8 100644
--- a/writer_unittest.cc
+++ b/writer_unittest.cc
@@ -1,8 +1,8 @@
-// Copyright 2017 The Chromium Authors. All rights reserved.
+// Copyright 2017 The Chromium OS Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#include "components/cbor/writer.h"
+#include "cbor/writer.h"
 
 #include <limits>
 #include <string>