1 /*
2  * Copyright (C) 2020 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 #include "CryptoType.h"
18 
19 #include <string.h>
20 
21 #include <android-base/logging.h>
22 #include <cutils/properties.h>
23 
24 namespace android {
25 namespace vold {
26 
lookup_crypto_algorithm(const CryptoType table[],int table_len,const CryptoType & default_alg,const char * property)27 const CryptoType& lookup_crypto_algorithm(const CryptoType table[], int table_len,
28                                           const CryptoType& default_alg, const char* property) {
29     char paramstr[PROPERTY_VALUE_MAX];
30 
31     property_get(property, paramstr, default_alg.get_config_name());
32     for (int i = 0; i < table_len; i++) {
33         if (strcmp(paramstr, table[i].get_config_name()) == 0) {
34             return table[i];
35         }
36     }
37     LOG(ERROR) << "Invalid name (" << paramstr << ") for " << property << ".  Defaulting to "
38                << default_alg.get_config_name() << ".";
39     return default_alg;
40 }
41 
42 }  // namespace vold
43 }  // namespace android
44