自定义源代码的crypto++
Custom source for Crypto++
我已经为二进制I/O制作了自己的自定义流类。现在我正试图使它们与crypto++库兼容。我发现了一个问题,处理自定义水槽和实现我自己的。现在我需要实现一个源。我已经搜索了文档,似乎有一个巨大的继承层次结构,所以我还不能理解它。
有人能提供一个示例代码吗?
这是我的流类的一部分:
/// 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
类复制大部分实现。相关文件为files.h
和files.cpp
。
首先,我们需要看看FileSource
类。它继承自SourceTemplate<FileStore>
。所以我们需要检查FileStore
类。它继承自Store
、FilterPutSpaceHelper
和NotCopyable
。我们需要创建一个继承这些类的类。
store类必须有默认构造函数,并实现以下虚函数:TransferTo2
、CopyRangeTo2
和StoreInitialize
。StoreInitialize
可以是private
最后,我们的源类只需要构造函数,如果你看看files.h
, FileSource
完全是在头文件中实现的。
完整的实现代码仅限于files.h
和files.cpp
,所以没有必要在这个答案中复制它。
相关文章:
- 在Linux中哪里可以找到互斥、未来等的源代码
- 如果编译的源代码是特定于它编译的硬件的,我们如何分发它
- 使用cmake从源代码构建MySQL连接器/C++失败(与以前的声明冲突)
- 如何使用Crypto++并为RSA返回可打印的字节/字符数组
- 难以理解某些人解决IOI问题的源代码
- 使用g++编译hdf5源代码
- 如何使用C++读取另一个程序中的源代码输出
- Poco FindMySql.cmake 无法找到 MySQL 源代码
- 更改命令行 qt5 源代码构建配置的正确/快速方法
- C++出现控制台错误.我无法识别源代码的问题
- hkdf.h 在 Crypto++ 库中找不到
- Qt Quick,如何更改 Ui 源代码?
- 使用 Git 处理 C++ Visual Studio 2019 解决方案的外部依赖项源代码管理的最佳方法是什么?
- 从macOS Catalina上的源代码编译LLVM(如何解决未找到"stdio.h")
- 如何使用QT创建器获取网页源代码?
- 从源代码构建 gRPC C++
- 如何使用我构建的库,而不会从源代码出错,但不为我自己的项目编译?
- 解析 crypto++ 中的 GFP2Element
- 如何在使用 LLVM 编译时获取部分源代码的二进制代码
- 自定义源代码的crypto++