Avoid deprecated ndn-cxx functions
Change-Id: Idcef8a642affb276581397e869d19534ec776240
diff --git a/src/detail/ca-memory.cpp b/src/detail/ca-memory.cpp
index eae67cc..b3c5efd 100644
--- a/src/detail/ca-memory.cpp
+++ b/src/detail/ca-memory.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2017-2021, Regents of the University of California.
+ * Copyright (c) 2017-2022, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -36,8 +36,7 @@
{
auto search = m_requests.find(requestId);
if (search == m_requests.end()) {
- NDN_THROW(std::runtime_error("Request " + ndn::toHex(requestId.data(), requestId.size()) +
- " does not exists"));
+ NDN_THROW(std::runtime_error("Request " + ndn::toHex(requestId) + " does not exists"));
}
return search->second;
}
@@ -50,8 +49,7 @@
m_requests.insert(std::make_pair(request.requestId, request));
}
else {
- NDN_THROW(std::runtime_error("Request " + ndn::toHex(request.requestId.data(), request.requestId.size()) +
- " already exists"));
+ NDN_THROW(std::runtime_error("Request " + ndn::toHex(request.requestId) + " already exists"));
}
}
diff --git a/src/detail/ca-request-state.cpp b/src/detail/ca-request-state.cpp
index 68d189a..63ac317 100644
--- a/src/detail/ca-request-state.cpp
+++ b/src/detail/ca-request-state.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2017-2021, Regents of the University of California.
+ * Copyright (c) 2017-2022, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -71,7 +71,7 @@
operator<<(std::ostream& os, const RequestState& request)
{
os << "Request's CA name: " << request.caPrefix << "\n";
- os << "Request's request ID: " << ndn::toHex(request.requestId.data(), request.requestId.size()) << "\n";
+ os << "Request's request ID: " << ndn::toHex(request.requestId) << "\n";
os << "Request's status: " << statusToString(request.status) << "\n";
os << "Request's challenge type: " << request.challengeType << "\n";
if (request.challengeState) {
diff --git a/src/detail/ca-sqlite.cpp b/src/detail/ca-sqlite.cpp
index 45cd84d..0632edc 100644
--- a/src/detail/ca-sqlite.cpp
+++ b/src/detail/ca-sqlite.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2017-2021, Regents of the University of California.
+ * Copyright (c) 2017-2022, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -157,8 +157,7 @@
return state;
}
else {
- NDN_THROW(std::runtime_error("Request " + ndn::toHex(requestId.data(), requestId.size()) +
- " cannot be fetched from database"));
+ NDN_THROW(std::runtime_error("Request " + ndn::toHex(requestId) + " cannot be fetched from database"));
}
}
@@ -188,8 +187,8 @@
statement.bind(11, request.challengeState->remainingTime.count());
}
if (statement.step() != SQLITE_DONE) {
- NDN_THROW(std::runtime_error("Request " + ndn::toHex(request.requestId.data(), request.requestId.size()) +
- " cannot be added to database"));
+ NDN_THROW(std::runtime_error("Request " + ndn::toHex(request.requestId) +
+ " cannot be added to the database"));
}
}
diff --git a/src/detail/challenge-encoder.cpp b/src/detail/challenge-encoder.cpp
index c2bdd68..1a7a83d 100644
--- a/src/detail/challenge-encoder.cpp
+++ b/src/detail/challenge-encoder.cpp
@@ -36,7 +36,7 @@
if (request.challengeState->challengeStatus == "need-proof") {
response.push_back(ndn::makeStringBlock(tlv::ParameterKey, "nonce"));
auto nonce = ndn::fromHex(request.challengeState->secrets.get("nonce", ""));
- response.push_back(ndn::makeBinaryBlock(tlv::ParameterValue, nonce->data(), 16));
+ response.push_back(ndn::makeBinaryBlock(tlv::ParameterValue, *nonce));
}
}
if (!issuedCertName.empty()) {
@@ -57,7 +57,7 @@
auto result = decodeBlockWithAesGcm128(contentBlock, state.m_aesKey.data(),
state.m_requestId.data(), state.m_requestId.size(),
state.m_decryptionIv, state.m_encryptionIv);
- auto data = ndn::makeBinaryBlock(tlv::EncryptedPayload, result.data(), result.size());
+ auto data = ndn::makeBinaryBlock(tlv::EncryptedPayload, result);
data.parse();
int numStatus = 0;
diff --git a/src/detail/crypto-helpers.cpp b/src/detail/crypto-helpers.cpp
index d0c2e55..16e56a5 100644
--- a/src/detail/crypto-helpers.cpp
+++ b/src/detail/crypto-helpers.cpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2017-2021, Regents of the University of California.
+ * Copyright (c) 2017-2022, Regents of the University of California.
*
* This file is part of ndncert, a certificate management system based on NDN.
*
@@ -416,17 +416,20 @@
// The spec of AES encrypted payload TLV used in NDNCERT:
// https://github.com/named-data/ndncert/wiki/NDNCERT-Protocol-0.3#242-aes-gcm-encryption
ndn::Buffer encryptedPayload(payloadSize);
- uint8_t tag[16];
if (encryptionIv.empty()) {
encryptionIv.resize(12, 0);
- ndn::random::generateSecureBytes(encryptionIv.data(), 8);
+ ndn::random::generateSecureBytes(ndn::make_span(encryptionIv).first(8));
}
+
+ uint8_t tag[16];
size_t encryptedPayloadLen = aesGcm128Encrypt(payload, payloadSize, associatedData, associatedDataSize,
key, encryptionIv.data(), encryptedPayload.data(), tag);
+
Block content(tlvType);
- content.push_back(ndn::makeBinaryBlock(tlv::InitializationVector, encryptionIv.data(), encryptionIv.size()));
- content.push_back(ndn::makeBinaryBlock(tlv::AuthenticationTag, tag, 16));
- content.push_back(ndn::makeBinaryBlock(tlv::EncryptedPayload, encryptedPayload.data(), encryptedPayloadLen));
+ content.push_back(ndn::makeBinaryBlock(tlv::InitializationVector, encryptionIv));
+ content.push_back(ndn::makeBinaryBlock(tlv::AuthenticationTag, tag));
+ content.push_back(ndn::makeBinaryBlock(tlv::EncryptedPayload,
+ ndn::make_span(encryptedPayload).first(encryptedPayloadLen)));
content.encode();
// update IV's counter
updateIv(encryptionIv, payloadSize);
diff --git a/src/detail/request-encoder.cpp b/src/detail/request-encoder.cpp
index fde2d86..1187243 100644
--- a/src/detail/request-encoder.cpp
+++ b/src/detail/request-encoder.cpp
@@ -31,9 +31,8 @@
const std::vector<uint8_t>& ecdhPub,
const Certificate& certRequest)
{
- Block
- request(ndn::tlv::ApplicationParameters);
- request.push_back(ndn::makeBinaryBlock(tlv::EcdhPub, ecdhPub.data(), ecdhPub.size()));
+ Block request(ndn::tlv::ApplicationParameters);
+ request.push_back(ndn::makeBinaryBlock(tlv::EcdhPub, ecdhPub));
if (requestType == RequestType::NEW || requestType == RequestType::RENEW) {
request.push_back(makeNestedBlock(tlv::CertRequest, certRequest));
}
@@ -83,14 +82,15 @@
}
Block
-requesttlv::encodeDataContent(const std::vector <uint8_t>& ecdhKey, const std::array<uint8_t, 32>& salt,
+requesttlv::encodeDataContent(const std::vector<uint8_t>& ecdhKey,
+ const std::array<uint8_t, 32>& salt,
const RequestId& requestId,
- const std::vector <std::string>& challenges)
+ const std::vector<std::string>& challenges)
{
Block response(ndn::tlv::Content);
- response.push_back(ndn::makeBinaryBlock(tlv::EcdhPub, ecdhKey.data(), ecdhKey.size()));
- response.push_back(ndn::makeBinaryBlock(tlv::Salt, salt.data(), salt.size()));
- response.push_back(ndn::makeBinaryBlock(tlv::RequestId, requestId.data(), requestId.size()));
+ response.push_back(ndn::makeBinaryBlock(tlv::EcdhPub, ecdhKey));
+ response.push_back(ndn::makeBinaryBlock(tlv::Salt, salt));
+ response.push_back(ndn::makeBinaryBlock(tlv::RequestId, requestId));
for (const auto& entry: challenges) {
response.push_back(ndn::makeStringBlock(tlv::Challenge, entry));
}