blob: 39e8d1f9899a021e720c8801104c020803bd2bf5 [file] [log] [blame]
Shawn Willdend67afae2014-08-19 12:36:27 -06001/*
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 "authorization_set.h"
21#include "keymaster_defs.h"
22
23namespace keymaster {
24
25class KeyBlob;
26class Operation;
27
28class Key {
29 public:
30 static Key* CreateKey(const KeyBlob& blob, keymaster_error_t* error);
31 static Key* GenerateKey(const AuthorizationSet& key_description, keymaster_error_t* error);
Shawn Willden437fbd12014-08-20 11:59:49 -060032 static Key* ImportKey(const AuthorizationSet& key_description,
33 keymaster_key_format_t key_format, const uint8_t* key_data,
34 size_t key_data_length, keymaster_error_t* error);
Shawn Willdend67afae2014-08-19 12:36:27 -060035
36 virtual ~Key() {}
37 virtual Operation* CreateOperation(keymaster_purpose_t purpose, keymaster_error_t* error) = 0;
38
39 /**
40 * Return a copy of raw key material, in the key's preferred binary format.
41 */
42 virtual keymaster_error_t key_material(UniquePtr<uint8_t[]>*, size_t* size) const = 0;
43
44 /**
45 * Return a copy of raw key material, in the specified format.
46 */
Shawn Willdenf268d742014-08-19 15:36:26 -060047 virtual keymaster_error_t formatted_key_material(keymaster_key_format_t format,
48 UniquePtr<uint8_t[]>* material,
Shawn Willdend67afae2014-08-19 12:36:27 -060049 size_t* size) const = 0;
50
51 const AuthorizationSet& authorizations() const { return authorizations_; }
52
53 protected:
54 Key(const KeyBlob& blob);
55 Key(const AuthorizationSet& authorizations) : authorizations_(authorizations) {}
56
57 private:
58 AuthorizationSet authorizations_;
59};
60
61} // namespace keymaster
62
63#endif // SYSTEM_KEYMASTER_KEY_H_