diff --git a/include/pcp.h b/include/pcp.h index fb0d6c6..8b16eae 100644 --- a/include/pcp.h +++ b/include/pcp.h @@ -8,7 +8,6 @@ extern "C" { #include "pcp/config.h" #include "pcp/base85.h" #include "pcp/buffer.h" -#include "pcp/config.h" #include "pcp/crypto.h" #include "pcp/defines.h" #include "pcp/digital_crc32.h" diff --git a/include/pcp/pcpstream.h b/include/pcp/pcpstream.h index ff11b44..59b2d8a 100644 --- a/include/pcp/pcpstream.h +++ b/include/pcp/pcpstream.h @@ -45,6 +45,10 @@ Streams are, just like iostreams in c++, either output or input mode. + Sample usage: + + \include tests/streamtest.c + */ diff --git a/man/html/annotated.html b/man/html/annotated.html index 73cabe8..1c5b565 100644 --- a/man/html/annotated.html +++ b/man/html/annotated.html @@ -61,7 +61,7 @@ diff --git a/man/html/buffer_8h_source.html b/man/html/buffer_8h_source.html index bb2eb42..5437699 100644 --- a/man/html/buffer_8h_source.html +++ b/man/html/buffer_8h_source.html @@ -183,7 +183,7 @@ diff --git a/man/html/classes.html b/man/html/classes.html index a5ed037..8afb588 100644 --- a/man/html/classes.html +++ b/man/html/classes.html @@ -58,7 +58,7 @@ diff --git a/man/html/crypto_8h_source.html b/man/html/crypto_8h_source.html index 3d327d2..001062e 100644 --- a/man/html/crypto_8h_source.html +++ b/man/html/crypto_8h_source.html @@ -125,7 +125,7 @@ diff --git a/man/html/defines_8h_source.html b/man/html/defines_8h_source.html index 1c267c9..7ea147d 100644 --- a/man/html/defines_8h_source.html +++ b/man/html/defines_8h_source.html @@ -167,7 +167,7 @@ diff --git a/man/html/dir_76e3dfa7802a76391b3a5cc4012b4dd7.html b/man/html/dir_76e3dfa7802a76391b3a5cc4012b4dd7.html index 6cb001c..4447785 100644 --- a/man/html/dir_76e3dfa7802a76391b3a5cc4012b4dd7.html +++ b/man/html/dir_76e3dfa7802a76391b3a5cc4012b4dd7.html @@ -91,7 +91,7 @@ Files diff --git a/man/html/dir_d44c64559bbebec7f509842c48db8b23.html b/man/html/dir_d44c64559bbebec7f509842c48db8b23.html index ced4636..d1667d1 100644 --- a/man/html/dir_d44c64559bbebec7f509842c48db8b23.html +++ b/man/html/dir_d44c64559bbebec7f509842c48db8b23.html @@ -53,7 +53,7 @@ Directories diff --git a/man/html/ed_8h_source.html b/man/html/ed_8h_source.html index f37d293..d3a8ac7 100644 --- a/man/html/ed_8h_source.html +++ b/man/html/ed_8h_source.html @@ -107,7 +107,7 @@ diff --git a/man/html/files.html b/man/html/files.html index cf92552..ab26c1b 100644 --- a/man/html/files.html +++ b/man/html/files.html @@ -72,7 +72,7 @@ diff --git a/man/html/functions.html b/man/html/functions.html index a76cba9..c4351e2 100644 --- a/man/html/functions.html +++ b/man/html/functions.html @@ -266,7 +266,7 @@ diff --git a/man/html/functions_vars.html b/man/html/functions_vars.html index fccece4..c897b50 100644 --- a/man/html/functions_vars.html +++ b/man/html/functions_vars.html @@ -266,7 +266,7 @@ diff --git a/man/html/getpass_8h_source.html b/man/html/getpass_8h_source.html index a809f75..822c47a 100644 --- a/man/html/getpass_8h_source.html +++ b/man/html/getpass_8h_source.html @@ -74,7 +74,7 @@ diff --git a/man/html/group__Buffer.html b/man/html/group__Buffer.html index d5cdade..d2f958b 100644 --- a/man/html/group__Buffer.html +++ b/man/html/group__Buffer.html @@ -1518,7 +1518,7 @@ be 0 in case of errors. See also: fatals_ifany(), buffer_done() and buffer_left( diff --git a/man/html/group__CRYPTO.html b/man/html/group__CRYPTO.html index 2db4a4e..2578d01 100644 --- a/man/html/group__CRYPTO.html +++ b/man/html/group__CRYPTO.html @@ -587,7 +587,7 @@ Encrypted Output Format diff --git a/man/html/group__ED.html b/man/html/group__ED.html index 71906e4..046c4d2 100644 --- a/man/html/group__ED.html +++ b/man/html/group__ED.html @@ -434,7 +434,7 @@ Functions diff --git a/man/html/group__FATALS.html b/man/html/group__FATALS.html index 7429fd0..b989bdb 100644 --- a/man/html/group__FATALS.html +++ b/man/html/group__FATALS.html @@ -213,7 +213,7 @@ Variables diff --git a/man/html/group__KEYHASH.html b/man/html/group__KEYHASH.html index 40a3076..81ef276 100644 --- a/man/html/group__KEYHASH.html +++ b/man/html/group__KEYHASH.html @@ -396,7 +396,7 @@ Variables diff --git a/man/html/group__KEYS.html b/man/html/group__KEYS.html index 1f7275d..045ba46 100644 --- a/man/html/group__KEYS.html +++ b/man/html/group__KEYS.html @@ -702,7 +702,7 @@ Functions diff --git a/man/html/group__Pcpstream.html b/man/html/group__Pcpstream.html index 0be6836..3911be7 100644 --- a/man/html/group__Pcpstream.html +++ b/man/html/group__Pcpstream.html @@ -100,8 +100,81 @@ Functions

I/O wrapper for files or buffers.

Simple wrapper around FILE streams or Buffers, depending how the user initialized them. The Pcpstream object behaves always the same and it doesn't matter how it's backed.

We use it in the lib, e.g. in the crypto routines. That way we can support blockwise crypto on buffers or files.

-

Streams are, just like iostreams in c++, either output or input mode.

-

Typedef Documentation

+

Streams are, just like iostreams in c++, either output or input mode.

+

Sample usage:

+
#include <stdio.h>
+
#include <stdlib.h>
+
#include <limits.h>
+
+
#include <pcp.h>
+
+
int main() {
+
/* create a file with "encrypted" data */
+
FILE *out, *in;
+
unsigned char clear[8] = "ABCDEFGH";
+
unsigned char key[8] = "IxD8Lq1K";
+
unsigned char crypt[8] = {0};
+
int blocks = 8;
+
int i = 0;
+
+
if((out = fopen("teststream.out", "wb+")) == NULL) {
+
fprintf(stderr, "oops, could not open file!\n");
+
return 1;
+
}
+
Pcpstream *pout = ps_new_file(out);
+
+
/* "encrypt" a couple of times into the file */
+
for(i=0; i<blocks; i++) {
+
memcpy(crypt, clear, 8);
+
_xorbuf(key, crypt, 8);
+
ps_write(pout, crypt, 8);
+
}
+
ps_close(pout);
+
fclose(out);
+
+
/* read it in again using an in and an out stream */
+
if((in = fopen("teststream.out", "rb")) == NULL) {
+
fprintf(stderr, "oops, could not open file!\n");
+
return 1;
+
}
+
Pcpstream *pin = ps_new_file(in);
+
+
/* we'll use this stream to put the "decrypted" data in.
+
note, that this could be a file as well. */
+
Pcpstream *pclear = ps_new_outbuffer();
+
+
/* read and "decrypt" */
+
for(i=0; i<blocks; i++) {
+
ps_read(pin, crypt, 8);
+
_xorbuf(key, crypt, 8);
+
ps_write(pclear, crypt, 8);
+
}
+
ps_close(pin);
+
fclose(in);
+
+
/* now extract the buffer from the output stream */
+
Buffer *result = ps_buffer(pclear);
+
+
/* and verify if it's "decrypted" (re-use crypt) */
+
for(i=0; i<blocks; i++) {
+
buffer_get_chunk(result, crypt, 8);
+
if(memcmp(crypt, clear, 8) != 0) {
+
fprintf(stderr, "Oops, block %d doesn't match\n", i);
+
goto error;
+
}
+
}
+
+
ps_close(pclear);
+
+
fprintf(stderr, "done\n");
+
+
return 0;
+
+
error:
+
ps_close(pclear);
+
return 1;
+
}
+

Typedef Documentation

@@ -114,7 +187,7 @@ Functions

The name used everywhere.

-

Definition at line 63 of file pcpstream.h.

+

Definition at line 67 of file pcpstream.h.

@@ -459,7 +532,7 @@ Functions diff --git a/man/html/group__PubKeyExport.html b/man/html/group__PubKeyExport.html index 365a287..d1da0c4 100644 --- a/man/html/group__PubKeyExport.html +++ b/man/html/group__PubKeyExport.html @@ -302,7 +302,7 @@ Functions diff --git a/man/html/group__UTILs.html b/man/html/group__UTILs.html index 58bee03..03b3c43 100644 --- a/man/html/group__UTILs.html +++ b/man/html/group__UTILs.html @@ -231,7 +231,7 @@ Functions diff --git a/man/html/group__VAULT.html b/man/html/group__VAULT.html index 5bc6d8d..cec2cda 100644 --- a/man/html/group__VAULT.html +++ b/man/html/group__VAULT.html @@ -360,7 +360,7 @@ Vault File Format diff --git a/man/html/group__Z85.html b/man/html/group__Z85.html index af71f6b..2b7d20b 100644 --- a/man/html/group__Z85.html +++ b/man/html/group__Z85.html @@ -300,7 +300,7 @@ Functions diff --git a/man/html/index.html b/man/html/index.html index efc1d90..960e9c1 100644 --- a/man/html/index.html +++ b/man/html/index.html @@ -122,7 +122,7 @@ Sample usage diff --git a/man/html/key_8h_source.html b/man/html/key_8h_source.html index d29362c..3b62120 100644 --- a/man/html/key_8h_source.html +++ b/man/html/key_8h_source.html @@ -219,7 +219,7 @@ diff --git a/man/html/keyhash_8h_source.html b/man/html/keyhash_8h_source.html index 8fda272..9cb09c2 100644 --- a/man/html/keyhash_8h_source.html +++ b/man/html/keyhash_8h_source.html @@ -125,7 +125,7 @@ diff --git a/man/html/keysig_8h_source.html b/man/html/keysig_8h_source.html index 611590c..1e55467 100644 --- a/man/html/keysig_8h_source.html +++ b/man/html/keysig_8h_source.html @@ -111,7 +111,7 @@ diff --git a/man/html/mac_8h_source.html b/man/html/mac_8h_source.html index ef4a719..1c0cc76 100644 --- a/man/html/mac_8h_source.html +++ b/man/html/mac_8h_source.html @@ -105,7 +105,7 @@ diff --git a/man/html/mem_8h_source.html b/man/html/mem_8h_source.html index 9f9368f..dbf1738 100644 --- a/man/html/mem_8h_source.html +++ b/man/html/mem_8h_source.html @@ -99,7 +99,7 @@ diff --git a/man/html/mgmt_8h_source.html b/man/html/mgmt_8h_source.html index ecd351f..6d35f4e 100644 --- a/man/html/mgmt_8h_source.html +++ b/man/html/mgmt_8h_source.html @@ -191,7 +191,7 @@ diff --git a/man/html/modules.html b/man/html/modules.html index 3166fac..bea334e 100644 --- a/man/html/modules.html +++ b/man/html/modules.html @@ -58,7 +58,7 @@ diff --git a/man/html/pad_8h_source.html b/man/html/pad_8h_source.html index 08c9a80..a9e08d2 100644 --- a/man/html/pad_8h_source.html +++ b/man/html/pad_8h_source.html @@ -150,7 +150,7 @@ diff --git a/man/html/pcpstream_8h_source.html b/man/html/pcpstream_8h_source.html index 65de4cd..d1e19ef 100644 --- a/man/html/pcpstream_8h_source.html +++ b/man/html/pcpstream_8h_source.html @@ -80,50 +80,50 @@
29 #include "defines.h"
30 #include "buffer.h"
31 
-
54 struct _pcp_stream_t {
-
55  FILE *fd;
-
56  Buffer *b;
-
57  uint8_t is_buffer;
-
58  uint8_t eof;
-
59  uint8_t err;
-
60 };
-
61 
-
63 typedef struct _pcp_stream_t Pcpstream;
-
64 
-
65 /* initialize a new empty stream */
-
66 Pcpstream *ps_init(void);
-
67 
-
76 Pcpstream *ps_new_file(FILE *backendfd);
-
77 
-
86 Pcpstream *ps_new_inbuffer(Buffer *b);
-
87 
-
95 Pcpstream *ps_new_outbuffer();
-
96 
-
97 
-
118 size_t ps_read(Pcpstream *stream, void *buf, size_t readbytes);
-
119 
-
135 size_t ps_write(Pcpstream *stream, void *buf, size_t writebytes);
-
136 
-
152 size_t ps_print(Pcpstream *stream, const char * fmt, ...);
-
153 
-
163 size_t ps_tell(Pcpstream *stream);
-
164 
-
176 Buffer *ps_buffer(Pcpstream *stream);
-
177 
-
187 void ps_close(Pcpstream *stream);
-
188 
-
200 int ps_end(Pcpstream *stream);
-
201 
-
208 int ps_err(Pcpstream *stream);
-
209 
-
210 
-
211 #endif // HAVE_PCP_PCPSTEAM_H
-
212 
+
58 struct _pcp_stream_t {
+
59  FILE *fd;
+
60  Buffer *b;
+
61  uint8_t is_buffer;
+
62  uint8_t eof;
+
63  uint8_t err;
+
64 };
+
65 
+
67 typedef struct _pcp_stream_t Pcpstream;
+
68 
+
69 /* initialize a new empty stream */
+
70 Pcpstream *ps_init(void);
+
71 
+
80 Pcpstream *ps_new_file(FILE *backendfd);
+
81 
+
90 Pcpstream *ps_new_inbuffer(Buffer *b);
+
91 
+
99 Pcpstream *ps_new_outbuffer();
+
100 
+
101 
+
122 size_t ps_read(Pcpstream *stream, void *buf, size_t readbytes);
+
123 
+
139 size_t ps_write(Pcpstream *stream, void *buf, size_t writebytes);
+
140 
+
156 size_t ps_print(Pcpstream *stream, const char * fmt, ...);
+
157 
+
167 size_t ps_tell(Pcpstream *stream);
+
168 
+
180 Buffer *ps_buffer(Pcpstream *stream);
+
181 
+
191 void ps_close(Pcpstream *stream);
+
192 
+
204 int ps_end(Pcpstream *stream);
+
205 
+
212 int ps_err(Pcpstream *stream);
213 
+
214 
+
215 #endif // HAVE_PCP_PCPSTEAM_H
+
216 
+
217 
diff --git a/man/html/plist_8h_source.html b/man/html/plist_8h_source.html index 7691da4..522d554 100644 --- a/man/html/plist_8h_source.html +++ b/man/html/plist_8h_source.html @@ -128,7 +128,7 @@ diff --git a/man/html/randomart_8h_source.html b/man/html/randomart_8h_source.html index 54c9666..d826564 100644 --- a/man/html/randomart_8h_source.html +++ b/man/html/randomart_8h_source.html @@ -106,7 +106,7 @@ diff --git a/man/html/scrypt_8h_source.html b/man/html/scrypt_8h_source.html index 7b756e8..01f959d 100644 --- a/man/html/scrypt_8h_source.html +++ b/man/html/scrypt_8h_source.html @@ -94,7 +94,7 @@ diff --git a/man/html/struct__pcp__buffer-members.html b/man/html/struct__pcp__buffer-members.html index 280a80e..281f978 100644 --- a/man/html/struct__pcp__buffer-members.html +++ b/man/html/struct__pcp__buffer-members.html @@ -60,7 +60,7 @@ diff --git a/man/html/struct__pcp__buffer.html b/man/html/struct__pcp__buffer.html index ed04d94..c9086c8 100644 --- a/man/html/struct__pcp__buffer.html +++ b/man/html/struct__pcp__buffer.html @@ -222,7 +222,7 @@ Public Attributes diff --git a/man/html/struct__pcp__key__t-members.html b/man/html/struct__pcp__key__t-members.html index 23d4f38..faeaaec 100644 --- a/man/html/struct__pcp__key__t-members.html +++ b/man/html/struct__pcp__key__t-members.html @@ -67,7 +67,7 @@ diff --git a/man/html/struct__pcp__key__t.html b/man/html/struct__pcp__key__t.html index 793f968..96a08e3 100644 --- a/man/html/struct__pcp__key__t.html +++ b/man/html/struct__pcp__key__t.html @@ -365,7 +365,7 @@ Public Attributes diff --git a/man/html/struct__pcp__pubkey__t-members.html b/man/html/struct__pcp__pubkey__t-members.html index 7e8ad63..8b581f9 100644 --- a/man/html/struct__pcp__pubkey__t-members.html +++ b/man/html/struct__pcp__pubkey__t-members.html @@ -65,7 +65,7 @@ diff --git a/man/html/struct__pcp__pubkey__t.html b/man/html/struct__pcp__pubkey__t.html index b53a52b..53b002c 100644 --- a/man/html/struct__pcp__pubkey__t.html +++ b/man/html/struct__pcp__pubkey__t.html @@ -317,7 +317,7 @@ Public Attributes diff --git a/man/html/struct__pcp__rec__t-members.html b/man/html/struct__pcp__rec__t-members.html index 7b269e8..65e6db4 100644 --- a/man/html/struct__pcp__rec__t-members.html +++ b/man/html/struct__pcp__rec__t-members.html @@ -56,7 +56,7 @@ diff --git a/man/html/struct__pcp__rec__t.html b/man/html/struct__pcp__rec__t.html index 659ce4d..0f4cd91 100644 --- a/man/html/struct__pcp__rec__t.html +++ b/man/html/struct__pcp__rec__t.html @@ -147,7 +147,7 @@ Public Attributes diff --git a/man/html/struct__pcp__stream__t-members.html b/man/html/struct__pcp__stream__t-members.html index 309e31c..f036c81 100644 --- a/man/html/struct__pcp__stream__t-members.html +++ b/man/html/struct__pcp__stream__t-members.html @@ -57,7 +57,7 @@ diff --git a/man/html/struct__pcp__stream__t.html b/man/html/struct__pcp__stream__t.html index 8f1bbd6..d3e473f 100644 --- a/man/html/struct__pcp__stream__t.html +++ b/man/html/struct__pcp__stream__t.html @@ -76,7 +76,7 @@ Public Attributes

Detailed Description

An I/O wrapper object backed by a file or a buffer.

-

Definition at line 54 of file pcpstream.h.

+

Definition at line 58 of file pcpstream.h.

Member Data Documentation

@@ -90,7 +90,7 @@ Public Attributes

The backend Buffer object.

-

Definition at line 56 of file pcpstream.h.

+

Definition at line 60 of file pcpstream.h.

@@ -106,7 +106,7 @@ Public Attributes

Set to 1 if EOF reached.

-

Definition at line 58 of file pcpstream.h.

+

Definition at line 62 of file pcpstream.h.

@@ -122,7 +122,7 @@ Public Attributes

Set to 1 if an error occured.

-

Definition at line 59 of file pcpstream.h.

+

Definition at line 63 of file pcpstream.h.

@@ -138,7 +138,7 @@ Public Attributes

The backend FILE stream.

-

Definition at line 55 of file pcpstream.h.

+

Definition at line 59 of file pcpstream.h.

@@ -154,7 +154,7 @@ Public Attributes

Set to 1 if the backend is a Buffer.

-

Definition at line 57 of file pcpstream.h.

+

Definition at line 61 of file pcpstream.h.

@@ -164,7 +164,7 @@ Public Attributes diff --git a/man/html/struct__vault__header__t-members.html b/man/html/struct__vault__header__t-members.html index ec8987b..9beb76d 100644 --- a/man/html/struct__vault__header__t-members.html +++ b/man/html/struct__vault__header__t-members.html @@ -55,7 +55,7 @@ diff --git a/man/html/struct__vault__header__t.html b/man/html/struct__vault__header__t.html index 36f536e..4ee8c91 100644 --- a/man/html/struct__vault__header__t.html +++ b/man/html/struct__vault__header__t.html @@ -127,7 +127,7 @@ Public Attributes diff --git a/man/html/struct__vault__item__header__t-members.html b/man/html/struct__vault__item__header__t-members.html index d62813c..3cfcedb 100644 --- a/man/html/struct__vault__item__header__t-members.html +++ b/man/html/struct__vault__item__header__t-members.html @@ -56,7 +56,7 @@ diff --git a/man/html/struct__vault__item__header__t.html b/man/html/struct__vault__item__header__t.html index e618ac6..397534a 100644 --- a/man/html/struct__vault__item__header__t.html +++ b/man/html/struct__vault__item__header__t.html @@ -146,7 +146,7 @@ Public Attributes diff --git a/man/html/struct__vault__t-members.html b/man/html/struct__vault__t-members.html index 35200dd..2d9aad9 100644 --- a/man/html/struct__vault__t-members.html +++ b/man/html/struct__vault__t-members.html @@ -61,7 +61,7 @@ diff --git a/man/html/struct__vault__t.html b/man/html/struct__vault__t.html index e2c9af5..2bdcbaf 100644 --- a/man/html/struct__vault__t.html +++ b/man/html/struct__vault__t.html @@ -240,7 +240,7 @@ Public Attributes diff --git a/man/html/util_8h_source.html b/man/html/util_8h_source.html index 38d1c79..b4f36f2 100644 --- a/man/html/util_8h_source.html +++ b/man/html/util_8h_source.html @@ -98,7 +98,7 @@ diff --git a/man/html/vault_8h_source.html b/man/html/vault_8h_source.html index de3149a..848b0b9 100644 --- a/man/html/vault_8h_source.html +++ b/man/html/vault_8h_source.html @@ -171,7 +171,7 @@ diff --git a/man/html/version_8h_source.html b/man/html/version_8h_source.html index 95e9e86..63673b9 100644 --- a/man/html/version_8h_source.html +++ b/man/html/version_8h_source.html @@ -89,7 +89,7 @@ diff --git a/man/html/z85_8h_source.html b/man/html/z85_8h_source.html index 8d46637..8d996ae 100644 --- a/man/html/z85_8h_source.html +++ b/man/html/z85_8h_source.html @@ -101,7 +101,7 @@ diff --git a/tests/streamtest.c b/tests/streamtest.c new file mode 100644 index 0000000..ff8a694 --- /dev/null +++ b/tests/streamtest.c @@ -0,0 +1,72 @@ +#include +#include +#include + +#include + +int main() { + /* create a file with "encrypted" data */ + FILE *out, *in; + unsigned char clear[8] = "ABCDEFGH"; + unsigned char key[8] = "IxD8Lq1K"; + unsigned char crypt[8] = {0}; + int blocks = 8; + int i = 0; + + if((out = fopen("teststream.out", "wb+")) == NULL) { + fprintf(stderr, "oops, could not open file!\n"); + return 1; + } + Pcpstream *pout = ps_new_file(out); + + /* "encrypt" a couple of times into the file */ + for(i=0; i