Specify Tlsh::getHash() as a const method
scott_forman
8 years ago
17 | 17 |
|
18 | 18 |
set(VERSION_MAJOR 3)
|
19 | 19 |
set(VERSION_MINOR 4)
|
20 | |
set(VERSION_PATCH 3)
|
|
20 |
set(VERSION_PATCH 4)
|
21 | 21 |
|
22 | 22 |
# TLSH uses only half the counting buckets.
|
23 | 23 |
# It can use all the buckets now.
|
213 | 213 |
|
214 | 214 |
**3.4.3**
|
215 | 215 |
- Fix regression tests running on Windows
|
|
216 |
|
|
217 |
**3.4.4**
|
|
218 |
- Specify Tlsh::getHash() is a const method
|
65 | 65 |
void final(const unsigned char* data = NULL, unsigned int len = 0);
|
66 | 66 |
|
67 | 67 |
/* to get the hex-encoded hash code */
|
68 | |
const char* getHash();
|
|
68 |
const char* getHash() const ;
|
69 | 69 |
|
70 | 70 |
/* to get the hex-encoded hash code without allocating buffer in TlshImpl - bufSize should be TLSH_STRING_BUFFER_LEN */
|
71 | |
const char* getHash(char *buffer, unsigned int bufSize);
|
|
71 |
const char* getHash(char *buffer, unsigned int bufSize) const;
|
72 | 72 |
|
73 | 73 |
/* to bring to object back to the initial state */
|
74 | 74 |
void reset();
|
|
78 | 78 |
/* is to be excluded (len_diff=false). In general, the length should be considered in the difference calculation, but there */
|
79 | 79 |
/* could be applications where a part of the adversarial activity might be to add a lot of content. For example to add 1 million */
|
80 | 80 |
/* zero bytes at the end of a file. In that case, the caller would want to exclude the length from the calculation. */
|
81 | |
int totalDiff(Tlsh *, bool len_diff=true);
|
|
81 |
int totalDiff(const Tlsh *, bool len_diff=true) const;
|
82 | 82 |
|
83 | 83 |
/* validate TrendLSH string and reset the hash according to it */
|
84 | 84 |
int fromTlshStr(const char* str);
|
53 | 53 |
void update(const unsigned char* data, unsigned int len);
|
54 | 54 |
void final();
|
55 | 55 |
void reset();
|
56 | |
const char* hash();
|
57 | |
const char* hash(char *buffer, unsigned int bufSize); // saves allocating hash string in TLSH instance - bufSize should be TLSH_STRING_LEN + 1
|
|
56 |
const char* hash() const;
|
|
57 |
const char* hash(char *buffer, unsigned int bufSize) const; // saves allocating hash string in TLSH instance - bufSize should be TLSH_STRING_LEN + 1
|
58 | 58 |
int compare(const TlshImpl& other) const;
|
59 | 59 |
int totalDiff(const TlshImpl& other, bool len_diff=true) const;
|
60 | 60 |
int fromTlshStr(const char* str);
|
|
77 | 77 |
unsigned char tmp_code[CODE_SIZE]; // 32/64 bytes
|
78 | 78 |
} lsh_bin;
|
79 | 79 |
|
80 | |
char *lsh_code; // allocated when hash() function without buffer is called - 70/134 bytes or 74/138 bytes
|
|
80 |
mutable char *lsh_code; // allocated when hash() function without buffer is called - 70/134 bytes or 74/138 bytes
|
81 | 81 |
bool lsh_code_valid; // true iff final() or fromTlshStr complete successfully
|
82 | 82 |
};
|
83 | 83 |
|
64 | 64 |
}
|
65 | 65 |
}
|
66 | 66 |
|
67 | |
const char* Tlsh::getHash()
|
|
67 |
const char* Tlsh::getHash() const
|
68 | 68 |
{
|
69 | 69 |
if ( NULL != impl )
|
70 | 70 |
return impl->hash();
|
|
72 | 72 |
return "";
|
73 | 73 |
}
|
74 | 74 |
|
75 | |
const char* Tlsh::getHash(char *buffer, unsigned int bufSize)
|
|
75 |
const char* Tlsh::getHash (char *buffer, unsigned int bufSize) const
|
76 | 76 |
{
|
77 | 77 |
if ( NULL != impl )
|
78 | 78 |
return impl->hash(buffer, bufSize);
|
|
103 | 103 |
return !(*this==other);
|
104 | 104 |
}
|
105 | 105 |
|
106 | |
int Tlsh::totalDiff(Tlsh *other, bool len_diff)
|
|
106 |
int Tlsh::totalDiff(const Tlsh *other, bool len_diff) const
|
107 | 107 |
{
|
108 | 108 |
if( NULL==impl || NULL == other || NULL == other->impl )
|
109 | 109 |
return -(EINVAL);
|
195 | 195 |
return 0;
|
196 | 196 |
}
|
197 | 197 |
|
198 | |
const char* TlshImpl::hash(char *buffer, unsigned int bufSize)
|
|
198 |
const char* TlshImpl::hash(char *buffer, unsigned int bufSize) const
|
199 | 199 |
{
|
200 | 200 |
if (bufSize < TLSH_STRING_LEN + 1) {
|
201 | 201 |
strncpy(buffer, "", bufSize);
|
|
221 | 221 |
}
|
222 | 222 |
|
223 | 223 |
/* to get the hex-encoded hash code */
|
224 | |
const char* TlshImpl::hash()
|
|
224 |
const char* TlshImpl::hash() const
|
225 | 225 |
{
|
226 | 226 |
if (this->lsh_code != NULL) {
|
227 | 227 |
// lsh_code has been previously calculated, so just return it
|