aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Bonné <brambonne@google.com>2020-10-20 16:40:52 +0200
committerBram Bonné <brambonne@google.com>2020-10-21 11:59:10 +0200
commitf04333a4b1f00ad29bc6828854ed17c34e78901b (patch)
tree78b1e8469b084dc55846ba8f23260bb04b5c0428
parentf3ebf71e14186be9b881bc1d111ebab3b0b93f06 (diff)
downloadlibcppbor-f04333a4b1f00ad29bc6828854ed17c34e78901b.tar.gz
Add Trusty support to libcppbor.
Add a rules.mk file to libcppbor to allow Trusty to depend on it. Additionally, remove dependency on the Android logging framework when running in the Trusty environment, and remove dependencies on stringstream to improve portability. Bug: 171373138 Test: trusty/vendor/google/aosp/scripts/build.py generic-arm64-test-debug Test: m -j Change-Id: I7a01db28e6bf448886f4a7a1a4dea02d569493c9
-rw-r--r--rules.mk29
-rw-r--r--src/cppbor.cpp10
-rw-r--r--src/cppbor_parse.cpp17
3 files changed, 46 insertions, 10 deletions
diff --git a/rules.mk b/rules.mk
new file mode 100644
index 0000000..739fe23
--- /dev/null
+++ b/rules.mk
@@ -0,0 +1,29 @@
+# Copyright (C) 2020 The Android Open Source Project.
+#
+# Permission to use, copy, modify, and/or distribute this software for any
+# purpose with or without fee is hereby granted, provided that the above
+# copyright notice and this permission notice appear in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+# SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+# OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+# This file is not used in the Android build process! It's used only by Trusty.
+
+LOCAL_DIR := $(GET_LOCAL_DIR)
+
+MODULE := $(LOCAL_DIR)
+
+MODULE_CPPFLAGS := -std=c++17 -frtti
+
+MODULE_SRCS := \
+ $(LOCAL_DIR)/src/cppbor.cpp \
+ $(LOCAL_DIR)/src/cppbor_parse.cpp
+
+GLOBAL_INCLUDES += $(LOCAL_DIR)/include/cppbor/
+
+include make/module.mk \ No newline at end of file
diff --git a/src/cppbor.cpp b/src/cppbor.cpp
index 25c2da1..223a445 100644
--- a/src/cppbor.cpp
+++ b/src/cppbor.cpp
@@ -16,8 +16,12 @@
#include "cppbor.h"
-#define LOG_TAG "CppBor"
-#include <android-base/logging.h>
+#ifndef __TRUSTY__
+ #include <android-base/logging.h>
+ #define LOG_TAG "CppBor"
+#else
+ #define CHECK(x) (void)(x)
+#endif
namespace cppbor {
@@ -129,7 +133,7 @@ bool Item::operator==(const Item& other) const& {
}
Nint::Nint(int64_t v) : mValue(v) {
- CHECK(v < 0) << "Only negative values allowed";
+ CHECK(v < 0);
}
bool Simple::operator==(const Simple& other) const& {
diff --git a/src/cppbor_parse.cpp b/src/cppbor_parse.cpp
index 6da0036..5cffe15 100644
--- a/src/cppbor_parse.cpp
+++ b/src/cppbor_parse.cpp
@@ -16,11 +16,14 @@
#include "cppbor_parse.h"
-#include <sstream>
#include <stack>
-#define LOG_TAG "CppBor"
-#include <android-base/logging.h>
+#ifndef __TRUSTY__
+ #include <android-base/logging.h>
+ #define LOG_TAG "CppBor"
+#else
+ #define CHECK(x) (void)(x)
+#endif
namespace cppbor {
@@ -28,10 +31,10 @@ namespace {
std::string insufficientLengthString(size_t bytesNeeded, size_t bytesAvail,
const std::string& type) {
- std::stringstream errStream;
- errStream << "Need " << bytesNeeded << " byte(s) for " << type << ", have " << bytesAvail
- << ".";
- return errStream.str();
+ char buf[1024];
+ snprintf(buf, sizeof(buf), "Need %zu byte(s) for %s, have %zu",
+ bytesNeeded, type.c_str(), bytesAvail);
+ return std::string(buf);
}
template <typename T, typename = std::enable_if_t<std::is_unsigned_v<T>>>