- add sources.
[platform/framework/web/crosswalk.git] / src / chromeos / cryptohome / cryptohome_util.cc
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chromeos/cryptohome/cryptohome_util.h"
6
7 #include "base/logging.h"
8 #include "chromeos/dbus/cryptohome_client.h"
9 #include "chromeos/dbus/dbus_thread_manager.h"
10
11 namespace chromeos {
12 namespace cryptohome_util {
13
14 bool TpmIsEnabled() {
15   bool result = false;
16   DBusThreadManager::Get()->GetCryptohomeClient()->CallTpmIsEnabledAndBlock(
17       &result);
18   return result;
19 }
20
21 bool TpmIsOwned() {
22   bool result = false;
23   DBusThreadManager::Get()->GetCryptohomeClient()->CallTpmIsOwnedAndBlock(
24       &result);
25   return result;
26 }
27
28 bool TpmIsBeingOwned() {
29   bool result = false;
30   DBusThreadManager::Get()->GetCryptohomeClient()->
31       CallTpmIsBeingOwnedAndBlock(&result);
32   return result;
33 }
34
35 bool InstallAttributesGet(
36     const std::string& name, std::string* value) {
37   std::vector<uint8> buf;
38   bool success = false;
39   DBusThreadManager::Get()->GetCryptohomeClient()->
40       InstallAttributesGet(name, &buf, &success);
41   if (success) {
42     // Cryptohome returns 'buf' with a terminating '\0' character.
43     DCHECK(!buf.empty());
44     DCHECK_EQ(buf.back(), 0);
45     value->assign(reinterpret_cast<char*>(buf.data()), buf.size() - 1);
46   }
47   return success;
48 }
49
50 bool InstallAttributesSet(
51     const std::string& name, const std::string& value) {
52   std::vector<uint8> buf(value.c_str(), value.c_str() + value.size() + 1);
53   bool success = false;
54   DBusThreadManager::Get()->GetCryptohomeClient()->
55       InstallAttributesSet(name, buf, &success);
56   return success;
57 }
58
59 bool InstallAttributesFinalize() {
60   bool success = false;
61   DBusThreadManager::Get()->GetCryptohomeClient()->
62       InstallAttributesFinalize(&success);
63   return success;
64 }
65
66 bool InstallAttributesIsInvalid() {
67   bool result = false;
68   DBusThreadManager::Get()->GetCryptohomeClient()->
69       InstallAttributesIsInvalid(&result);
70   return result;
71 }
72
73 bool InstallAttributesIsFirstInstall() {
74   bool result = false;
75   DBusThreadManager::Get()->GetCryptohomeClient()->
76       InstallAttributesIsFirstInstall(&result);
77   return result;
78 }
79
80 }  // namespace cryptohome_util
81 }  // namespace chromeos