Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
Olm
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nheko Reborn
Olm
Commits
0e13cd35
Commit
0e13cd35
authored
10 years ago
by
Mark Haines
Browse files
Options
Downloads
Patches
Plain Diff
Move unit test code into a separate header
parent
7c1da489
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/include/unittest.hh
+55
-0
55 additions, 0 deletions
tests/include/unittest.hh
tests/test_crypto.cpp
+6
-55
6 additions, 55 deletions
tests/test_crypto.cpp
with
61 additions
and
55 deletions
tests/include/unittest.hh
0 → 100644
+
55
−
0
View file @
0e13cd35
#include
<cstring>
#include
<iostream>
#include
<iomanip>
#include
<cstdlib>
std
::
ostream
&
print_hex
(
std
::
ostream
&
os
,
std
::
uint8_t
const
*
data
,
std
::
size_t
length
)
{
for
(
std
::
size_t
i
=
0
;
i
<
length
;
i
++
)
{
os
<<
std
::
setw
(
2
)
<<
std
::
setfill
(
'0'
)
<<
std
::
right
<<
std
::
hex
<<
(
int
)
data
[
i
];
}
return
os
;
}
char
const
*
TEST_CASE
;
template
<
typename
T
>
void
assert_equals
(
const
T
&
expected
,
const
T
&
actual
)
{
if
(
expected
!=
actual
)
{
std
::
cout
<<
"FAILED: "
<<
TEST_CASE
<<
std
::
endl
;
std
::
cout
<<
"Expected: "
<<
expected
<<
std
::
endl
;
std
::
cout
<<
"Actual: "
<<
actual
<<
std
::
endl
;
std
::
exit
(
1
);
}
}
void
assert_equals
(
std
::
uint8_t
*
expected
,
std
::
uint8_t
*
actual
,
std
::
size_t
length
)
{
if
(
std
::
memcmp
(
expected
,
actual
,
length
))
{
std
::
cout
<<
"FAILED: "
<<
TEST_CASE
<<
std
::
endl
;
print_hex
(
std
::
cout
<<
"Expected: "
,
expected
,
length
)
<<
std
::
endl
;
print_hex
(
std
::
cout
<<
"Actual: "
,
actual
,
length
)
<<
std
::
endl
;
std
::
exit
(
1
);
}
}
class
TestCase
{
public:
TestCase
(
const
char
*
name
)
{
TEST_CASE
=
name
;
}
~
TestCase
()
{
std
::
cout
<<
"PASSED: "
<<
TEST_CASE
<<
std
::
endl
;
}
};
This diff is collapsed.
Click to expand it.
tests/test_crypto.cpp
+
6
−
55
View file @
0e13cd35
#include
"axolotl/crypto.hh"
#include
<cstring>
#include
<iostream>
#include
<iomanip>
#include
<cstdlib>
std
::
ostream
&
print_hex
(
std
::
ostream
&
os
,
std
::
uint8_t
const
*
data
,
std
::
size_t
length
)
{
for
(
std
::
size_t
i
=
0
;
i
<
length
;
i
++
)
{
os
<<
std
::
setw
(
2
)
<<
std
::
setfill
(
'0'
)
<<
std
::
right
<<
std
::
hex
<<
(
int
)
data
[
i
];
}
return
os
;
}
char
const
*
TEST_CASE
;
void
assert_equals
(
std
::
uint8_t
*
expected
,
std
::
uint8_t
*
actual
,
std
::
size_t
length
)
{
if
(
std
::
memcmp
(
expected
,
actual
,
length
))
{
std
::
cout
<<
"FAILED :"
<<
TEST_CASE
<<
std
::
endl
;
print_hex
(
std
::
cout
<<
"Expected: "
,
expected
,
length
)
<<
std
::
endl
;
print_hex
(
std
::
cout
<<
"Actual: "
,
actual
,
length
)
<<
std
::
endl
;
std
::
exit
(
1
);
}
}
void
pass
()
{
std
::
cout
<<
"PASSED: "
<<
TEST_CASE
<<
std
::
endl
;
}
#include
"unittest.hh"
int
main
()
{
{
/* Curve25529 Test Case 1 */
T
EST_CASE
=
"Curve25529 Test Case 1"
;
T
estCase
test_case
(
"Curve25529 Test Case 1"
)
;
std
::
uint8_t
alice_private
[
32
]
=
{
0x77
,
0x07
,
0x6D
,
0x0A
,
0x73
,
0x18
,
0xA5
,
0x7D
,
...
...
@@ -103,14 +64,12 @@ axolotl::curve25519_shared_secret(bob_pair, alice_pair, actual_agreement);
assert_equals
(
expected_agreement
,
actual_agreement
,
32
);
pass
();
}
/* Curve25529 Test Case 1 */
{
/* AES Test Case 1 */
T
EST_CASE
=
"AES Test Case 1"
;
T
estCase
test_case
(
"AES Test Case 1"
)
;
axolotl
::
Aes256Key
key
=
{};
axolotl
::
Aes256Iv
iv
=
{};
...
...
@@ -133,14 +92,12 @@ axolotl::aes_decrypt_cbc(key, iv, expected, sizeof(expected), actual);
assert_equals
(
input
,
actual
,
32
);
pass
();
}
/* AES Test Case 1 */
{
/* SHA 256 Test Case 1 */
T
EST_CASE
=
"SHA 256 Test Case 1"
;
T
estCase
test_case
(
"SHA 256 Test Case 1"
)
;
std
::
uint8_t
input
[
0
]
=
{};
...
...
@@ -157,13 +114,11 @@ axolotl::sha256(input, sizeof(input), actual);
assert_equals
(
expected
,
actual
,
32
);
pass
();
}
/* SHA 256 Test Case 1 */
{
/* HMAC Test Case 1 */
T
EST_CASE
=
"HMAC Test Case 1"
;
T
estCase
test_case
(
"HMAC Test Case 1"
)
;
std
::
uint8_t
input
[
0
]
=
{};
...
...
@@ -180,13 +135,11 @@ axolotl::hmac_sha256(input, sizeof(input), input, sizeof(input), actual);
assert_equals
(
expected
,
actual
,
32
);
pass
();
}
/* HMAC Test Case 1 */
{
/* HDKF Test Case 1 */
T
EST_CASE
=
"HDKF Test Case 1"
;
T
estCase
test_case
(
"HDKF Test Case 1"
)
;
std
::
uint8_t
input
[
22
]
=
{
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
0x0b
,
...
...
@@ -241,8 +194,6 @@ axolotl::hkdf_sha256(
assert_equals
(
hkdf_expected_output
,
hkdf_actual_output
,
42
);
pass
();
}
/* HDKF Test Case 1 */
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment