1 /* delimited, authenticated, encrypted connection */ 2 enum { 3 Maxmsg = 4096, /* messages > Maxmsg bytes are truncated */ 4 }; 5 6 typedef struct SConn SConn; 7 struct SConn { 8 void *chan; 9 int secretlen; 10 int (*secret)(SConn*, uchar*, int); 11 int (*read)(SConn*, uchar*, int); /* <0 if error; errmess in buffer */ 12 int (*write)(SConn*, uchar*, int); 13 void (*free)(SConn*); /* also closes file descriptor */ 14 }; 15 16 SConn *newSConn(int); /* arg is open file descriptor */ 17 18 /* 19 * secret(s,b,dir) sets secret for digest, encrypt, using the secretlen 20 * bytes in b to form keys for the two directions; 21 * set dir=0 in client, dir=1 in server 22 */ 23 24 /* error convention: write !message in-band */ 25 void writerr(SConn*, char*); 26 27 /* 28 * returns -1 upon error, with error message in buf 29 * call with buf of size Maxmsg+1 30 */ 31 int readstr(SConn*, char*); 32 33 void *emalloc(ulong); /* dies on failure; clears memory */ 34 void *erealloc(void*, ulong); 35 char *estrdup(char*); 36