security: fix error handling in KeyChain::importSafeBag()
Tpm::importPrivateKey() now throws on error instead of
returning false, for consistency with similar functions.
Change-Id: Id07c2be3809e32d1779c0b5977232e4728528e3c
Refs: #4359
diff --git a/src/security/tpm/tpm.cpp b/src/security/tpm/tpm.cpp
index 0ed1062..d72440b 100644
--- a/src/security/tpm/tpm.cpp
+++ b/src/security/tpm/tpm.cpp
@@ -1,5 +1,5 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
+/*
* Copyright (c) 2013-2017 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
@@ -138,36 +138,27 @@
return m_backEnd->exportKey(keyName, pw, pwLen);
}
-bool
+void
Tpm::importPrivateKey(const Name& keyName, const uint8_t* pkcs8, size_t pkcs8Len,
const char* pw, size_t pwLen)
{
- try {
- m_backEnd->importKey(keyName, pkcs8, pkcs8Len, pw, pwLen);
- }
- catch (const BackEnd::Error&) {
- return false;
- }
- return true;
+ m_backEnd->importKey(keyName, pkcs8, pkcs8Len, pw, pwLen);
}
const KeyHandle*
Tpm::findKey(const Name& keyName) const
{
auto it = m_keys.find(keyName);
-
if (it != m_keys.end())
return it->second.get();
- unique_ptr<KeyHandle> handle = m_backEnd->getKeyHandle(keyName);
+ auto handle = m_backEnd->getKeyHandle(keyName);
+ if (handle == nullptr)
+ return nullptr;
- if (handle != nullptr) {
- KeyHandle* key = handle.get();
- m_keys[keyName] = std::move(handle);
- return key;
- }
-
- return nullptr;
+ const KeyHandle* key = handle.get();
+ m_keys[keyName] = std::move(handle);
+ return key;
}
} // namespace tpm