Home | History | Annotate | Download | only in keymaster
      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 <UniquePtr.h>
     21 
     22 #include <hardware/keymaster_defs.h>
     23 #include <keymaster/authorization_set.h>
     24 
     25 namespace keymaster {
     26 
     27 class Key {
     28   public:
     29     virtual ~Key() {}
     30 
     31     /**
     32      * Return a copy of raw key material, in the key's preferred binary format.
     33      */
     34     virtual keymaster_error_t key_material(UniquePtr<uint8_t[]>*, size_t* size) const = 0;
     35 
     36     /**
     37      * Return a copy of raw key material, in the specified format.
     38      */
     39     virtual keymaster_error_t formatted_key_material(keymaster_key_format_t format,
     40                                                      UniquePtr<uint8_t[]>* material,
     41                                                      size_t* size) const = 0;
     42 
     43     const AuthorizationSet& authorizations() const { return authorizations_; }
     44 
     45   protected:
     46     Key(const AuthorizationSet& hw_enforced, const AuthorizationSet& sw_enforced,
     47         keymaster_error_t* error);
     48 
     49   private:
     50     AuthorizationSet authorizations_;
     51 };
     52 
     53 }  // namespace keymaster
     54 
     55 #endif  // SYSTEM_KEYMASTER_KEY_H_
     56