• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2014 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 SYSTEM_KEYMASTER_KEY_H_
18 #define SYSTEM_KEYMASTER_KEY_H_
19 
20 #include <keymaster/authorization_set.h>
21 #include <keymaster/keymaster_defs.h>
22 #include <keymaster/logger.h>
23 
24 namespace keymaster {
25 
26 class KeyBlob;
27 class Operation;
28 
29 class Key {
30   public:
31     static Key* CreateKey(const KeyBlob& blob, const Logger& logger, keymaster_error_t* error);
32     static Key* GenerateKey(const AuthorizationSet& key_description, const Logger& logger,
33                             keymaster_error_t* error);
34     static Key* ImportKey(const AuthorizationSet& key_description,
35                           keymaster_key_format_t key_format, const uint8_t* key_data,
36                           size_t key_data_length, const Logger& logger, keymaster_error_t* error);
37 
~Key()38     virtual ~Key() {}
39     virtual Operation* CreateOperation(keymaster_purpose_t purpose, keymaster_error_t* error) = 0;
40 
41     /**
42      * Return a copy of raw key material, in the key's preferred binary format.
43      */
44     virtual keymaster_error_t key_material(UniquePtr<uint8_t[]>*, size_t* size) const = 0;
45 
46     /**
47      * Return a copy of raw key material, in the specified format.
48      */
49     virtual keymaster_error_t formatted_key_material(keymaster_key_format_t format,
50                                                      UniquePtr<uint8_t[]>* material,
51                                                      size_t* size) const = 0;
52 
authorizations()53     const AuthorizationSet& authorizations() const { return authorizations_; }
54 
55   protected:
56     Key(const KeyBlob& blob, const Logger& logger);
Key(const AuthorizationSet & authorizations,const Logger & logger)57     Key(const AuthorizationSet& authorizations, const Logger& logger)
58         : logger_(logger), authorizations_(authorizations) {}
59 
60     const Logger& logger_;
61 
62   private:
63     AuthorizationSet authorizations_;
64 };
65 
66 }  // namespace keymaster
67 
68 #endif  // SYSTEM_KEYMASTER_KEY_H_
69