Skip to content

Commit 3add360

Browse files
committed
test refactor
1 parent f26a140 commit 3add360

File tree

4 files changed

+25
-14
lines changed

4 files changed

+25
-14
lines changed

test/padding.jl

+7-5
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,19 @@ end
1919
test_vector = Vector{UInt8}([1,2,3])
2020
Random.seed!(42)
2121
padded = ToyPublicKeys.pad(ToyPublicKeys.pkcs1_v1_5, test_vector)
22-
@test ToyPublicKeys.unpad(ToyPublicKeys.pkcs1_v1_5, padded) == test_vector
22+
unpadded = ToyPublicKeys.unpad(ToyPublicKeys.pkcs1_v1_5, padded)
23+
@test unpadded == test_vector
2324
end
2425

2526
@testset "padding/pkcs_1_v2_2 pad(unpad) is identity" begin
26-
test_vector = Vector{UInt8}([1,2,3])
27+
test_vector = Vector{UInt8}([3,2,1])
2728
Random.seed!(42)
2829
private_key, public_key = ToyPublicKeys.generate_rsa_key_pair(ToyPublicKeys.pkcs1_v1_5, 2048)
2930
padded = ToyPublicKeys.pad(ToyPublicKeys.pkcs1_v2_2,
3031
test_vector,
3132
public_key)
32-
@test test_vector == ToyPublicKeys.unpad(ToyPublicKeys.pkcs1_v2_2,
33-
padded,
34-
public_key)
33+
unpadded = ToyPublicKeys.unpad(ToyPublicKeys.pkcs1_v2_2,
34+
padded,
35+
public_key)
36+
@test unpadded == test_vector
3537
end

test/rsa.jl

+9
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,12 @@ end
117117
signature = ToyPublicKeys.RSASP1(ToyPublicKeys.pkcs1_v1_5, msg, private_key)
118118
@test ToyPublicKeys.RSAVP1(ToyPublicKeys.pkcs1_v1_5, signature, public_key) == msg
119119
end
120+
121+
@testset "rsaes_oaep_decrypt(rsaes_oaep_encrypt) is true" begin
122+
Random.seed!(42)
123+
private_key, public_key = ToyPublicKeys.generate_rsa_key_pair(ToyPublicKeys.pkcs1_v1_5, 2048)
124+
msg = Vector{UInt8}("123")
125+
C = ToyPublicKeys.rsaes_oaep_encrypt(msg, public_key)
126+
ret = ToyPublicKeys.rsaes_oaep_decrypt(C, private_key)
127+
@test ret == msg
128+
end

test/runtests.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ using ToyPublicKeys
22
using Test
33
import Random
44

5+
include("utils.jl")
6+
include("padding.jl")
57
include("rsa.jl")
68
include("dh.jl")
7-
include("padding.jl")
8-
include("utils.jl")

test/utils.jl

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
@testset "I2OSP" begin
1+
@testset "i2osp" begin
22
b = big"255"
3-
@test b |> ToyPublicKeys.I2OSP == "FF"
4-
@test b |> x -> ToyPublicKeys.I2OSP(x, 3) == "00:FF"
3+
@test b |> ToyPublicKeys.i2osp == "FF"
4+
@test b |> x -> ToyPublicKeys.i2osp(x, 3) == "00:FF"
55
end
66

7-
@testset "OS2IP" begin
7+
@testset "os2ip" begin
88
b = "FF"
9-
@test b |> ToyPublicKeys.OS2IP == big"255"
9+
@test b |> ToyPublicKeys.os2ip == big"255"
1010
end
1111

12-
@testset "I2OSP |> OS2IP" begin
12+
@testset "i2osp |> os2ip" begin
1313
b = big"255"
14-
@test b |> ToyPublicKeys.I2OSP |> ToyPublicKeys.OS2IP == b
14+
@test b |> ToyPublicKeys.i2osp |> ToyPublicKeys.os2ip == b
1515
end

0 commit comments

Comments
 (0)