diff options
author | Jari Vetoniemi <mailroxas@gmail.com> | 2019-03-17 15:30:43 +0200 |
---|---|---|
committer | Jari Vetoniemi <mailroxas@gmail.com> | 2019-03-25 09:33:18 +0200 |
commit | 662d78b9a5bebdb98dc178ebd1f8e3384793c104 (patch) | |
tree | ea02633b41bd08957d3490d40553d389b1e78a36 /src/sw-crypt.c |
Diffstat (limited to 'src/sw-crypt.c')
-rw-r--r-- | src/sw-crypt.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/sw-crypt.c b/src/sw-crypt.c new file mode 100644 index 0000000..04c9d0f --- /dev/null +++ b/src/sw-crypt.c @@ -0,0 +1,25 @@ +#include "packet.h" +#include <stdlib.h> +#include <stdio.h> +#include <err.h> + +int +main(void) +{ + setvbuf(stdout, NULL, _IONBF, 0); + + union packet packet; + for (size_t psz; (psz = fread(packet.buf, 1, sizeof(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; +} |