X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=include%2Fvlc_md5.h;h=f32bccf5ea851fcf29378055f981519bf8004e25;hb=69f5eeae3da75c81a7be56855e37d046aae5ea75;hp=b574d0a7c55d2ee99b6cbc66c421c6f4c3042163;hpb=85b29bdc288a1573d43bd524908be5748a9b3640;p=vlc diff --git a/include/vlc_md5.h b/include/vlc_md5.h index b574d0a7c5..f32bccf5ea 100644 --- a/include/vlc_md5.h +++ b/include/vlc_md5.h @@ -1,7 +1,7 @@ /***************************************************************************** * vlc_md5.h: MD5 hash ***************************************************************************** - * Copyright (C) 2004-2005 VideoLAN (Centrale Réseaux) and its contributors + * Copyright (C) 2004-2005 the VideoLAN team * $Id$ * * Authors: Jon Lech Johansen @@ -19,11 +19,16 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ -#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 @@ -38,9 +43,32 @@ struct md5_s uint32_t p_data[16]; /* Buffer to cache non-aligned writes */ }; -VLC_EXPORT(void, InitMD5, ( struct md5_s * ) ); -VLC_EXPORT(void, AddMD5, ( struct md5_s *, const uint8_t *, uint32_t ) ); -VLC_EXPORT(void, EndMD5, ( struct md5_s * ) ); -VLC_EXPORT(void, DigestMD5, ( struct md5_s *, uint32_t * ) ); +VLC_API void InitMD5( struct md5_s * ); +VLC_API void AddMD5( struct md5_s *, const void *, size_t ); +VLC_API 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