DiceKeys Seeded Cryptography Library
sodium-buffer.hpp
1 #pragma once
2 
3 #include "sodium-initializer.hpp"
4 #include "sodium.h"
5 #include <memory.h>
6 #include <vector>
7 #include <string>
8 
9 // class SodiumBufferSerializationIterator;
10 
27 class SodiumBuffer {
28 public:
33  unsigned char* data;
38  const size_t length;
39 
49  SodiumBuffer(size_t length = 0, const unsigned char* bufferData = NULL);
50 
55  SodiumBuffer(const std::vector<unsigned char>& bufferData);
56 
62  SodiumBuffer(const SodiumBuffer& other);
63 
67  SodiumBuffer(const std::string str);
68 
86  const std::vector<const SodiumBuffer*>& buffers
87  );
88 
102  const std::vector<SodiumBuffer> splitFixedLengthList(
103  int count
104  ) const;
105 
114  static SodiumBuffer fromHexString(const std::string& hexStr);
115 
120  ~SodiumBuffer();
121 
129  const std::vector<unsigned char> toVector() const;
130 
136  const std::string toUtf8String() const;
137 
145  const std::string toHexString() const;
146 
151  //SodiumBufferSerializationIterator getSerializationIterator() const;
152 };
SodiumBuffer
A byte array containing a length and a pointer to memory (the data field), which ensures data is eras...
Definition: sodium-buffer.hpp:27
SodiumBuffer::length
const size_t length
The length of the buffer.
Definition: sodium-buffer.hpp:38
SodiumBuffer::data
unsigned char * data
A pointer to the buffer of bytes.
Definition: sodium-buffer.hpp:33
SodiumBuffer::~SodiumBuffer
~SodiumBuffer()
Destroy the SodiumBuffer object, freeing and zero-ing the buffer.
Definition: sodium-buffer.cpp:48
SodiumBuffer::combineFixedLengthList
static const SodiumBuffer combineFixedLengthList(const std::vector< const SodiumBuffer * > &buffers)
Create a new SodiumBuffer that stored a fixed-length array of other $n$ other sodium buffers.
Definition: sodium-buffer.cpp:94
SodiumBuffer::splitFixedLengthList
const std::vector< SodiumBuffer > splitFixedLengthList(int count) const
Deserialize a fixed-length list of SodiumBuffers that had been serialized to a single buffer via a ca...
Definition: sodium-buffer.cpp:139
SodiumBuffer::toVector
const std::vector< unsigned char > toVector() const
Copy the buffer into a byte vector, which by nature of being a standard library class will be stored ...
Definition: sodium-buffer.cpp:52
SodiumBuffer::SodiumBuffer
SodiumBuffer(size_t length=0, const unsigned char *bufferData=NULL)
Construct a new SodiumBuffer by specifying its length and optionally specifying a pointer to a buffer...
Definition: sodium-buffer.cpp:26
SodiumBuffer::toUtf8String
const std::string toUtf8String() const
If the data in the buffer represents a UTF8-format string, reconstitute the data back into a UTF8 std...
Definition: sodium-buffer.cpp:58
SodiumBuffer::toHexString
const std::string toHexString() const
Convert the data in the buffer to a lowercase hex string, which by nature of being stored in a string...
Definition: sodium-buffer.cpp:62
SodiumBuffer::fromHexString
static SodiumBuffer fromHexString(const std::string &hexStr)
Create a SodiumBuffer from a string of hex digits.
Definition: sodium-buffer.cpp:77