1 #include "EXTERN.h"
2 #include "perl.h"
3 #include "XSUB.h"
4 #include "ppport.h"
5 #include "_rabbit.c"
6
7 typedef struct rabbit {
8 t_instance state;
9 }* Crypt__Rabbit;
10
11 MODULE = Crypt::Rabbit PACKAGE = Crypt::Rabbit
12 PROTOTYPES: DISABLE
13
14 Crypt::Rabbit
new(class,rawkey)15 new(class, rawkey)
16 SV* rawkey
17 CODE:
18 {
19 STRLEN keyLength;
20 if (! SvPOK(rawkey))
21 croak("Key setup error: Key must be a string scalar!");
22
23 keyLength = SvCUR(rawkey);
24 if (keyLength != 16)
25 croak("Key setup error: Key must be 16 bytes long!");
26
27 Newz(0, RETVAL, 1, struct rabbit);
28 key_setup(&RETVAL->state, SvPV_nolen(rawkey));
29 }
30
31 OUTPUT:
32 RETVAL
33
34 SV*
rabbit_enc(self,input)35 rabbit_enc(self, input)
36 Crypt::Rabbit self
37 SV* input
38 CODE:
39 {
40 STRLEN bufsize;
41 unsigned char* intext = SvPV(input, bufsize);
42 RETVAL = newSVpv("", bufsize);
43 cipher(&self->state, intext, SvPV_nolen(RETVAL), bufsize);
44 }
45
46 OUTPUT:
47 RETVAL
48
49 void
50 DESTROY(self)
51 Crypt::Rabbit self
52 CODE:
53 Safefree(self);
54
55