summaryrefslogtreecommitdiff
path: root/src/sw-crypt.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/sw-crypt.c')
-rw-r--r--src/sw-crypt.c25
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;
+}