Home | History | Annotate | Download | only in keystore
      1 /*
      2  * Copyright (C) 2012 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 <keystore/IKeystoreService.h>
     18 #include <binder/IServiceManager.h>
     19 
     20 #include <keystore/keystore_get.h>
     21 
     22 using namespace android;
     23 
     24 ssize_t keystore_get(const char *key, size_t keyLength, uint8_t** value) {
     25     sp<IServiceManager> sm = defaultServiceManager();
     26     sp<IBinder> binder = sm->getService(String16("android.security.keystore"));
     27     sp<IKeystoreService> service = interface_cast<IKeystoreService>(binder);
     28 
     29     if (service == NULL) {
     30         return -1;
     31     }
     32 
     33     size_t valueLength;
     34     int32_t ret = service->get(String16(key, keyLength), value, &valueLength);
     35     if (ret < 0) {
     36         return -1;
     37     } else if (ret != ::NO_ERROR) {
     38         return -1;
     39     } else {
     40         return valueLength;
     41     }
     42 }
     43