This repository has been archived by the owner on Mar 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
blob.h
62 lines (44 loc) · 1.67 KB
/
blob.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#ifndef BLOB_H
#define BLOB_H
#include <vector>
#include <string>
/** \brief Universal blob representation */
class Blob
{
public:
/** \brief Create new hash-validated blob */
template< typename T >
static Blob newHashValidatedBlob( char blobType, const T& content )
{
static_assert( sizeof(content[0]) == 1, "content's element must be of byte size" );
Blob ret;
// Build the unencrypted data buffer
ret.sourceData.resize( content.size() + 1 );
ret.sourceData[0] = blobType;
std::copy( content.begin(), content.end(), ret.sourceData.begin()+1 );
// Create bid, key and encrypted data
ret.rebuildHashValidatedBlob();
return ret;
}
/** \brief Get the current key */
inline const std::string& getKey() const { return key; }
/** \brief Get the current bid */
inline const std::string& getBid() const { return bid; }
/** \brief Get the source data */
inline const std::vector< char >& getSourceData() const { return sourceData; }
/** \brief Get the result data */
inline const std::vector< char >& getResultData() const { return resultData; }
/** \brief Get rid of data entries, leave bid and key only */
void cutData();
/** \brief Dump the content of a blob to the std::count */
void dump( std::string name ) const;
private:
inline Blob()
{}
void rebuildHashValidatedBlob();
std::vector< char > sourceData;
std::vector< char > resultData;
std::string bid;
std::string key;
};
#endif // BLOB_H