refactor the HKDF State class

Change-Id: I819c9a8dcb7b3b13c1a63269a18ceadfa2b80c50
diff --git a/tests/unit-tests/crypto-helper.t.cpp b/tests/unit-tests/crypto-helper.t.cpp
index 09c4705..4bb2e22 100644
--- a/tests/unit-tests/crypto-helper.t.cpp
+++ b/tests/unit-tests/crypto-helper.t.cpp
@@ -30,52 +30,47 @@
 BOOST_AUTO_TEST_CASE(EcdhWithRawKey)
 {
   ECDHState aliceState;
-  auto alicePub = aliceState.getRawSelfPubKey();
-  BOOST_CHECK(aliceState.m_publicKeyLen != 0);
+  auto alicePub = aliceState.getSelfPubKey();
+  BOOST_CHECK(!alicePub.empty());
 
   ECDHState bobState;
-  auto bobPub = bobState.getRawSelfPubKey();
-  BOOST_CHECK(bobState.m_publicKeyLen != 0);
+  auto bobPub = bobState.getSelfPubKey();
+  BOOST_CHECK(!bobPub.empty());
 
-  auto aliceResult = aliceState.deriveSecret(bobPub, bobState.m_publicKeyLen);
-
-  BOOST_CHECK(aliceState.m_sharedSecretLen != 0);
-
-  auto bobResult = bobState.deriveSecret(alicePub, aliceState.m_publicKeyLen);
-
-  BOOST_CHECK(bobState.m_sharedSecretLen != 0);
-
-  BOOST_CHECK_EQUAL_COLLECTIONS(aliceResult, aliceResult + 32, bobResult, bobResult + 32);
+  auto aliceResult = aliceState.deriveSecret(bobPub);
+  BOOST_CHECK(!aliceResult.empty());
+  auto bobResult = bobState.deriveSecret(alicePub);
+  BOOST_CHECK(!bobResult.empty());
+  BOOST_CHECK_EQUAL_COLLECTIONS(aliceResult.begin(), aliceResult.end(), bobResult.begin(), bobResult.end());
 }
 
 BOOST_AUTO_TEST_CASE(EcdhWithRawKeyWrongInput)
 {
   ECDHState aliceState;
-  auto alicePub = aliceState.getRawSelfPubKey();
-  BOOST_CHECK(alicePub != nullptr);
-  BOOST_CHECK(aliceState.m_publicKeyLen != 0);
+  auto alicePub = aliceState.getSelfPubKey();
+  BOOST_CHECK(!alicePub.empty());
   uint8_t fakePub[] = {0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b};
   BOOST_CHECK_THROW(aliceState.deriveSecret(fakePub, sizeof(fakePub)), std::runtime_error);
 }
 
-BOOST_AUTO_TEST_CASE(EcdhWithBase64Key)
-{
-  ECDHState aliceState;
-  auto alicePub = aliceState.getBase64PubKey();
-  BOOST_CHECK(alicePub != "");
+// BOOST_AUTO_TEST_CASE(EcdhWithBase64Key)
+// {
+//   ECDHState aliceState;
+//   auto alicePub = aliceState.getBase64PubKey();
+//   BOOST_CHECK(alicePub != "");
 
-  ECDHState bobState;
-  auto bobPub = bobState.getBase64PubKey();
-  BOOST_CHECK(bobPub != "");
+//   ECDHState bobState;
+//   auto bobPub = bobState.getBase64PubKey();
+//   BOOST_CHECK(bobPub != "");
 
-  auto aliceResult = aliceState.deriveSecret(bobPub);
-  BOOST_CHECK(aliceState.m_sharedSecretLen != 0);
+//   auto aliceResult = aliceState.deriveSecret(bobPub);
+//   BOOST_CHECK(aliceState.m_sharedSecretLen != 0);
 
-  auto bobResult = bobState.deriveSecret(alicePub);
-  BOOST_CHECK(bobState.m_sharedSecretLen != 0);
+//   auto bobResult = bobState.deriveSecret(alicePub);
+//   BOOST_CHECK(bobState.m_sharedSecretLen != 0);
 
-  BOOST_CHECK_EQUAL_COLLECTIONS(aliceResult, aliceResult + 32, bobResult, bobResult + 32);
-}
+//   BOOST_CHECK_EQUAL_COLLECTIONS(aliceResult, aliceResult + 32, bobResult, bobResult + 32);
+// }
 
 BOOST_AUTO_TEST_CASE(HmacSha256)
 {
diff --git a/tests/unit-tests/protocol-detail.t.cpp b/tests/unit-tests/protocol-detail.t.cpp
index e3aa143..e02afaf 100644
--- a/tests/unit-tests/protocol-detail.t.cpp
+++ b/tests/unit-tests/protocol-detail.t.cpp
@@ -77,20 +77,17 @@
   auto cert = key.getDefaultCertificate();
 
   ECDHState ecdhState;
-  auto block = NewRenewRevokeEncoder::encodeApplicationParameters(RequestType::NEW,
-                                                                  ecdhState.getBase64PubKey(),
-                                                                  cert);
-  std::string ecdhPub;
+  auto selfKey = ecdhState.getSelfPubKey();
+  auto block = NewRenewRevokeEncoder::encodeApplicationParameters(RequestType::NEW, selfKey, cert);
+  std::vector<uint8_t> peerKey;
   shared_ptr<security::Certificate> clientCert;
-  NewRenewRevokeEncoder::decodeApplicationParameters(block, RequestType::NEW, ecdhPub, clientCert);
-  BOOST_CHECK_EQUAL(ecdhState.getBase64PubKey(), ecdhPub);
+  NewRenewRevokeEncoder::decodeApplicationParameters(block, RequestType::NEW, peerKey, clientCert);
+  BOOST_CHECK_EQUAL_COLLECTIONS(selfKey.begin(), selfKey.end(), peerKey.begin(), peerKey.end());
   BOOST_CHECK_EQUAL(cert, *clientCert);
 
-  block = NewRenewRevokeEncoder::encodeApplicationParameters(RequestType::REVOKE,
-                                                             ecdhState.getBase64PubKey(),
-                                                             cert);
-  NewRenewRevokeEncoder::decodeApplicationParameters(block, RequestType::REVOKE, ecdhPub, clientCert);
-  BOOST_CHECK_EQUAL(ecdhState.getBase64PubKey(), ecdhPub);
+  block = NewRenewRevokeEncoder::encodeApplicationParameters(RequestType::REVOKE, selfKey, cert);
+  NewRenewRevokeEncoder::decodeApplicationParameters(block, RequestType::REVOKE, peerKey, clientCert);
+  BOOST_CHECK_EQUAL_COLLECTIONS(selfKey.begin(), selfKey.end(), peerKey.begin(), peerKey.end());
   BOOST_CHECK_EQUAL(cert, *clientCert);
 
   // NewRenewRevokeEncoder::encodeDataContent(ecdhState.getBase64PubKey(), "")