// hash manipulators //------------------------------------------------- // reset - reset the hash collection to an empty // set of hashes and flags //------------------------------------------------- public void reset() { m_flags = ""; m_has_crc32 = false; m_has_sha1 = false; m_creator = null; }
} //void compute(const uint8_t *data, uint32_t length, const char *types = nullptr) { begin(types); buffer(data, length); end(); } // internal helpers //------------------------------------------------- // copyfrom - copy everything from another // collection //------------------------------------------------- void copyfrom(hash_collection src) { // copy flags directly m_flags = src.m_flags; // copy hashes m_has_crc32 = src.m_has_crc32; m_crc32 = src.m_crc32; m_has_sha1 = src.m_has_sha1; m_sha1 = src.m_sha1; // don't copy creators m_creator = null; }
// creation //------------------------------------------------- // begin - begin hashing //------------------------------------------------- void begin(string types = null) { // nuke previous creator and make a new one //delete m_creator; m_creator = new hash_creator(); // by default use all types if (string.IsNullOrEmpty(types)) { m_creator.m_doing_crc32 = true; m_creator.m_doing_sha1 = true; } // otherwise, just allocate the ones that are specified else { m_creator.m_doing_crc32 = types.IndexOf(HASH_CRC) != -1; m_creator.m_doing_sha1 = types.IndexOf(HASH_SHA1) != -1; } }
//------------------------------------------------- // end - stop hashing //------------------------------------------------- void end() { //assert(m_creator != NULL); // finish up the CRC32 if (m_creator.m_doing_crc32) { m_has_crc32 = true; m_crc32 = m_creator.m_crc32_creator.finish(); } // finish up the SHA1 if (m_creator.m_doing_sha1) { m_has_sha1 = true; m_sha1 = m_creator.m_sha1_creator.finish(); } // nuke the creator //delete m_creator; m_creator = null; }