};
-// Forward declaration for createHash()
+/// \brief Forward declaration for createHash()
class Hash;
-// Forward declaration for createHMAC()
+/// \brief Forward declaration for createHMAC()
class HMAC;
-// Forward declaration for getRNG()
+/// \brief Forward declaration for getRNG()
class RNG;
+
+/// \brief Type representing the pointer to the RNG.
typedef boost::shared_ptr<RNG> RNGPtr;
/// General exception class that is the base for all crypto-related
CryptoLinkError(file, line, what) {}
};
-/// Forward declarations for pimpl
+/// \brief Forward declarations for CryptoLink pimpl.
class CryptoLinkImpl;
+
+/// \brief Type representing the pointer to the CryptoLinkImpl.
+typedef boost::shared_ptr<CryptoLinkImpl> CryptoLinkImplPtr;
+
+/// \brief Forward declarations for RNG pimpl.
class RNGImpl;
/// \brief Singleton entry point and factory class
///
/// There is only one way to access it, through getCryptoLink(), which
/// returns a reference to the initialized library. On the first call,
-/// it will be initialized automatically. You can however initialize it
-/// manually through a call to initialize(), before your first call
-/// to getCryptoLink. Any subsequent call to initialize() will be a
-/// noop.
+/// it will be initialized automatically.
///
/// In order for the CryptoLink library to be sure that the underlying
/// library has been initialized, and because we do not want to add
/// \return Reference to the singleton instance
static CryptoLink& getCryptoLink();
- /// \brief Initialize the library manually
- ///
- /// If the library has already been initialized (either by a call
- /// to initialize() or automatically in getCryptoLink()), this
- /// function does nothing.
- ///
- /// \note A call to initialize() is not strictly necessary with
- /// the current implementation.
- ///
- /// \exception InitializationError if initialization fails
- ///
- static void initialize();
-
/// \brief Get version string
static std::string getVersion();
virtual RNGPtr& getRNG();
private:
- // To enable us to use an optional explicit initialization call,
- // the 'real' instance getter is private
- static CryptoLink& getCryptoLinkInternal();
+ /// \brief Initialize the library
+ ///
+ /// If the library has already been initialized (either by a call
+ /// to initialize() or automatically in getCryptoLink()), this
+ /// function does nothing.
+ ///
+ /// \note A call to initialize() is not strictly necessary with
+ /// the current implementation.
+ ///
+ /// \exception InitializationError if initialization fails
+ ///
+ /// \param c the CryptoLink singleton instance which is being initialized.
+ void initialize(CryptoLink& c);
// To prevent people constructing their own, we make the constructor
// private too.
- CryptoLink() : impl_(NULL) {}
+ CryptoLink() : impl_(NULL) {
+ initialize(*this);
+ }
~CryptoLink();
- CryptoLinkImpl* impl_;
+ CryptoLinkImplPtr impl_;
RNGPtr rng_;
};
namespace util {
namespace str {
-/// \brief A Set of C++ Utilities for Manipulating Strings
+/// @brief A Set of C++ Utilities for Manipulating Strings
///
-/// \brief A standard string util exception that is thrown if getToken or
+/// @brief A standard string util exception that is thrown if getToken or
/// numToToken are called with bad input data
///
class StringTokenError : public Exception {
isc::Exception(file, line, what) {}
};
-/// \brief Normalize Backslash
+/// @brief Normalize Backslash
///
/// Only relevant to Windows, this replaces all "\" in a string with "/"
/// and returns the result. On other systems it is a no-op. Note
/// that Windows does recognize file names with the "\" replaced by "/"
/// (at least in system calls, if not the command line).
///
-/// \param name Name to be substituted
+/// @param name Name to be substituted
void normalizeSlash(std::string& name);
-/// \brief Trim Leading and Trailing Spaces
+/// @brief Trim Leading and Trailing Spaces
///
/// Returns a copy of the input string but with any leading or trailing spaces
/// or tabs removed.
///
-/// \param instring Input string to modify
+/// @param instring Input string to modify
///
-/// \return String with leading and trailing spaces removed
+/// @return String with leading and trailing spaces removed
std::string trim(const std::string& instring);
-/// \brief Finds the "trimmed" end of a buffer
+/// @brief Finds the "trimmed" end of a buffer
///
/// Works backward from the end of the buffer, looking for the first
/// character not equal to the trim value, and returns an iterator
/// pointing that that position.
///
-/// \param begin - Forward iterator pointing to the beginning of the
+/// @param begin - Forward iterator pointing to the beginning of the
/// buffer to trim
-/// \param end - Forward iterator pointing to the untrimmed end of
+/// @param end - Forward iterator pointing to the untrimmed end of
/// the buffer to trim
-/// \param trim_val - byte value to trim off
+/// @param trim_val - byte value to trim off
///
-/// \return Iterator pointing the first character from the end of the
+/// @return Iterator pointing the first character from the end of the
/// buffer not equal to the trim value
template<typename Iterator>
Iterator
return(end);
}
-/// \brief Split String into Tokens
+/// @brief Split String into Tokens
///
/// Splits a string into tokens (the tokens being delimited by one or more of
/// the delimiter characters) and returns the tokens in a vector array. Note
/// We could use Boost for this, but this (simple) function eliminates one
/// dependency in the code.
///
-/// \param text String to be split. Passed by value as the internal copy is
+/// @param text String to be split. Passed by value as the internal copy is
/// altered during the processing.
-/// \param delim Delimiter characters
-/// \param escape Use backslash to escape delimiter characters
+/// @param delim Delimiter characters
+/// @param escape Use backslash to escape delimiter characters
///
-/// \return Vector of tokens.
+/// @return Vector of tokens.
std::vector<std::string> tokens(const std::string& text,
const std::string& delim = std::string(" \t\n"),
bool escape = false);
-/// \brief Uppercase Character
+/// @brief Uppercase Character
///
/// Used in uppercase() to pass as an argument to std::transform(). The
/// function std::toupper() can't be used as it takes an "int" as its argument;
/// this confuses the template expansion mechanism because dereferencing a
/// string::iterator returns a char.
///
-/// \param chr Character to be upper-cased.
+/// @param chr Character to be upper-cased.
///
-/// \return Uppercase version of the argument
+/// @return Uppercase version of the argument
inline char toUpper(char chr) {
return (static_cast<char>(std::toupper(static_cast<int>(chr))));
}
-/// \brief Uppercase String
+/// @brief Uppercase String
///
/// A convenience function to uppercase a string.
///
-/// \param text String to be upper-cased.
+/// @param text String to be upper-cased.
inline void uppercase(std::string& text) {
std::transform(text.begin(), text.end(), text.begin(),
isc::util::str::toUpper);
}
-/// \brief Lowercase Character
+/// @brief Lowercase Character
///
/// Used in lowercase() to pass as an argument to std::transform(). The
/// function std::tolower() can't be used as it takes an "int" as its argument;
/// this confuses the template expansion mechanism because dereferencing a
/// string::iterator returns a char.
///
-/// \param chr Character to be lower-cased.
+/// @param chr Character to be lower-cased.
///
-/// \return Lowercase version of the argument
+/// @return Lowercase version of the argument
inline char toLower(char chr) {
return (static_cast<char>(std::tolower(static_cast<int>(chr))));
}
-/// \brief Lowercase String
+/// @brief Lowercase String
///
/// A convenience function to lowercase a string
///
-/// \param text String to be lower-cased.
+/// @param text String to be lower-cased.
inline void lowercase(std::string& text) {
std::transform(text.begin(), text.end(), text.begin(),
isc::util::str::toLower);
}
-/// \brief Apply Formatting
+/// @brief Apply Formatting
///
/// Given a printf-style format string containing only "%s" place holders
/// (others are ignored) and a vector of strings, this produces a single string
/// with the placeholders replaced.
///
-/// \param format Format string
-/// \param args Vector of argument strings
+/// @param format Format string
+/// @param args Vector of argument strings
///
-/// \return Resultant string
+/// @return Resultant string
std::string format(const std::string& format,
const std::vector<std::string>& args);
-/// \brief Returns one token from the given stringstream
+/// @brief Returns one token from the given stringstream
///
/// Using the >> operator, with basic error checking
///
-/// \exception StringTokenError if the token cannot be read from the stream
+/// @throw StringTokenError if the token cannot be read from the stream
///
-/// \param iss stringstream to read one token from
+/// @param iss stringstream to read one token from
///
-/// \return the first token read from the stringstream
+/// @return the first token read from the stringstream
std::string getToken(std::istringstream& iss);
-/// \brief Converts a string token to an *unsigned* integer.
+/// @brief Converts a string token to an *unsigned* integer.
///
/// The value is converted using a lexical cast, with error and bounds
/// checking.
/// necessary because lexical_cast<T> where T is an unsigned integer type
/// doesn't correctly reject negative numbers when compiled with SunStudio.
///
-/// \exception StringTokenError if the value is out of range, or if it
-/// could not be converted
+/// @throw StringTokenError if the value is out of range, or if it
+/// could not be converted
///
-/// \param num_token the string token to convert
+/// @param num_token the string token to convert
///
-/// \return the converted value, of type NumType
+/// @return the converted value, of type NumType
template <typename NumType, int BitSize>
NumType
tokenToNum(const std::string& num_token) {
return (num);
}
-/// \brief Converts a string in quotes into vector.
+/// @brief Converts a string in quotes into vector.
///
/// A converted string is first trimmed. If a trimmed string is in
/// quotes, the quotes are removed and the resulting string is copied
/// parsers to convert string values surrounded with quotes into
/// binary form.
///
-/// \param quoted_string String to be converted.
-/// \return Vector containing converted string or empty string if
+/// @param quoted_string String to be converted.
+///
+/// @return Vector containing converted string or empty string if
/// input string didn't contain expected quote characters.
std::vector<uint8_t>
quotedStringToBinary(const std::string& quoted_string);
-/// \brief Converts a string of separated hexadecimal digits
+/// @brief Converts a string of separated hexadecimal digits
/// into a vector.
///
/// Octets may contain 1 or 2 digits. For example, using a colon
/// If the decoded string doesn't match any of the supported formats,
/// an exception is thrown.
///
-/// \param hex_string Input string.
-/// \param sep character to use as a separator.
-/// \param binary Vector receiving converted string into binary.
-/// \throw isc::BadValue if the format of the input string is invalid.
+/// @param hex_string Input string.
+/// @param sep character to use as a separator.
+/// @param binary Vector receiving converted string into binary.
+///
+/// @throw isc::BadValue if the format of the input string is invalid.
void
decodeSeparatedHexString(const std::string& hex_string,
const std::string& sep,
std::vector<uint8_t>& binary);
-/// \brief Converts a string of hexadecimal digits with colons into
+/// @brief Converts a string of hexadecimal digits with colons into
/// a vector.
///
/// Convenience method which calls @c decodeSeparatedHexString() passing
/// in a colon for the separator.
-/// \param hex_string Input string.
-/// \param binary Vector receiving converted string into binary.
-/// \throw isc::BadValue if the format of the input string is invalid.
+/// @param hex_string Input string.
+/// @param binary Vector receiving converted string into binary.
+///
+/// @throw isc::BadValue if the format of the input string is invalid.
void
decodeColonSeparatedHexString(const std::string& hex_string,
std::vector<uint8_t>& binary);
-/// \brief Converts a formatted string of hexadecimal digits into
+/// @brief Converts a formatted string of hexadecimal digits into
/// a vector.
///
/// This function supports the following formats:
/// If there is an odd number of hexadecimal digits in the input
/// string, the '0' is prepended to the string before decoding.
///
-/// \param hex_string Input string.
-/// \param binary Vector receiving converted string into binary.
-/// \throw isc::BadValue if the format of the input string is invalid.
+/// @param hex_string Input string.
+/// @param binary Vector receiving converted string into binary.
+///
+/// @throw isc::BadValue if the format of the input string is invalid.
void
decodeFormattedHexString(const std::string& hex_string,
std::vector<uint8_t>& binary);
/// @brief Forward declaration to the @c StringSanitizer implementation.
class StringSanitizerImpl;
+/// @brief Type representing the pointer to the @c StringSanitizerImpl.
+typedef boost::shared_ptr<StringSanitizerImpl> StringSanitizerImplPtr;
+
/// @brief Implements a regular expression based string scrubber
///
/// The implementation uses C++11 regex IF the environment supports it
class StringSanitizer {
public:
- /// Constructor
+ /// @brief Constructor.
///
/// Compiles the given character set into a regular expression, and
/// retains the given character replacement. Thereafter, the instance
/// inversion of valid characters "[^A-Za-z0-9_-]".
/// @param char_replacement string of one or more characters to use as the
/// replacement for invalid characters.
+ ///
/// @throw BadValue if given an invalid regular expression
StringSanitizer(const std::string& char_set,
const std::string& char_replacement);
/// expression with the character replacement.
///
/// @param original the string to scrub
+ ///
/// @throw Unexpected if an error occurs during scrubbing
std::string scrub(const std::string& original);
private:
/// @brief Pointer to the @c StringSanitizerImpl.
- StringSanitizerImpl* impl_;
+ StringSanitizerImplPtr impl_;
};
+/// @brief Type representing the pointer to the @c StringSanitizer.
typedef boost::shared_ptr<StringSanitizer> StringSanitizerPtr;
-/// \brief Check if a string is printable
+/// @brief Check if a string is printable
///
-/// \param content String to check for printable characters
-/// \return True if empty or contains only printable characters, False otherwise
+/// @param content String to check for printable characters
+///
+/// @return True if empty or contains only printable characters, False otherwise
inline bool
isPrintable(const std::string& content) {
for (const auto& ch : content) {
return (true);
}
-/// \brief Check if a byte vector is printable
+/// @brief Check if a byte vector is printable
+///
+/// @param content Vector to check for printable characters
///
-/// \param content Vector to check for printable characters
-/// \return True if empty or contains only printable characters, False otherwise
+/// @return True if empty or contains only printable characters, False otherwise
inline bool
isPrintable(const std::vector<uint8_t>& content) {
for (const auto& ch : content) {