X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fmisc%2Fupdate_crypto.c;h=f16cb0fe10ebdf571dad46a53adadb4a2559ec2b;hb=12ade3e3bc975d5426ba4af155b7372c31093b31;hp=ac720d42ba803bd3bc10f8ae02eb0fb508616e3d;hpb=2de5a59ad0b05eb2554b228675d6719fc20fa658;p=vlc diff --git a/src/misc/update_crypto.c b/src/misc/update_crypto.c index ac720d42ba..f16cb0fe10 100644 --- a/src/misc/update_crypto.c +++ b/src/misc/update_crypto.c @@ -42,7 +42,7 @@ #include "vlc_common.h" #include #include -#include +#include #include "update.h" @@ -653,41 +653,13 @@ error: } -/* hash a text - * * provided as a buffer (\0 terminated) - * * with "\r\n" line endings if it's a text signature, else use UNIX line - * * endings - */ -static int hash_from_string( const char *psz_string, gcry_md_hd_t hd, - bool text_signature ) -{ - while( *psz_string ) - { - size_t i_len = strcspn( psz_string, "\r\n" ); - if( !i_len ) - break; - - gcry_md_write( hd, psz_string, i_len ); - if( text_signature ) - gcry_md_putc( hd, '\r' ); - gcry_md_putc( hd, '\n' ); - - psz_string += i_len; - while( *psz_string == '\r' || *psz_string == '\n' ) - psz_string++; - } - - return 0; -} - - /* hash a binary file */ static int hash_from_binary_file( const char *psz_file, gcry_md_hd_t hd ) { uint8_t buffer[4096]; size_t i_read; - FILE *f = utf8_fopen( psz_file, "r" ); + FILE *f = vlc_fopen( psz_file, "r" ); if( !f ) return -1; @@ -754,11 +726,23 @@ uint8_t *hash_sha1_from_text( const char *psz_string, if( gcry_md_open( &hd, GCRY_MD_SHA1, 0 ) ) return NULL; - if( hash_from_string( psz_string, hd, p_sig->type == TEXT_SIGNATURE ) < 0 ) + if( p_sig->type == TEXT_SIGNATURE ) + while( *psz_string ) { - gcry_md_close( hd ); - return NULL; + size_t i_len = strcspn( psz_string, "\r\n" ); + if( !i_len ) + break; + + gcry_md_write( hd, psz_string, i_len ); + gcry_md_putc( hd, '\r' ); + gcry_md_putc( hd, '\n' ); + + psz_string += i_len; + while( *psz_string == '\r' || *psz_string == '\n' ) + psz_string++; } + else + gcry_md_write( hd, psz_string, strlen( psz_string ) ); return hash_finish( hd, p_sig ); }