chiark / gitweb /
c6fe050b8d675f29a6a6bfb8162391c2e08518d5
[chiark-tcl.git] / hbytes / hbytes.h
1 /*
2  */
3 /*
4  *  hbytes raw2h BINARY                          => hex
5  *  hbytes h2raw HEX                             => binary
6  *
7  *  hbytes prefix VAR [VALUE ...]         = set VAR [concat VALUE ... $VAR]
8  *  hbytes append VAR [VALUE ...]         = set VAR [concat $VAR VALUE ...]
9  *  hbytes concat VAR [VALUE ...]         = set VAR [concat VALUE ...]
10  *  hbytes unprepend VAR PREFIXLENGTH            => prefix (removed from VAR)
11  *  hbytes unappend VAR SUFFIXLENGTH             => suffix (removed from VAR)
12  *  hbytes chopto VAR NEWVARLENGTH               => suffix (removed from VAR)
13  *                                                  (too short? error)
14  *
15  *  hbytes pkcs5 pa|ua VAR ALG                   => worked?  (always 1 for p)
16  *  hbytes pkcs5 pn|un VAR BLOCKSIZE             => worked?  (always 1 for p)
17  *  hbytes blockcipher e|d VAR ALG MODE [IV]     => IV
18  *
19  *  hbytes hash ALG VALUE                        => hash
20  *  hbytes hmac ALG VALUE KEY [MACLENGTH]        => mac
21  *
22  * Refs: HMAC: RFC2104
23  */
24
25 #ifndef HBYTES_H
26 #define HBYTES_H
27
28 #include <assert.h>
29 #include <stdlib.h>
30
31 #include <tcl.h>
32
33 typedef unsigned char Byte;
34
35 /* from hbytes.c */
36
37 typedef struct {
38   Byte *start, *end; /* always allocated dynamically */
39 } HBytes_Value; /* overlays internalRep */
40
41 extern Tcl_ObjType hbytes_type;
42
43 int staticerr(Tcl_Interp *ip, const char *m);
44 void objfreeir(Tcl_Obj *o);
45
46 Tcl_Obj *hbytes_set(Tcl_Obj *overwrite, const Byte *array, int l);
47
48 /* from enum.c */
49
50 extern Tcl_ObjType enum_nearlytype;
51
52 const void *enum_lookup_cached_func(Tcl_Interp *ip, Tcl_Obj *o,
53                                     size_t entrysize, const void *firstentry,
54                                     const char *what);
55 #define enum_lookup_cached(ip,o,table,what)                     \
56     (enum_lookup_cached_func((ip),(o),                          \
57                              sizeof((table)[0]),&(table)[0],    \
58                              (what)))
59   /* table should be a pointer to an array of structs of size
60    * entrysize, the first member of which should be a const char*.
61    * The table should finish with a null const char *.
62    * On error, 0 is returned and the ip->result will have been
63    * set to the error message.
64    */
65
66 /* useful macros */
67
68 #define HBYTES(o) ((HBytes_Value*)&(o)->internalRep.twoPtrValue)
69 #define HBYTES_LEN(o) (HBYTES((o))->end - HBYTES((o))->start)
70
71 #define TALLOC(s) ((void*)Tcl_Alloc((s)))
72 #define TFREE(f) (Tcl_Free((void*)(f)))
73
74 #endif /*HBYTES_H*/