Home | History | Annotate | Download | only in keymaster
      1 /*
      2  * Copyright 2017 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 ANDROID_HARDWARE_KEYMASTER_PROTO_UTILS_H
     18 #define ANDROID_HARDWARE_KEYMASTER_PROTO_UTILS_H
     19 
     20 #include <android/hardware/keymaster/4.0/IKeymasterDevice.h>
     21 
     22 #include <Keymaster.client.h>
     23 
     24 #include <map>
     25 #include <vector>
     26 
     27 namespace android {
     28 namespace hardware {
     29 namespace keymaster {
     30 
     31 // HAL
     32 using ::android::hardware::keymaster::V4_0::Algorithm;
     33 using ::android::hardware::keymaster::V4_0::EcCurve;
     34 using ::android::hardware::keymaster::V4_0::ErrorCode;
     35 using ::android::hardware::keymaster::V4_0::HardwareAuthToken;
     36 using ::android::hardware::keymaster::V4_0::KeyParameter;
     37 using ::android::hardware::keymaster::V4_0::SecurityLevel;
     38 using ::android::hardware::keymaster::V4_0::Tag;
     39 using ::android::hardware::keymaster::V4_0::VerificationToken;
     40 using ::android::hardware::hidl_vec;
     41 
     42 // std
     43 using std::map;
     44 using std::vector;
     45 
     46 // App
     47 namespace nosapp = nugget::app::keymaster;
     48 
     49 typedef map<Tag, vector<KeyParameter>> tag_map_t;
     50 
     51 ErrorCode key_parameter_to_pb(const KeyParameter& param,
     52                               nosapp::KeyParameter *pb);
     53 ErrorCode hidl_params_to_pb(const hidl_vec<KeyParameter>& params,
     54                             nosapp::KeyParameters *pbParams);
     55 ErrorCode hidl_params_to_map(const hidl_vec<KeyParameter>& params,
     56                              tag_map_t *tag_map);
     57 ErrorCode map_params_to_pb(const tag_map_t& params,
     58                            nosapp::KeyParameters *pbParams);
     59 ErrorCode pb_to_hidl_params(const nosapp::KeyParameters& pbParams,
     60                             hidl_vec<KeyParameter> *params);
     61 ErrorCode translate_algorithm(nosapp::Algorithm algorithm,
     62                               Algorithm *out);
     63 ErrorCode translate_error_code(nosapp::ErrorCode error_code);
     64 ErrorCode translate_ec_curve(nosapp::EcCurve ec_curve, EcCurve *out);
     65 ErrorCode translate_auth_token(const HardwareAuthToken& auth_token,
     66                           nosapp::HardwareAuthToken *out);
     67 void translate_verification_token(
     68     const VerificationToken& verification_token,
     69     nosapp::VerificationToken *out);
     70 
     71 }  // namespace keymaster
     72 }  // hardware
     73 }  // android
     74 
     75 #endif  // ANDROID_HARDWARE_KEYMASTER_PROTO_UTILS_H
     76