File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change
1
+ # -*- coding:binary -*-
2
+ require 'spec_helper'
3
+
4
+ RSpec . describe Rex ::Crypto do
5
+ describe '.bytes_to_int' do
6
+ it 'converts an empty byte correctly' do
7
+ expect ( subject . bytes_to_int ( "" . b ) ) . to eq ( 0 )
8
+ end
9
+
10
+ it 'converts a single null byte correctly' do
11
+ expect ( subject . bytes_to_int ( "\x00 " . b ) ) . to eq ( 0 )
12
+ end
13
+
14
+ it 'converts a single non-null byte correctly' do
15
+ expect ( subject . bytes_to_int ( "\x01 " . b ) ) . to eq ( 1 )
16
+ end
17
+
18
+ it 'converts multiple bytes correctly' do
19
+ expect ( subject . bytes_to_int ( "\x01 \x02 \x03 \x04 " . b ) ) . to eq ( 16909060 )
20
+ end
21
+ end
22
+
23
+ describe '.int_to_bytes' do
24
+ it 'converts 0 to an empty byte' do
25
+ expect ( subject . int_to_bytes ( 0 ) ) . to eq ( "" . b )
26
+ end
27
+
28
+ it 'converts to bytes correctly' do
29
+ expect ( subject . int_to_bytes ( 1 ) ) . to eq ( "\x01 " . b )
30
+ expect ( subject . int_to_bytes ( 16909060 ) ) . to eq ( "\x01 \x02 \x03 \x04 " . b )
31
+ end
32
+ end
33
+ end
You can’t perform that action at this time.
0 commit comments