summaryrefslogtreecommitdiff
path: root/src/sw-crypt.c
blob: 04c9d0fdc6c92d553ea375926052c86599021e53 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include "packet.h"
#include <stdlib.h>
#include <stdio.h>
#include <err.h>

int
main(void)
{
   setvbuf(stdoutNULL_IONBF0);

   union packet packet;
   for (size_t psz; (psz = fread(packet.buf, 1sizeof(packet.hdr), stdin)) > 0;) {
      if (!packet_verify(&packet))
         errx(EXIT_FAILURE"invalid packet");

      psz += fread(packet.buf + sizeof(packet.hdr), 1, packet.hdr.size - sizeof(packet.hdr), stdin);
      if (psz != packet.hdr.size)
         errx(EXIT_FAILURE"packet size doesn't match, got %zu, expected %u", psz, packet.hdr.size);

      packet_crypt(&packet);
      fwrite(packet.buf, 1, packet.hdr.size, stdout);
   }

   return EXIT_SUCCESS;
}