/usr/include/x86_64-linux-gnu/qcc/SecureAllocator.h is in liballjoyn-common-dev-1604 16.04a-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | /**
* @file
*
* Custom allocator for STL container that will securely delete
* contents on memory deletion.
*/
/******************************************************************************
* Copyright AllSeen Alliance. All rights reserved.
*
* 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.
******************************************************************************/
#ifndef _QCC_SECUREALLOCATOR_H
#define _QCC_SECUREALLOCATOR_H
#include <qcc/platform.h>
#include <cstddef>
#include <memory>
#include <qcc/Util.h>
namespace qcc {
/**
* This class is an allocator that may be used by any STL container where there
* is a need to ensure that the contained data is securely deleted when the
* memory gets deallocated.
*/
template <class T>
class SecureAllocator : public std::allocator<T> {
public:
typedef std::size_t size_type; ///< typedef conforming to STL usage
typedef T* pointer; ///< typedef conforming to STL usage
typedef const T* const_pointer; ///< typedef conforming to STL usage
/**
* A class that enables an allocator for objects of one type to create
* storage for another type.
*/
template <typename U>
struct rebind {
typedef SecureAllocator<U> other;
};
/** Constructor */
SecureAllocator() : std::allocator<T>() { }
/** Copy Constructor */
SecureAllocator(const SecureAllocator& a) : std::allocator<T>(a) { }
/** Copy Constructor */
template <typename U>
SecureAllocator(const SecureAllocator<U>& a) : std::allocator<T>(a) { }
/** Destructor */
virtual ~SecureAllocator() { }
/** Allocate memory */
virtual pointer allocate(size_type n, const_pointer hint = 0) {
return std::allocator<T>::allocate(n, hint);
}
/** Deallocate memory, but securely wipe it out first. */
virtual void deallocate(pointer p, size_type n) {
ClearMemory(p, n * sizeof(T));
std::allocator<T>::deallocate(p, n);
}
};
/**
* Append the contents of a string to a vector<uint8_t, SecureAllocator<uint8_t> >.
*
* @param str String to be added.
* @param v Vector to be added to.
*/
void AJ_CALL AppendStringToSecureVector(const qcc::String& str, std::vector<uint8_t, SecureAllocator<uint8_t> >& v);
}
#endif // _QCC_SECUREALLOCATOR_H
|