summaryrefslogtreecommitdiff
path: root/src/tool_metalink.h
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2012-05-22 01:40:11 +0900
committerDaniel Stenberg <daniel@haxx.se>2012-05-26 23:11:46 +0200
commit9f7f7925da648b3b39714e6c9fd65500a869bdfe (patch)
tree5dcc6fd6301c14d33589c86728cd798461351549 /src/tool_metalink.h
parentc3ef63f16743202eae8b0a1207130a5ba65b8ec2 (diff)
downloadcurl-9f7f7925da648b3b39714e6c9fd65500a869bdfe.tar.gz
Check checksum of downloaded file if checksum is available
Metalink file contains several hash types of checksums, such as md5, sha-1, sha-256, etc. To deal with these checksums, I created abstraction layer based on lib/curl_md5.h and lib/md5.c. Basically, they are almost the same but I changed the code so that it is not hash type dependent. Currently, GNUTLS(nettle or gcrypt) and OpenSSL functions are supported. Checksum checking is done by reopening download file. If there is an I/O error, the current implementation just prints error message and does not try next resource. In this patch, the supported hash types are: md5, sha-1 and sha-256.
Diffstat (limited to 'src/tool_metalink.h')
-rw-r--r--src/tool_metalink.h57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/tool_metalink.h b/src/tool_metalink.h
index f7a0abe84..0c9d589eb 100644
--- a/src/tool_metalink.h
+++ b/src/tool_metalink.h
@@ -56,4 +56,61 @@ int parse_metalink(struct Configurable *config, const char *infile);
*/
int check_metalink_content_type(const char *content_type);
+typedef void (* Curl_digest_init_func)(void *context);
+typedef void (* Curl_digest_update_func)(void *context,
+ const unsigned char *data,
+ unsigned int len);
+typedef void (* Curl_digest_final_func)(unsigned char *result, void *context);
+
+typedef struct {
+ Curl_digest_init_func digest_init; /* Initialize context procedure */
+ Curl_digest_update_func digest_update; /* Update context with data */
+ Curl_digest_final_func digest_final; /* Get final result procedure */
+ unsigned int digest_ctxtsize; /* Context structure size */
+ unsigned int digest_resultlen; /* Result length (bytes) */
+} digest_params;
+
+typedef struct {
+ const digest_params *digest_hash; /* Hash function definition */
+ void *digest_hashctx; /* Hash function context */
+} digest_context;
+
+extern const digest_params MD5_DIGEST_PARAMS[1];
+extern const digest_params SHA1_DIGEST_PARAMS[1];
+extern const digest_params SHA256_DIGEST_PARAMS[1];
+
+digest_context * Curl_digest_init(const digest_params *dparams);
+int Curl_digest_update(digest_context *context,
+ const unsigned char *data,
+ unsigned int len);
+int Curl_digest_final(digest_context *context, unsigned char *result);
+
+typedef struct {
+ const char *hash_name;
+ const digest_params *dparams;
+} metalink_digest_def;
+
+typedef struct {
+ const char *alias_name;
+ const metalink_digest_def *digest_def;
+} metalink_digest_alias;
+
+/*
+ * Check checksum of file denoted by filename.
+ *
+ * This function returns 1 if the checksum matches or one of the
+ * following integers:
+ *
+ * 0:
+ * Checksum didn't match.
+ * -1:
+ * Could not open file; or could not read data from file.
+ * -2:
+ * No checksum in Metalink supported; or Metalink does not contain
+ * checksum.
+ */
+int metalink_check_hash(struct Configurable *config,
+ struct metalinkfile *mlfile,
+ const char *filename);
+
#endif /* HEADER_CURL_TOOL_METALINK_H */