1 //
2 // Copyright (C) 2015 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 TRUNKS_BLOB_PARSER_H_
18 #define TRUNKS_BLOB_PARSER_H_
19 
20 #include <string>
21 
22 #include "trunks/tpm_generated.h"
23 #include "trunks/trunks_export.h"
24 
25 namespace trunks {
26 
27 class TRUNKS_EXPORT BlobParser {
28  public:
29   BlobParser() = default;
30   virtual ~BlobParser() = default;
31 
32   // This method is used to construct a |key_blob| given the associated key's
33   // TPM2B_PUBLIC and TPM2B_PRIVATE structs. Returns true on successful
34   // serialization, else false.
35   virtual bool SerializeKeyBlob(const TPM2B_PUBLIC& public_info,
36                                 const TPM2B_PRIVATE& private_info,
37                                 std::string* key_blob);
38 
39   // This method returns the Public and Private structs associated with a given
40   // |key_blob|. Returns true on success, else false.
41   virtual bool ParseKeyBlob(const std::string& key_blob,
42                             TPM2B_PUBLIC* public_info,
43                             TPM2B_PRIVATE* private_info);
44 
45   // This method is used to construct a |creation_blob| given the associated
46   // key's |creation_data|, |creation_hash| and |creation_ticket| structs.
47   // Returns true on successful serializtion, else false.
48   virtual bool SerializeCreationBlob(const TPM2B_CREATION_DATA& creation_data,
49                                      const TPM2B_DIGEST& creation_hash,
50                                      const TPMT_TK_CREATION& creation_ticket,
51                                      std::string* creation_blob);
52 
53   // This method returns the creation structures associated with a given
54   // |creation_blob|. Returns true on success, else false.
55   virtual bool ParseCreationBlob(const std::string& creation_blob,
56                                  TPM2B_CREATION_DATA* creation_data,
57                                  TPM2B_DIGEST* creation_hash,
58                                  TPMT_TK_CREATION* creation_ticket);
59 
60  private:
61   DISALLOW_COPY_AND_ASSIGN(BlobParser);
62 };
63 
64 }  // namespace trunks
65 
66 #endif  // TRUNKS_BLOB_PARSER_H_
67