123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- #ifndef ANDROID_VOLD_KEYBUFFER_H
- #define ANDROID_VOLD_KEYBUFFER_H
- #include <cstring>
- #include <memory>
- #include <vector>
- namespace android {
- namespace vold {
- #ifdef __clang__
- #define OPTNONE __attribute__((optnone))
- #else
- #define OPTNONE __attribute__((optimize("O0")))
- #endif
- inline OPTNONE void* memset_s(void* s, int c, size_t n) {
- if (!s) return s;
- return memset(s, c, n);
- }
- #undef OPTNONE
- class ZeroingAllocator : public std::allocator<char> {
- public:
- void deallocate(pointer p, size_type n) {
- memset_s(p, 0, n);
- std::allocator<char>::deallocate(p, n);
- }
- };
- using KeyBuffer = std::vector<char, ZeroingAllocator>;
- KeyBuffer operator+(KeyBuffer&& lhs, const KeyBuffer& rhs);
- KeyBuffer operator+(KeyBuffer&& lhs, const char* rhs);
- }
- }
- #endif
|