encryptor: Properly handle KEK fetching notification

Change-Id: Id65b58d4a24cd79015fa5a6ab38994bb873af31f
Refs: #4669
diff --git a/src/encryptor.cpp b/src/encryptor.cpp
index 0472e1e..eb6c486 100644
--- a/src/encryptor.cpp
+++ b/src/encryptor.cpp
@@ -153,7 +153,9 @@
                              m_kekPendingInterest = nullptr;
                              // @todo verify if the key is legit
                              m_kek = kek;
-                             makeAndPublishCkData(onFailure);
+                             if (makeAndPublishCkData(onFailure)) {
+                               onReady();
+                             }
                              // otherwise, failure has been already declared
                            },
                            [=] (const Interest& i, const lp::Nack& nack) {
@@ -189,7 +191,7 @@
                            });
 }
 
-void
+bool
 Encryptor::makeAndPublishCkData(const ErrorCallback& onFailure)
 {
   try {
@@ -207,9 +209,11 @@
     m_ims.insert(*ckData);
 
     NDN_LOG_DEBUG("Publishing CK data: " << ckData->getName());
+    return true;
   }
   catch (const std::runtime_error& error) {
     onFailure(ErrorCode::EncryptionFailure, "Failed to encrypt generated CK with KEK " + m_kek->getName().toUri());
+    return false;
   }
 }
 
diff --git a/src/encryptor.hpp b/src/encryptor.hpp
index 34d69bb..2b82d31 100644
--- a/src/encryptor.hpp
+++ b/src/encryptor.hpp
@@ -124,10 +124,10 @@
                            const ErrorCallback& onFailure,
                            size_t nTriesLeft);
 
-  void
+  bool
   makeAndPublishCkData(const ErrorCallback& onFailure);
 
-private:
+PUBLIC_WITH_TESTS_ELSE_PRIVATE:
   Name m_accessPrefix;
   Name m_ckPrefix;
   Name m_ckName;