X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=include%2Fvlc_md5.h;h=d05126980ffacc7e6778cdc35a74339374386292;hb=85a9ea3bac5bd026836c3e6bad37c42f1161fca7;hp=7c84fb9d0a0ca191bc79d2e48c85b3a519ffc6a0;hpb=4e4b03cdd235c50480f15243bc92ea6a4fc9ec5e;p=vlc diff --git a/include/vlc_md5.h b/include/vlc_md5.h index 7c84fb9d0a..d05126980f 100644 --- a/include/vlc_md5.h +++ b/include/vlc_md5.h @@ -22,12 +22,13 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ -#if !defined( __LIBVLC__ ) - #error You are not libvlc or one of its plugins. You cannot include this file -#endif +#ifndef VLC_MD5_H +# define VLC_MD5_H -#ifndef _VLC_MD5_H -# define _VLC_MD5_H +/** + * \file + * This file defines functions and structures for handling md5 checksums + */ /***************************************************************************** * md5_s: MD5 message structure @@ -46,4 +47,28 @@ VLC_EXPORT(void, InitMD5, ( struct md5_s * ) ); VLC_EXPORT(void, AddMD5, ( struct md5_s *, const void *, size_t ) ); VLC_EXPORT(void, EndMD5, ( struct md5_s * ) ); +/** + * Returns a char representation of the md5 hash, as shown by UNIX md5 or + * md5sum tools. + */ +static inline char * psz_md5_hash( struct md5_s *md5_s ) +{ + char *psz = malloc( 33 ); /* md5 string is 32 bytes + NULL character */ + if( !psz ) return NULL; + + int i; + for ( i = 0; i < 4; i++ ) + { + sprintf( &psz[8*i], "%02x%02x%02x%02x", + md5_s->p_digest[i] & 0xff, + ( md5_s->p_digest[i] >> 8 ) & 0xff, + ( md5_s->p_digest[i] >> 16 ) & 0xff, + md5_s->p_digest[i] >> 24 + ); + } + psz[32] = '\0'; + + return psz; +} + #endif