line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# $Id$ |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# string::hexa Brik |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
package Metabrik::String::Hexa; |
7
|
1
|
|
|
1
|
|
764
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
8
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
27
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
5
|
use base qw(Metabrik); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
440
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub brik_properties { |
13
|
|
|
|
|
|
|
return { |
14
|
0
|
|
|
0
|
1
|
|
revision => '$Revision$', |
15
|
|
|
|
|
|
|
tags => [ qw(unstable encode decode hex) ], |
16
|
|
|
|
|
|
|
author => 'GomoR ', |
17
|
|
|
|
|
|
|
license => 'http://opensource.org/licenses/BSD-3-Clause', |
18
|
|
|
|
|
|
|
attributes => { |
19
|
|
|
|
|
|
|
with_x => [ ], |
20
|
|
|
|
|
|
|
}, |
21
|
|
|
|
|
|
|
attributes_default => { |
22
|
|
|
|
|
|
|
with_x => 1, |
23
|
|
|
|
|
|
|
}, |
24
|
|
|
|
|
|
|
commands => { |
25
|
|
|
|
|
|
|
encode => [ qw($data) ], |
26
|
|
|
|
|
|
|
decode => [ qw($data) ], |
27
|
|
|
|
|
|
|
is_hexa => [ qw($data) ], |
28
|
|
|
|
|
|
|
}, |
29
|
|
|
|
|
|
|
require_modules => { |
30
|
|
|
|
|
|
|
'MIME::Base64' => [ ], |
31
|
|
|
|
|
|
|
}, |
32
|
|
|
|
|
|
|
}; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub encode { |
36
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
37
|
0
|
|
|
|
|
|
my ($data) = @_; |
38
|
|
|
|
|
|
|
|
39
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('encode', $data) or return; |
40
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
my $encoded = unpack('H*', $data); |
42
|
|
|
|
|
|
|
|
43
|
0
|
0
|
|
|
|
|
if ($self->with_x) { |
44
|
0
|
|
|
|
|
|
$encoded =~ s/(..)/\\x$1/g; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
return $encoded; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub decode { |
51
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
52
|
0
|
|
|
|
|
|
my ($data) = @_; |
53
|
|
|
|
|
|
|
|
54
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('decode', $data) or return; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# Keep only hex-compliant characters |
57
|
0
|
|
|
|
|
|
$data =~ s/[^a-fA-F0-9]//g; |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
my $decoded = pack('H*', $data); |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
return $decoded; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub is_hexa { |
65
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
66
|
0
|
|
|
|
|
|
my ($data) = @_; |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
my $this = lc($data); |
69
|
0
|
|
|
|
|
|
$this =~ s/\\x//g; |
70
|
|
|
|
|
|
|
|
71
|
0
|
0
|
|
|
|
|
if ($this =~ /^[a-f0-9]+$/) { |
72
|
0
|
|
|
|
|
|
return 1; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
return 0; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
1; |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
__END__ |