Crypto++ 的自定义源代码
Custom source for Crypto++
我已经为二进制 I/O 创建了自己的自定义流 classes。现在我试图让它们与 Crypto++ 库兼容。我找到了一个 处理自定义接收器并实现了我自己的。现在我需要实现一个来源。我搜索了文档,似乎有一个巨大的继承层次结构,所以我还看不懂。
有人可以提供示例代码吗?
这是我的直播部分 class:
/// \brief Base class for a binary input stream.
/// \details Binary streams are used for low level unformatted I/O. Built on top
/// of standard streams, this system takes care of endianness and provides
/// convenient << and >> overloads. This class is designed to mirror
/// std::istream.
class BinaryInputStream : public virtual BinaryStreamBase
{
public:
/// \brief Returns whether last I/O operation has completed successfully.
/// \return True if last I/O operation has completed successfully,
/// false otherwise.
virtual bool IsGood() const = 0;
/// \brief Returns whether end-of-file has been reached.
/// \return True if end-of-file has been reached, false otherwise.
virtual bool IsEOF() const = 0;
/// \brief Returns whether recoverable error has occured.
/// \return True if recoverable error has occured, false otherwise.
virtual bool IsFail() const = 0;
/// \brief Returns whether non-recoverable error has occured.
/// \return True if non-recoverable error has occured, false otherwise.
virtual bool IsBad() const = 0;
/// \brief Reads a sequence of bytes from the stream.
/// \param[in,out] buffer Buffer to write to.
/// \param[in] size Number of bytes to read.
/// \return Reference to this stream.
/// \warning You are responsible for allocating the buffer and ensuring that
/// it contains enough space to hold the data. If number of bytes to read is
/// greater than the size of the buffer, the behavior is undefined.
virtual BinaryInputStream& Read(char* buffer, std::size_t size) = 0;
};
我不得不查看 crypto++ 的源代码并从 FileSource
class. The relevant files are files.h
and files.cpp
复制大部分实现。
首先,我们需要看一下FileSource
class. It inherits from SourceTemplate<FileStore>
. So we need to examine FileStore
class。它继承自 Store
、FilterPutSpaceHelper
和 NotCopyable
。我们需要创建 class 也继承自这些 classes.
我们的商店 class 必须具有默认构造函数并实现以下虚函数:TransferTo2
、CopyRangeTo2
和 StoreInitialize
。 StoreInitialize
可以是私有的。
最后,我们的源代码 class 只需要构造函数,如果您查看 files.h
, FileSource
完全在头文件中实现。
我已经为二进制 I/O 创建了自己的自定义流 classes。现在我试图让它们与 Crypto++ 库兼容。我找到了一个
有人可以提供示例代码吗?
这是我的直播部分 class:
/// \brief Base class for a binary input stream.
/// \details Binary streams are used for low level unformatted I/O. Built on top
/// of standard streams, this system takes care of endianness and provides
/// convenient << and >> overloads. This class is designed to mirror
/// std::istream.
class BinaryInputStream : public virtual BinaryStreamBase
{
public:
/// \brief Returns whether last I/O operation has completed successfully.
/// \return True if last I/O operation has completed successfully,
/// false otherwise.
virtual bool IsGood() const = 0;
/// \brief Returns whether end-of-file has been reached.
/// \return True if end-of-file has been reached, false otherwise.
virtual bool IsEOF() const = 0;
/// \brief Returns whether recoverable error has occured.
/// \return True if recoverable error has occured, false otherwise.
virtual bool IsFail() const = 0;
/// \brief Returns whether non-recoverable error has occured.
/// \return True if non-recoverable error has occured, false otherwise.
virtual bool IsBad() const = 0;
/// \brief Reads a sequence of bytes from the stream.
/// \param[in,out] buffer Buffer to write to.
/// \param[in] size Number of bytes to read.
/// \return Reference to this stream.
/// \warning You are responsible for allocating the buffer and ensuring that
/// it contains enough space to hold the data. If number of bytes to read is
/// greater than the size of the buffer, the behavior is undefined.
virtual BinaryInputStream& Read(char* buffer, std::size_t size) = 0;
};
我不得不查看 crypto++ 的源代码并从 FileSource
class. The relevant files are files.h
and files.cpp
复制大部分实现。
首先,我们需要看一下FileSource
class. It inherits from SourceTemplate<FileStore>
. So we need to examine FileStore
class。它继承自 Store
、FilterPutSpaceHelper
和 NotCopyable
。我们需要创建 class 也继承自这些 classes.
我们的商店 class 必须具有默认构造函数并实现以下虚函数:TransferTo2
、CopyRangeTo2
和 StoreInitialize
。 StoreInitialize
可以是私有的。
最后,我们的源代码 class 只需要构造函数,如果您查看 files.h
, FileSource
完全在头文件中实现。