blob: 720b38e7dae868272ddc094bac5a02a2bb10b29d [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
Yi Jinc23fad22017-09-15 17:24:59 -070017#ifndef PRIVACY_BUFFER_H
18#define PRIVACY_BUFFER_H
Yi Jin99c248f2017-08-25 18:11:58 -070019
Yi Jin99c248f2017-08-25 18:11:58 -070020#include "Privacy.h"
21
Yi Jinc23fad22017-09-15 17:24:59 -070022#include <android/util/EncodedBuffer.h>
Yi Jin99c248f2017-08-25 18:11:58 -070023#include <stdint.h>
Yi Jinc23fad22017-09-15 17:24:59 -070024#include <utils/Errors.h>
25
26using namespace android;
27using namespace android::util;
Yi Jin99c248f2017-08-25 18:11:58 -070028
29/**
Yi Jinc23fad22017-09-15 17:24:59 -070030 * PrivacyBuffer holds the original protobuf data and strips PII-sensitive fields
31 * based on the request and holds stripped data in its own buffer for output.
Yi Jin99c248f2017-08-25 18:11:58 -070032 */
Yi Jinc23fad22017-09-15 17:24:59 -070033class PrivacyBuffer
Yi Jin99c248f2017-08-25 18:11:58 -070034{
35public:
Yi Jinc23fad22017-09-15 17:24:59 -070036 PrivacyBuffer(const Privacy* policy, EncodedBuffer::iterator& data);
37 ~PrivacyBuffer();
Yi Jin99c248f2017-08-25 18:11:58 -070038
39 /**
40 * Strip based on the request and hold data in its own buffer. Return NO_ERROR if strip succeeds.
41 */
42 status_t strip(const PrivacySpec& spec);
43
44 /**
45 * Clear encoded buffer so it can be reused by another request.
46 */
47 void clear();
48
49 /**
50 * Return the size of the stripped data.
51 */
52 size_t size() const;
53
54 /**
55 * Flush buffer to the given fd. NO_ERROR is returned if the flush succeeds.
56 */
57 status_t flush(int fd);
58
59private:
Yi Jin99c248f2017-08-25 18:11:58 -070060 const Privacy* mPolicy;
Yi Jinc23fad22017-09-15 17:24:59 -070061 EncodedBuffer::iterator& mData;
62
63 EncodedBuffer mBuffer;
Yi Jin99c248f2017-08-25 18:11:58 -070064 size_t mSize;
65};
66
Yi Jinc23fad22017-09-15 17:24:59 -070067#endif // PRIVACY_BUFFER_H