blob: fe53c29fc0184ddb1940f442ac841c1af6768879 [file] [log] [blame]
Dmitry Dementyeva447b3c2017-10-27 23:09:53 -07001/*
2**
3** Copyright 2017, The Android Open Source Project
4**
5** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
8**
9** http://www.apache.org/licenses/LICENSE-2.0
10**
11** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
15** limitations under the License.
16*/
17
18#include "include/keystore/KeystoreArguments.h"
19#include "keystore_aidl_hidl_marshalling_utils.h"
20
21#include <binder/Parcel.h>
22
23namespace android {
24namespace security {
25
26using ::android::security::KeystoreArg;
27using ::android::security::KeystoreArguments;
28
29const ssize_t MAX_GENERATE_ARGS = 3;
30status_t KeystoreArguments::readFromParcel(const android::Parcel* in) {
31 ssize_t numArgs = in->readInt32();
32 if (numArgs > MAX_GENERATE_ARGS) {
33 return BAD_VALUE;
34 }
35 if (numArgs > 0) {
36 for (size_t i = 0; i < static_cast<size_t>(numArgs); i++) {
37 ssize_t inSize = in->readInt32();
38 if (inSize >= 0 && static_cast<size_t>(inSize) <= in->dataAvail()) {
39 sp<KeystoreArg> arg = new KeystoreArg(in->readInplace(inSize), inSize);
40 args.push_back(arg);
41 } else {
42 args.push_back(NULL);
43 }
44 }
45 }
46 return OK;
47};
48
49status_t KeystoreArguments::writeToParcel(android::Parcel* out) const {
50 out->writeInt32(args.size());
51 for (sp<KeystoreArg> item : args) {
52 size_t keyLength = item->size();
53 out->writeInt32(keyLength);
54 void* buf = out->writeInplace(keyLength);
55 memcpy(buf, item->data(), keyLength);
56 }
57 return OK;
58}
59
60} // namespace security
61} // namespace android