Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 77d6f591 authored by Arman Uguray's avatar Arman Uguray
Browse files

service: Remove local copies of base and modp_b64

Since libbase is now available on AOSP (under libchrome) Bluetooth code can
depend on it rather than maintain its own copy a subset of base sources (and
modp_b64 dependencies).

Dependent CL: http://r.android.com/158335

Bug: 22175181
Change-Id: I3a301e49353598633ad857ac4345d0361c273beb
parent c2465add
Loading
Loading
Loading
Loading
+11 −20
Original line number Diff line number Diff line
@@ -16,19 +16,6 @@

LOCAL_PATH:= $(call my-dir)

BASE_SRC := \
	base/base64.cpp \
	base/string_split.cpp \
	base/string_number_conversions.cpp \
	modp_b64/modp_b64.cpp

CORE_SRC := \
	a2dp_source.cpp \
	logging_helpers.cpp \
	core_stack.cpp \
	uuid.cpp \
	gatt_server.cpp

include $(CLEAR_VARS)
LOCAL_SRC_FILES := uuid_test.cpp uuid.cpp
LOCAL_CFLAGS += -std=c++11
@@ -39,10 +26,13 @@ include $(BUILD_HOST_NATIVE_TEST)
include $(CLEAR_VARS)

LOCAL_SRC_FILES := \
    $(BASE_SRC) \
    $(CORE_SRC) \
	a2dp_source.cpp \
	core_stack.cpp \
	gatt_server.cpp \
	host.cpp \
    main.cpp
	logging_helpers.cpp \
	main.cpp \
	uuid.cpp

LOCAL_C_INCLUDES += \
        $(LOCAL_PATH)/../
@@ -52,8 +42,9 @@ LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := bthost
LOCAL_REQUIRED_MODULES = bluetooth.default
LOCAL_SHARED_LIBRARIES += \
    libhardware \
	libchrome \
	libcutils \
	libhardware \
	liblog

include $(BUILD_EXECUTABLE)

system/service/base/base64.cpp

deleted100644 → 0
+0 −37
Original line number Diff line number Diff line
// Copyright (c) 2012 The Chromium 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 "base/base64.h"

#include "modp_b64/modp_b64.h"

namespace base {

void Base64Encode(const std::string& input, std::string* output) {
  std::string temp;
  temp.resize(modp_b64_encode_len(input.size()));  // makes room for null byte

  // modp_b64_encode_len() returns at least 1, so temp[0] is safe to use.
  size_t output_size = modp_b64_encode(&(temp[0]), input.data(), input.size());

  temp.resize(output_size);  // strips off null byte
  output->swap(temp);
}

bool Base64Decode(const std::string& input, std::string* output) {
  std::string temp;
  temp.resize(modp_b64_decode_len(input.size()));

  // does not null terminate result since result is binary data!
  size_t input_size = input.size();
  size_t output_size = modp_b64_decode(&(temp[0]), input.data(), input_size);
  if (output_size == MODP_B64_ERROR)
    return false;

  temp.resize(output_size);
  output->swap(temp);
  return true;
}

}  // namespace base

system/service/base/base64.h

deleted100644 → 0
+0 −22
Original line number Diff line number Diff line
// Copyright (c) 2011 The Chromium 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 BASE_BASE64_H__
#define BASE_BASE64_H__

#include <string>

namespace base {

// Encodes the input string in base64. The encoding can be done in-place.
void Base64Encode(const std::string& input, std::string* output);

// Decodes the base64 input string.  Returns true if successful and false
// otherwise. The output string is only modified if successful. The decoding can
// be done in-place.
bool Base64Decode(const std::string& input, std::string* output);

}  // namespace base

#endif  // BASE_BASE64_H__
+0 −87
Original line number Diff line number Diff line
// Copyright (c) 2012 The Chromium 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 "base/string_number_conversions.h"

#include <stdlib.h>

#include <limits>

namespace base {

// Utility to convert a character to a digit in a given base
template<typename CHAR, int BASE, bool BASE_LTE_10> class BaseCharToDigit {
};

// Faster specialization for bases <= 10
template<typename CHAR, int BASE> class BaseCharToDigit<CHAR, BASE, true> {
 public:
  static bool Convert(CHAR c, uint8_t* digit) {
    if (c >= '0' && c < '0' + BASE) {
      *digit = static_cast<uint8_t>(c - '0');
      return true;
    }
    return false;
  }
};

// Specialization for bases where 10 < base <= 36
template<typename CHAR, int BASE> class BaseCharToDigit<CHAR, BASE, false> {
 public:
  static bool Convert(CHAR c, uint8_t* digit) {
    if (c >= '0' && c <= '9') {
      *digit = c - '0';
    } else if (c >= 'a' && c < 'a' + BASE - 10) {
      *digit = c - 'a' + 10;
    } else if (c >= 'A' && c < 'A' + BASE - 10) {
      *digit = c - 'A' + 10;
    } else {
      return false;
    }
    return true;
  }
};

template<int BASE, typename CHAR> bool CharToDigit(CHAR c, uint8_t* digit) {
  return BaseCharToDigit<CHAR, BASE, BASE <= 10>::Convert(c, digit);
}

template<typename STR>
bool HexStringToBytesT(const STR& input, std::vector<uint8_t>* output) {
  output->clear();
  size_t count = input.size();
  if (count == 0 || (count % 2) != 0)
    return false;
  for (uintptr_t i = 0; i < count / 2; ++i) {
    uint8_t msb = 0;  // most significant 4 bits
    uint8_t lsb = 0;  // least significant 4 bits
    if (!CharToDigit<16>(input[i * 2], &msb) ||
        !CharToDigit<16>(input[i * 2 + 1], &lsb))
      return false;
    output->push_back((msb << 4) | lsb);
  }
  return true;
}


std::string HexEncode(const void* bytes, size_t size) {
  static const char kHexChars[] = "0123456789ABCDEF";

  // Each input byte creates two output hex characters.
  std::string ret(size * 2, '\0');

  for (size_t i = 0; i < size; ++i) {
    char b = reinterpret_cast<const char*>(bytes)[i];
    ret[(i * 2)] = kHexChars[(b >> 4) & 0xf];
    ret[(i * 2) + 1] = kHexChars[b & 0xf];
  }
  return ret;
}


bool HexStringToBytes(const std::string& input, std::vector<uint8_t>* output) {
  return HexStringToBytesT(input, output);
}

}  // namespace base
+0 −32
Original line number Diff line number Diff line
// Copyright (c) 2012 The Chromium 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 BASE_STRINGS_STRING_NUMBER_CONVERSIONS_H_
#define BASE_STRINGS_STRING_NUMBER_CONVERSIONS_H_

#include <string>
#include <vector>

namespace base {

// Hex encoding ----------------------------------------------------------------

// Returns a hex string representation of a binary buffer. The returned hex
// string will be in upper case. This function does not check if |size| is
// within reasonable limits since it's written with trusted data in mind.  If
// you suspect that the data you want to format might be large, the absolute
// max size for |size| should be is
//   std::numeric_limits<size_t>::max() / 2
std::string HexEncode(const void* bytes, size_t size);

// Similar to the previous functions, except that output is a vector of bytes.
// |*output| will contain as many bytes as were successfully parsed prior to the
// error.  There is no overflow, but input.size() must be evenly divisible by 2.
// Leading 0x or +/- are not allowed.
bool HexStringToBytes(const std::string& input,
                      std::vector<uint8_t>* output);

}  // namespace base

#endif  // BASE_STRINGS_STRING_NUMBER_CONVERSIONS_H_
Loading