security: move {Rsa,Ec,Aes}KeyParamsInfo into namespace detail
Change-Id: I06fb1f7dfc809551c5533a185ada1b8dce8ee03e
diff --git a/src/security/key-params.cpp b/src/security/key-params.cpp
index 546597c..a908b43 100644
--- a/src/security/key-params.cpp
+++ b/src/security/key-params.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).
@@ -28,8 +28,6 @@
static const uint32_t EC_KEY_SIZES[] = {256, 384};
static const uint32_t AES_KEY_SIZES[] = {128, 192, 256};
-KeyParams::~KeyParams() = default;
-
KeyParams::KeyParams(KeyType keyType, KeyIdType keyIdType)
: m_keyType(keyType)
, m_keyIdType(keyIdType)
@@ -45,11 +43,15 @@
BOOST_ASSERT(!keyId.empty());
}
+KeyParams::~KeyParams() = default;
+
+namespace detail {
+
uint32_t
RsaKeyParamsInfo::checkKeySize(uint32_t size)
{
if (size < MIN_RSA_KEY_SIZE)
- BOOST_THROW_EXCEPTION(KeyParams::Error("Unsupported key size"));
+ BOOST_THROW_EXCEPTION(KeyParams::Error("Unsupported RSA key size"));
return size;
}
@@ -66,7 +68,7 @@
if (EC_KEY_SIZES[i] == size)
return size;
}
- BOOST_THROW_EXCEPTION(KeyParams::Error("Unsupported key size"));
+ BOOST_THROW_EXCEPTION(KeyParams::Error("Unsupported EC key size"));
}
uint32_t
@@ -75,7 +77,6 @@
return EC_KEY_SIZES[0];
}
-
uint32_t
AesKeyParamsInfo::checkKeySize(uint32_t size)
{
@@ -83,7 +84,7 @@
if (AES_KEY_SIZES[i] == size)
return size;
}
- BOOST_THROW_EXCEPTION(KeyParams::Error("Unsupported key size"));
+ BOOST_THROW_EXCEPTION(KeyParams::Error("Unsupported AES key size"));
}
uint32_t
@@ -92,4 +93,5 @@
return AES_KEY_SIZES[0];
}
+} // namespace detail
} // namespace ndn
diff --git a/src/security/key-params.hpp b/src/security/key-params.hpp
index 4c7d118..dce4908 100644
--- a/src/security/key-params.hpp
+++ b/src/security/key-params.hpp
@@ -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).
@@ -22,9 +22,8 @@
#ifndef NDN_SECURITY_KEY_PARAMS_HPP
#define NDN_SECURITY_KEY_PARAMS_HPP
-#include "../common.hpp"
-#include "../name-component.hpp"
#include "security-common.hpp"
+#include "../name-component.hpp"
namespace ndn {
@@ -61,25 +60,25 @@
return m_keyIdType;
}
- void
- setKeyId(const name::Component& keyId)
- {
- m_keyId = keyId;
- }
-
const name::Component&
getKeyId() const
{
return m_keyId;
}
+ void
+ setKeyId(const name::Component& keyId)
+ {
+ m_keyId = keyId;
+ }
+
protected:
/**
* @brief Create a key generation parameter
*
* @param keyType Type of the created key
* @param keyIdType The method how the key id should be generated; must not be
- KeyIdType::USER_SPECIFIED
+ * KeyIdType::USER_SPECIFIED
*/
KeyParams(KeyType keyType, KeyIdType keyIdType);
@@ -100,18 +99,20 @@
};
-/// @brief RsaKeyParamInfo is used to initialize a SimplePublicKeyParams template for RSA key.
+namespace detail {
+
+/// @brief RsaKeyParamInfo is used to instantiate SimplePublicKeyParams for RSA keys.
class RsaKeyParamsInfo
{
public:
- static KeyType
+ static constexpr KeyType
getType()
{
return KeyType::RSA;
}
/**
- * @brief check if @p size is qualified.
+ * @brief check if @p size is valid and supported for this key type.
*
* @throw KeyParams::Error if the key size is not supported.
*/
@@ -122,18 +123,18 @@
getDefaultSize();
};
-/// @brief EcKeyParamInfo is used to initialize a SimplePublicKeyParams template for elliptic curve key.
+/// @brief EcKeyParamInfo is used to instantiate SimplePublicKeyParams for elliptic curve keys.
class EcKeyParamsInfo
{
public:
- static KeyType
+ static constexpr KeyType
getType()
{
return KeyType::EC;
}
/**
- * @brief check if @p size is qualified.
+ * @brief check if @p size is valid and supported for this key type.
*
* @throw KeyParams::Error if the key size is not supported.
*/
@@ -144,6 +145,8 @@
getDefaultSize();
};
+} // namespace detail
+
/// @brief SimplePublicKeyParams is a template for public keys with only one parameter: size.
template<typename KeyParamsInfo>
@@ -197,23 +200,26 @@
};
/// @brief RsaKeyParams carries parameters for RSA key.
-typedef SimplePublicKeyParams<RsaKeyParamsInfo> RsaKeyParams;
+typedef SimplePublicKeyParams<detail::RsaKeyParamsInfo> RsaKeyParams;
/// @brief EcKeyParams carries parameters for EC key.
-typedef SimplePublicKeyParams<EcKeyParamsInfo> EcKeyParams;
+typedef SimplePublicKeyParams<detail::EcKeyParamsInfo> EcKeyParams;
-/// @brief AesKeyParamsInfo is used to initialize a SimpleSymmetricKeyParams template for AES key.
+
+namespace detail {
+
+/// @brief AesKeyParamsInfo is used to instantiate SimpleSymmetricKeyParams for AES keys.
class AesKeyParamsInfo
{
public:
- static KeyType
+ static constexpr KeyType
getType()
{
return KeyType::AES;
}
/**
- * @brief check if @p size is qualified.
+ * @brief check if @p size is valid and supported for this key type.
*
* @return KeyParams::Error if the key size is not supported.
*/
@@ -224,6 +230,9 @@
getDefaultSize();
};
+} // namespace detail
+
+
/// @brief SimpleSymmetricKeyParams is a template for symmetric keys with only one parameter: size.
template<typename KeyParamsInfo>
class SimpleSymmetricKeyParams : public KeyParams
@@ -275,7 +284,8 @@
uint32_t m_size;
};
-typedef SimpleSymmetricKeyParams<AesKeyParamsInfo> AesKeyParams;
+/// @brief AesKeyParams carries parameters for AES key.
+typedef SimpleSymmetricKeyParams<detail::AesKeyParamsInfo> AesKeyParams;
} // namespace ndn