Skip to content

Commit 7522163

Browse files
committed
Add tests for byte to int conversions
1 parent 5b7ec05 commit 7522163

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

spec/lib/rex/crypto_spec.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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

0 commit comments

Comments
 (0)