File Coverage

inc/CryptX_Mac_Pelican.xs.inc
Criterion Covered Total %
statement 58 63 92.0
branch 41 60 68.3
condition n/a
subroutine n/a
pod n/a
total 99 123 80.4


line stmt bran cond sub pod time code
1             MODULE = CryptX PACKAGE = Crypt::Mac::Pelican
2              
3             PROTOTYPES: DISABLE
4              
5             ### BEWARE - GENERATED FILE, DO NOT EDIT MANUALLY!
6              
7             Crypt::Mac::Pelican
8             new(Class, SV * key)
9             CODE:
10             {
11 30           STRLEN k_len=0;
12 30           unsigned char *k=NULL;
13             int rv;
14              
15 30 50         if (!SvPOK(key)) croak("FATAL: key must be string/buffer scalar");
16 30 50         k = (unsigned char *) SvPVbyte(key, k_len);
17              
18 30           Newz(0, RETVAL, 1, pelican_state);
19 30 50         if (!RETVAL) croak("FATAL: Newz failed");
20              
21 30           rv = pelican_init(RETVAL, k, (unsigned long)k_len);
22 30 50         if (rv != CRYPT_OK) {
23 0           Safefree(RETVAL);
24 0           croak("FATAL: pelican_init failed: %s", error_to_string(rv));
25             }
26             }
27             OUTPUT:
28             RETVAL
29              
30             void
31             DESTROY(Crypt::Mac::Pelican self)
32             CODE:
33 30           Safefree(self);
34              
35             Crypt::Mac::Pelican
36             clone(Crypt::Mac::Pelican self)
37             CODE:
38 0           Newz(0, RETVAL, 1, pelican_state);
39 0 0         if (!RETVAL) croak("FATAL: Newz failed");
40 0           Copy(self, RETVAL, 1, pelican_state);
41             OUTPUT:
42             RETVAL
43              
44             void
45             add(Crypt::Mac::Pelican self, ...)
46             PPCODE:
47             {
48             int rv, i;
49             STRLEN in_data_len;
50             unsigned char *in_data;
51              
52 76 100         for(i = 1; i < items; i++) {
53 42 100         in_data = (unsigned char *)SvPVbyte(ST(i), in_data_len);
54 42 100         if (in_data_len > 0) {
55 34           rv = pelican_process(self, in_data, (unsigned long)in_data_len);
56 34 50         if (rv != CRYPT_OK) croak("FATAL: pelican_process failed: %s", error_to_string(rv));
57             }
58             }
59 34 50         XPUSHs(ST(0)); /* return self */
60             }
61              
62             SV *
63             mac(Crypt::Mac::Pelican self)
64             ALIAS:
65             hexmac = 1
66             b64mac = 2
67             b64umac = 3
68             CODE:
69             {
70             unsigned char mac[MAXBLOCKSIZE];
71             unsigned long maclen, outlen;
72             int rv;
73             char out[MAXBLOCKSIZE*2+1];
74              
75 30           maclen = 16;
76 30           rv = pelican_done(self, mac);
77 30 50         if (rv != CRYPT_OK) croak("FATAL: pelican_done failed: %s", error_to_string(rv));
78 30           outlen = sizeof(out);
79 30 100         if (ix == 3) {
80 1           rv = base64url_encode(mac, maclen, out, &outlen);
81 1 50         if (rv != CRYPT_OK) croak("FATAL: base64url_encode failed: %s", error_to_string(rv));
82 1           RETVAL = newSVpvn(out, outlen);
83             }
84 29 100         else if (ix == 2) {
85 1           rv = base64_encode(mac, maclen, out, &outlen);
86 1 50         if (rv != CRYPT_OK) croak("FATAL: base64_encode failed: %s", error_to_string(rv));
87 1           RETVAL = newSVpvn(out, outlen);
88             }
89 28 100         else if (ix == 1) {
90 14           rv = base16_encode(mac, maclen, out, &outlen, 0);
91 14 50         if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv));
92 14           RETVAL = newSVpvn(out, outlen);
93             }
94             else {
95 14           RETVAL = newSVpvn((char * )mac, maclen);
96             }
97             }
98             OUTPUT:
99             RETVAL
100              
101             SV *
102             pelican(SV * key, ...)
103             ALIAS:
104             pelican_hex = 1
105             pelican_b64 = 2
106             pelican_b64u = 3
107             CODE:
108             {
109             STRLEN inlen, klen;
110             unsigned char *in;
111 52 50         unsigned char *k = (unsigned char *)SvPVbyte(key, klen);
112             int rv, i;
113             unsigned char mac[MAXBLOCKSIZE];
114 52           unsigned long len = sizeof(mac), outlen;
115             char out[MAXBLOCKSIZE*2];
116             pelican_state st;
117              
118 52           len = 16;
119 52           rv = pelican_init(&st, k, (unsigned long)klen);
120 52 50         if (rv != CRYPT_OK) croak("FATAL: pelican_init failed: %s", error_to_string(rv));
121 112 100         for (i = 1; i < items; i++) {
122 60 100         in = (unsigned char *)SvPVbyte(ST(i), inlen);
123 60 100         if (inlen > 0) {
124 44           rv = pelican_process(&st, in, (unsigned long)inlen);
125 44 50         if (rv != CRYPT_OK) croak("FATAL: pelican_process failed: %s", error_to_string(rv));
126             }
127             }
128 52           rv = pelican_done(&st, mac);
129 52 50         if (rv != CRYPT_OK) croak("FATAL: pelican_done failed: %s", error_to_string(rv));
130              
131 52           outlen = sizeof(out);
132 52 100         if (ix == 3) {
133 13           rv = base64url_encode(mac, len, out, &outlen);
134 13 50         if (rv != CRYPT_OK) croak("FATAL: base64url_encode failed: %s", error_to_string(rv));
135 13           RETVAL = newSVpvn((char *) out, outlen);
136             }
137 39 100         else if (ix == 2) {
138 13           rv = base64_encode(mac, len, out, &outlen);
139 13 50         if (rv != CRYPT_OK) croak("FATAL: base64_encode failed: %s", error_to_string(rv));
140 13           RETVAL = newSVpvn(out, outlen);
141             }
142 26 100         else if (ix == 1) {
143 13           rv = base16_encode(mac, len, out, &outlen, 0);
144 13 50         if (rv != CRYPT_OK) croak("FATAL: base16_encode failed: %s", error_to_string(rv));
145 13           RETVAL = newSVpvn(out, outlen);
146             }
147             else {
148 13           RETVAL = newSVpvn((char *) mac, len);
149             }
150             }
151             OUTPUT:
152             RETVAL