Codebase list tlsh / 64abbac
Specify Tlsh::getHash() as a const method scott_forman 8 years ago
6 changed file(s) with 15 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
1717
1818 set(VERSION_MAJOR 3)
1919 set(VERSION_MINOR 4)
20 set(VERSION_PATCH 3)
20 set(VERSION_PATCH 4)
2121
2222 # TLSH uses only half the counting buckets.
2323 # It can use all the buckets now.
213213
214214 **3.4.3**
215215 - Fix regression tests running on Windows
216
217 **3.4.4**
218 - Specify Tlsh::getHash() is a const method
6565 void final(const unsigned char* data = NULL, unsigned int len = 0);
6666
6767 /* to get the hex-encoded hash code */
68 const char* getHash();
68 const char* getHash() const ;
6969
7070 /* 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;
7272
7373 /* to bring to object back to the initial state */
7474 void reset();
7878 /* is to be excluded (len_diff=false). In general, the length should be considered in the difference calculation, but there */
7979 /* could be applications where a part of the adversarial activity might be to add a lot of content. For example to add 1 million */
8080 /* 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;
8282
8383 /* validate TrendLSH string and reset the hash according to it */
8484 int fromTlshStr(const char* str);
5353 void update(const unsigned char* data, unsigned int len);
5454 void final();
5555 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
5858 int compare(const TlshImpl& other) const;
5959 int totalDiff(const TlshImpl& other, bool len_diff=true) const;
6060 int fromTlshStr(const char* str);
7777 unsigned char tmp_code[CODE_SIZE]; // 32/64 bytes
7878 } lsh_bin;
7979
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
8181 bool lsh_code_valid; // true iff final() or fromTlshStr complete successfully
8282 };
8383
6464 }
6565 }
6666
67 const char* Tlsh::getHash()
67 const char* Tlsh::getHash() const
6868 {
6969 if ( NULL != impl )
7070 return impl->hash();
7272 return "";
7373 }
7474
75 const char* Tlsh::getHash(char *buffer, unsigned int bufSize)
75 const char* Tlsh::getHash (char *buffer, unsigned int bufSize) const
7676 {
7777 if ( NULL != impl )
7878 return impl->hash(buffer, bufSize);
103103 return !(*this==other);
104104 }
105105
106 int Tlsh::totalDiff(Tlsh *other, bool len_diff)
106 int Tlsh::totalDiff(const Tlsh *other, bool len_diff) const
107107 {
108108 if( NULL==impl || NULL == other || NULL == other->impl )
109109 return -(EINVAL);
195195 return 0;
196196 }
197197
198 const char* TlshImpl::hash(char *buffer, unsigned int bufSize)
198 const char* TlshImpl::hash(char *buffer, unsigned int bufSize) const
199199 {
200200 if (bufSize < TLSH_STRING_LEN + 1) {
201201 strncpy(buffer, "", bufSize);
221221 }
222222
223223 /* to get the hex-encoded hash code */
224 const char* TlshImpl::hash()
224 const char* TlshImpl::hash() const
225225 {
226226 if (this->lsh_code != NULL) {
227227 // lsh_code has been previously calculated, so just return it