test: Move pong response to service.c
[libisds.git] / client / computemessagehash.c
blob72660fcea41af27d18e38ba79cd51310d485e2ff
1 #define _XOPEN_SOURCE 500
2 #include <stdlib.h>
3 #include <stdio.h>
4 #include <locale.h>
5 #include <time.h>
6 #include <string.h>
7 #include <isds.h>
8 #include "common.h"
10 isds_error compute_message_hash(struct isds_ctx *ctx,
11 struct isds_message *message) {
12 isds_error err;
13 struct isds_hash *old_hash;
15 /* Detach original hash */
16 old_hash = message->envelope->hash;
17 message->envelope->hash = NULL;
19 /* Recalculate hash */
20 printf("Calculating message hash\n");
21 err = isds_compute_message_hash(ctx, message, old_hash->algorithm);
22 if (err)
23 printf("isds_compute_message_hash() failed: %s: %s\n",
24 isds_strerror(err), isds_long_message(ctx));
25 else {
26 printf("isds_compute_message_hash() succeeded:\n");
28 printf("Stored hash = ");
29 print_hash(old_hash);
31 printf("Computed hash = ");
32 print_hash(message->envelope->hash);
34 /* Compare hashes */
35 compare_hashes(old_hash, message->envelope->hash);
38 isds_hash_free(&old_hash);
39 return err;
43 int main(int argc, char **argv) {
44 struct isds_ctx *ctx = NULL;
45 isds_error err;
47 setlocale(LC_ALL, "");
49 err = isds_init();
50 if (err) {
51 printf("isds_init() failed: %s\n", isds_strerror(err));
52 exit(EXIT_FAILURE);
55 /*isds_set_logging(ILF_ALL & ~ILF_HTTP, ILL_ALL);*/
57 ctx = isds_ctx_create();
58 if (!ctx) {
59 printf("isds_ctx_create() failed");
64 /* Load plain received message */
65 struct isds_message *message = NULL;
66 void *buffer;
67 int fd;
68 size_t length;
70 if (mmap_file(SRCDIR "/server/messages/received_message-151916.xml",
71 &fd, &buffer, &length)) {
72 fprintf(stderr, "Could not map file with plain received message\n");
73 isds_ctx_free(&ctx);
74 isds_cleanup();
75 exit(EXIT_FAILURE);
78 printf("Loading plain received message\n");
79 err = isds_load_message(ctx, RAWTYPE_INCOMING_MESSAGE,
80 buffer, length, &message, BUFFER_COPY);
81 if (err)
82 printf("isds_load_message() failed: %s: %s\n",
83 isds_strerror(err), isds_long_message(ctx));
84 else {
85 printf("isds_load_message() succeeded\n");
86 compute_message_hash(ctx, message);
89 isds_message_free(&message);
90 munmap_file(fd, buffer, length);
95 /* Load plain signed message */
96 struct isds_message *message = NULL;
97 void *buffer;
98 int fd;
99 size_t length;
101 if (mmap_file(SRCDIR "/server/messages/sent_message-206720.xml",
102 &fd, &buffer, &length)) {
103 fprintf(stderr, "Could not map file with plain signed message\n");
104 isds_ctx_free(&ctx);
105 isds_cleanup();
106 exit(EXIT_FAILURE);
109 printf("Loading plain signed sent message\n");
110 err = isds_load_message(ctx, RAWTYPE_PLAIN_SIGNED_OUTGOING_MESSAGE,
111 buffer, length, &message, BUFFER_COPY);
112 if (err)
113 printf("isds_load_message() failed: %s: %s\n",
114 isds_strerror(err), isds_long_message(ctx));
115 else {
116 printf("isds_load_message() succeeded\n");
117 compute_message_hash(ctx, message);
120 isds_message_free(&message);
121 munmap_file(fd, buffer, length);
126 /* Load CMS signed message */
127 struct isds_message *message = NULL;
128 void *buffer;
129 int fd;
130 size_t length;
132 if (mmap_file(SRCDIR "/server/messages/signed_sent_message-151874.zfo",
133 &fd, &buffer, &length)) {
134 fprintf(stderr, "Could not map file with CMS signed message\n");
135 isds_ctx_free(&ctx);
136 isds_cleanup();
137 exit(EXIT_FAILURE);
140 printf("Loading CMS signed sent message\n");
141 err = isds_load_message(ctx, RAWTYPE_CMS_SIGNED_OUTGOING_MESSAGE,
142 buffer, length, &message, BUFFER_COPY);
143 if (err)
144 printf("isds_load_message() failed: %s: %s\n",
145 isds_strerror(err), isds_long_message(ctx));
146 else {
147 printf("isds_load_message() succeeded\n");
148 compute_message_hash(ctx, message);
151 isds_message_free(&message);
152 munmap_file(fd, buffer, length);
156 err = isds_ctx_free(&ctx);
157 if (err) {
158 printf("isds_ctx_free() failed: %s\n", isds_strerror(err));
162 err = isds_cleanup();
163 if (err) {
164 printf("isds_cleanup() failed: %s\n", isds_strerror(err));
167 exit (EXIT_SUCCESS);