1 // 2 // Copyright (C) 2020 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 #pragma once 17 18 #include <vector> 19 20 #include "keymaster/serializable.h" 21 22 /** 23 * A keymaster::Serializable type that refers to multiple other 24 * keymaster::Serializable instances by pointer. When data is serialized or 25 * deserialized, it's delegated to the instances pointed to. 26 * 27 * The serialization format is to put the instances one after the other in 28 * the byte stream. 29 */ 30 class CompositeSerializable : public keymaster::Serializable { 31 public: 32 CompositeSerializable(const std::vector<keymaster::Serializable*>&); 33 34 size_t SerializedSize() const override; 35 uint8_t* Serialize(uint8_t* buf, const uint8_t* end) const override; 36 bool Deserialize(const uint8_t** buf_ptr, const uint8_t* end) override; 37 private: 38 std::vector<keymaster::Serializable*> members_; 39 }; 40