summaryrefslogtreecommitdiffstats
path: root/security/nss/cpputil/databuffer.h
diff options
context:
space:
mode:
authorwolfbeast <mcwerewolf@gmail.com>2018-04-25 21:33:33 +0200
committerwolfbeast <mcwerewolf@gmail.com>2018-04-25 21:33:33 +0200
commitfba28f19754f62b5227650143d5441fc86d4c7d7 (patch)
tree26629d73f83543ff92a060fd7b310bb748b13173 /security/nss/cpputil/databuffer.h
parentb4154e043bfc0d2f301d88304efc896989d650bf (diff)
downloadUXP-fba28f19754f62b5227650143d5441fc86d4c7d7.tar
UXP-fba28f19754f62b5227650143d5441fc86d4c7d7.tar.gz
UXP-fba28f19754f62b5227650143d5441fc86d4c7d7.tar.lz
UXP-fba28f19754f62b5227650143d5441fc86d4c7d7.tar.xz
UXP-fba28f19754f62b5227650143d5441fc86d4c7d7.zip
Revert "Update NSS to 3.35-RTM"
This reverts commit f1a0f0a56fdd0fc39f255174ce08c06b91c66c94.
Diffstat (limited to 'security/nss/cpputil/databuffer.h')
-rw-r--r--security/nss/cpputil/databuffer.h110
1 files changed, 0 insertions, 110 deletions
diff --git a/security/nss/cpputil/databuffer.h b/security/nss/cpputil/databuffer.h
deleted file mode 100644
index 58e07efe1..000000000
--- a/security/nss/cpputil/databuffer.h
+++ /dev/null
@@ -1,110 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* vim: set ts=2 et sw=2 tw=80: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef databuffer_h__
-#define databuffer_h__
-
-#include <algorithm>
-#include <cstring>
-#include <iomanip>
-#include <iostream>
-
-namespace nss_test {
-
-class DataBuffer {
- public:
- DataBuffer() : data_(nullptr), len_(0) {}
- DataBuffer(const uint8_t* data, size_t len) : data_(nullptr), len_(0) {
- Assign(data, len);
- }
- DataBuffer(const DataBuffer& other) : data_(nullptr), len_(0) {
- Assign(other);
- }
- ~DataBuffer() { delete[] data_; }
-
- DataBuffer& operator=(const DataBuffer& other) {
- if (&other != this) {
- Assign(other);
- }
- return *this;
- }
-
- void Allocate(size_t len) {
- delete[] data_;
- data_ = new uint8_t[len ? len : 1]; // Don't depend on new [0].
- len_ = len;
- }
-
- void Truncate(size_t len) { len_ = (std::min)(len_, len); }
-
- void Assign(const DataBuffer& other) { Assign(other.data(), other.len()); }
-
- void Assign(const uint8_t* data, size_t len);
-
- // Write will do a new allocation and expand the size of the buffer if needed.
- // Returns the offset of the end of the write.
- size_t Write(size_t index, const uint8_t* val, size_t count);
- size_t Write(size_t index, const DataBuffer& buf) {
- return Write(index, buf.data(), buf.len());
- }
-
- // Write an integer, also performing host-to-network order conversion.
- // Returns the offset of the end of the write.
- size_t Write(size_t index, uint32_t val, size_t count);
-
- // Starting at |index|, remove |remove| bytes and replace them with the
- // contents of |buf|.
- void Splice(const DataBuffer& buf, size_t index, size_t remove = 0) {
- Splice(buf.data(), buf.len(), index, remove);
- }
-
- void Splice(const uint8_t* ins, size_t ins_len, size_t index,
- size_t remove = 0);
- void Append(const DataBuffer& buf) { Splice(buf, len_); }
-
- bool Read(size_t index, size_t count, uint64_t* val) const;
- bool Read(size_t index, size_t count, uint32_t* val) const;
-
- const uint8_t* data() const { return data_; }
- uint8_t* data() { return data_; }
- size_t len() const { return len_; }
- bool empty() const { return len_ == 0; }
-
- static void SetLogLimit(size_t limit);
- friend std::ostream& operator<<(std::ostream& stream, const DataBuffer& buf);
-
- private:
- static size_t logging_limit;
- uint8_t* data_;
- size_t len_;
-};
-
-inline std::ostream& operator<<(std::ostream& stream, const DataBuffer& buf) {
- stream << "[" << buf.len() << "] ";
- for (size_t i = 0; i < buf.len(); ++i) {
- if (i >= DataBuffer::logging_limit) {
- stream << "...";
- break;
- }
- stream << std::hex << std::setfill('0') << std::setw(2)
- << static_cast<unsigned>(buf.data()[i]);
- }
- stream << std::dec;
- return stream;
-}
-
-inline bool operator==(const DataBuffer& a, const DataBuffer& b) {
- return (a.empty() && b.empty()) ||
- (a.len() == b.len() && 0 == memcmp(a.data(), b.data(), a.len()));
-}
-
-inline bool operator!=(const DataBuffer& a, const DataBuffer& b) {
- return !(a == b);
-}
-
-} // namespace nss_test
-
-#endif