]> git.sesse.net Git - vlc/blobdiff - src/misc/update_crypto.c
Use var_Inherit* instead of var_CreateGet*.
[vlc] / src / misc / update_crypto.c
index ac720d42ba803bd3bc10f8ae02eb0fb508616e3d..f16cb0fe10ebdf571dad46a53adadb4a2559ec2b 100644 (file)
@@ -42,7 +42,7 @@
 #include "vlc_common.h"
 #include <vlc_stream.h>
 #include <vlc_strings.h>
-#include <vlc_charset.h>
+#include <vlc_fs.h>
 
 #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 );
 }