Crypto ++的自定义源代码

时间:2016-10-26 14:14:00

标签: c++ crypto++

我已经为二进制I / O创建了自己的自定义流类。现在我正在尝试使它们与Crypto ++库兼容。我找到了question来处理自定义接收器并实现了我自己的接收器。现在我需要实现一个源代码。我搜索了文档,似乎有一个巨大的继承层次结构,所以我还不能理解它。

有人可以提供示例代码吗?

这是我的流类的一部分:

/// \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;
};

1 个答案:

答案 0 :(得分:0)

我必须查看crypto ++的源代码并从FileSource类复制大部分实现。相关文件为files.hfiles.cpp

首先,我们需要查看FileSource类。它继承自SourceTemplate<FileStore>。所以我们需要检查FileStore类。它继承自StoreFilterPutSpaceHelperNotCopyable。我们需要创建也继承自这些类的类。

我们的商店类必须具有默认构造函数并实现以下虚函数:TransferTo2CopyRangeTo2StoreInitializeStoreInitialize可以是私密的。

最后,我们的源类只需要构造函数,如果你看files.hFileSource完全在头文件中实现。

完整的实施代码仅限于files.hfiles.cpp,因此无需在此答案中复制它。