| /* |
| * Copyright (C) 2017 The Android Open Source Project |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| |
| #ifndef ENCODED_BUFFER_H |
| #define ENCODED_BUFFER_H |
| |
| #include "FdBuffer.h" |
| #include "Privacy.h" |
| |
| #include <stdint.h> |
| #include <vector> |
| |
| /** |
| * EncodedBuffer is constructed from FdBuffer which holds original protobuf formatted data and |
| * its privacy policy in its tagged proto message. The class strips PII-sensitive fields |
| * based on the request and holds stripped data in its buffer for output. |
| */ |
| class EncodedBuffer |
| { |
| public: |
| EncodedBuffer(const FdBuffer& buffer, const Privacy* policy); |
| ~EncodedBuffer(); |
| |
| /** |
| * Strip based on the request and hold data in its own buffer. Return NO_ERROR if strip succeeds. |
| */ |
| status_t strip(const PrivacySpec& spec); |
| |
| /** |
| * Clear encoded buffer so it can be reused by another request. |
| */ |
| void clear(); |
| |
| /** |
| * Return the size of the stripped data. |
| */ |
| size_t size() const; |
| |
| /** |
| * Flush buffer to the given fd. NO_ERROR is returned if the flush succeeds. |
| */ |
| status_t flush(int fd); |
| |
| private: |
| const FdBuffer& mFdBuffer; |
| const Privacy* mPolicy; |
| vector<vector<uint8_t>> mBuffers; |
| size_t mSize; |
| }; |
| |
| #endif // ENCODED_BUFFER_H |