line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#define PERL_NO_GET_CONTEXT |
2
|
|
|
|
|
|
|
#include "EXTERN.h" |
3
|
|
|
|
|
|
|
#include "perl.h" |
4
|
|
|
|
|
|
|
#include "XSUB.h" |
5
|
|
|
|
|
|
|
#include "ppport.h" |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
static const char base32[32] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
MODULE = MIME::Base32::XS PACKAGE = MIME::Base32::XS |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
SV * |
12
|
|
|
|
|
|
|
encode_base32(SV *sv) |
13
|
|
|
|
|
|
|
PREINIT: |
14
|
|
|
|
|
|
|
STRLEN len; |
15
|
|
|
|
|
|
|
SSize_t size; |
16
|
|
|
|
|
|
|
unsigned char *input; |
17
|
|
|
|
|
|
|
unsigned char *output; |
18
|
93
|
|
|
|
|
|
unsigned long int x = 0; |
19
|
93
|
|
|
|
|
|
unsigned int i, z, n = 0; |
20
|
93
|
|
|
|
|
|
char ap[5] = {0, 6, 4, 3, 1}; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
CODE: |
23
|
93
|
50
|
|
|
|
|
input = SvPV(sv, len); |
24
|
93
|
|
|
|
|
|
size = (SSize_t)len; |
25
|
|
|
|
|
|
|
|
26
|
93
|
|
|
|
|
|
len = (size * 2) + ap[size % 5]; |
27
|
|
|
|
|
|
|
|
28
|
93
|
50
|
|
|
|
|
RETVAL = newSV(len ? len : 1); |
29
|
93
|
|
|
|
|
|
SvPOK_on(RETVAL); |
30
|
93
|
|
|
|
|
|
output = SvPVX(RETVAL); |
31
|
|
|
|
|
|
|
|
32
|
186
|
100
|
|
|
|
|
for (i=0; i
|
33
|
186
|
50
|
|
|
|
|
for (z=0; z<5 && i
|
|
|
100
|
|
|
|
|
|
34
|
93
|
|
|
|
|
|
x |= input[i]; |
35
|
93
|
|
|
|
|
|
x <<= 8; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
93
|
|
|
|
|
|
x <<= (7 - z) << 3; |
39
|
93
|
|
|
|
|
|
*output++ = base32[x >> 59]; |
40
|
93
|
|
|
|
|
|
*output++ = base32[(x << 5) >> 59]; |
41
|
93
|
|
|
|
|
|
*output++ = base32[(x << 10) >> 59]; |
42
|
93
|
|
|
|
|
|
*output++ = base32[(x << 15) >> 59]; |
43
|
93
|
|
|
|
|
|
*output++ = base32[(x << 20) >> 59]; |
44
|
93
|
|
|
|
|
|
*output++ = base32[(x << 25) >> 59]; |
45
|
93
|
|
|
|
|
|
*output++ = base32[(x << 30) >> 59]; |
46
|
93
|
|
|
|
|
|
*output++ = base32[(x << 35) >> 59]; |
47
|
93
|
|
|
|
|
|
--i; |
48
|
|
|
|
|
|
|
|
49
|
93
|
|
|
|
|
|
n += 8; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
93
|
|
|
|
|
|
*output = '\0'; |
53
|
|
|
|
|
|
|
|
54
|
651
|
100
|
|
|
|
|
for (i = ap[size % 5]; i; i--) |
55
|
558
|
|
|
|
|
|
*--output = '='; |
56
|
|
|
|
|
|
|
|
57
|
93
|
|
|
|
|
|
SvCUR_set(RETVAL, n); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
OUTPUT: |
60
|
|
|
|
|
|
|
RETVAL |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
SV * |
63
|
|
|
|
|
|
|
decode_base32(SV *sv) |
64
|
|
|
|
|
|
|
PREINIT: |
65
|
|
|
|
|
|
|
STRLEN len; |
66
|
|
|
|
|
|
|
SSize_t size; |
67
|
|
|
|
|
|
|
unsigned char *input; |
68
|
|
|
|
|
|
|
char *output; |
69
|
|
|
|
|
|
|
unsigned long int x; |
70
|
93
|
|
|
|
|
|
unsigned int i, z, rtsize, n = 0; |
71
|
|
|
|
|
|
|
unsigned char pad; |
72
|
|
|
|
|
|
|
unsigned char t; |
73
|
93
|
|
|
|
|
|
char lkpad[7] = {0, 4, 0, 3, 2, 0, 1}; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
CODE: |
76
|
93
|
50
|
|
|
|
|
input = SvPV(sv, len); |
77
|
93
|
|
|
|
|
|
size = (SSize_t)len; |
78
|
|
|
|
|
|
|
|
79
|
651
|
100
|
|
|
|
|
for (pad = 0, i = len-1; input[i] == '='; i--) |
80
|
558
|
|
|
|
|
|
++pad; |
81
|
|
|
|
|
|
|
|
82
|
93
|
|
|
|
|
|
len = len * 3 / 4; |
83
|
93
|
|
|
|
|
|
size -= pad; |
84
|
|
|
|
|
|
|
|
85
|
93
|
50
|
|
|
|
|
RETVAL = newSV(len ? len : 1); |
86
|
93
|
|
|
|
|
|
SvPOK_on(RETVAL); |
87
|
93
|
|
|
|
|
|
output = SvPVX(RETVAL); |
88
|
|
|
|
|
|
|
|
89
|
186
|
100
|
|
|
|
|
for (i = 0; i < size; i++) { |
90
|
93
|
50
|
|
|
|
|
if (input[i] != '=') { |
91
|
279
|
50
|
|
|
|
|
for (x = 0, z = 0; z < 8 && i < size; z++, i++) { |
|
|
100
|
|
|
|
|
|
92
|
186
|
100
|
|
|
|
|
if ((input[i] >= 'A' && input[i] <= 'Z') || (input[i] >= '2' && input[i] <= '7')) { |
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
93
|
2368
|
100
|
|
|
|
|
for (t = 0; input[i] != base32[t]; t++); |
94
|
186
|
|
|
|
|
|
x |= t; |
95
|
186
|
|
|
|
|
|
x <<= 5; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
93
|
|
|
|
|
|
x <<= (19 + ((8-z)*5)); |
100
|
93
|
|
|
|
|
|
*output++ = x >> 56; |
101
|
93
|
|
|
|
|
|
*output++ = (x << 8) >> 56; |
102
|
93
|
|
|
|
|
|
*output++ = (x << 16) >> 56; |
103
|
93
|
|
|
|
|
|
*output++ = (x << 24) >> 56; |
104
|
93
|
|
|
|
|
|
*output++ = (x << 32) >> 56; |
105
|
93
|
|
|
|
|
|
--i; |
106
|
|
|
|
|
|
|
|
107
|
93
|
|
|
|
|
|
n += 5; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
93
|
|
|
|
|
|
*output = '\0'; |
112
|
|
|
|
|
|
|
|
113
|
93
|
|
|
|
|
|
SvCUR_set(RETVAL, n - 4); |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
OUTPUT: |
116
|
|
|
|
|
|
|
RETVAL |