library/src/blockclass/BP-BlockClass.cc
// Generates a SHA1 has provided given input.
Generates a SHA1 has provided given input.
Generates a SHA1 has provided given input .
bool Block::GenSHA1(char *in, size_t in_size)
{
	if(!in || !in_size)
		return ERR_FAILURE;
	if(this->sha1_ascii)
	{
		tq_free(this->tq, this->sha1_ascii);
		this->sha1_ascii = NULL;
	}
	this->sha1_ascii = (char *) tq_calloc(this->tq, 41, 1, BPLN);
	unsigned char obuf[20];
	SHA1((unsigned char *) in, in_size, (unsigned char *) &obuf);
	size_t i = 0;
	for(; i < 20; i++)
	{
		snprintf((char *) &this->sha1_ascii[bpstrlen(this->sha1_ascii)], 4, "%.02x", obuf[i]);
	}
	return ERR_SUCCESS;
}
bool Block :: GenSHA1 ( char * in , size_t in_size ) { if ( ! in || ! in_size ) return ERR_FAILURE ; if ( this -> sha1_ascii ) { tq_free ( this -> tq , this -> sha1_ascii ) ; this -> sha1_ascii = NULL ; } this -> sha1_ascii = ( char * ) tq_calloc ( this -> tq , 41 , 1 , BPLN ) ; unsigned char obuf [ 20 ] ; SHA1 ( ( unsigned char * ) in , in_size , ( unsigned char * ) & obuf ) ; size_t i = 0 ; for ( ; i < 20 ; i ++ ) { snprintf ( ( char * ) & this -> sha1_ascii [ bpstrlen ( this -> sha1_ascii ) ] , 4 , " " , obuf [ i ] ) ; } return ERR_SUCCESS ; }
Generates a SHA1 has provided given input.
Generates a SHA1 has provided given input .
// ensure we have an in pointer and a size // ensure we destroy the sha1 data if necessary // now create ascii buffer // create hash // create ascii hash from binary // return indicating success