blob: ea8603a585d7ef5469daf9d33e72716b9a8c4086 [file] [log] [blame]
Yi Jin99c248f2017-08-25 18:11:58 -07001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ENCODED_BUFFER_H
18#define ENCODED_BUFFER_H
19
20#include "FdBuffer.h"
21#include "Privacy.h"
22
23#include <stdint.h>
24#include <vector>
25
26/**
27 * EncodedBuffer is constructed from FdBuffer which holds original protobuf formatted data and
28 * its privacy policy in its tagged proto message. The class strips PII-sensitive fields
29 * based on the request and holds stripped data in its buffer for output.
30 */
31class EncodedBuffer
32{
33public:
34 EncodedBuffer(const FdBuffer& buffer, const Privacy* policy);
35 ~EncodedBuffer();
36
37 /**
38 * Strip based on the request and hold data in its own buffer. Return NO_ERROR if strip succeeds.
39 */
40 status_t strip(const PrivacySpec& spec);
41
42 /**
43 * Clear encoded buffer so it can be reused by another request.
44 */
45 void clear();
46
47 /**
48 * Return the size of the stripped data.
49 */
50 size_t size() const;
51
52 /**
53 * Flush buffer to the given fd. NO_ERROR is returned if the flush succeeds.
54 */
55 status_t flush(int fd);
56
57private:
58 const FdBuffer& mFdBuffer;
59 const Privacy* mPolicy;
60 vector<vector<uint8_t>> mBuffers;
61 size_t mSize;
62};
63
64#endif // ENCODED_BUFFER_H