CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/spec/lib/rex/crypto_spec.rb
Views: 18082
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
34