forked from larshp/abapNTLM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
zcl_arc4.clas.testclasses.abap
120 lines (81 loc) · 3 KB
/
zcl_arc4.clas.testclasses.abap
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
CLASS lcl_test DEFINITION DEFERRED.
CLASS zcl_arc4 DEFINITION LOCAL FRIENDS lcl_test.
*----------------------------------------------------------------------*
* CLASS lcl_Test DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_test DEFINITION FOR TESTING
DURATION SHORT
RISK LEVEL HARMLESS
FINAL.
PRIVATE SECTION.
* ================
METHODS: encrypt1 FOR TESTING RAISING cx_static_check,
encrypt2 FOR TESTING RAISING cx_static_check,
encrypt3 FOR TESTING RAISING cx_static_check,
decrypt1 FOR TESTING RAISING cx_static_check,
to_xstring FOR TESTING RAISING cx_static_check.
ENDCLASS. "lcl_Test
*----------------------------------------------------------------------*
* CLASS lcl_Test IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_test IMPLEMENTATION.
* ==============================
METHOD to_xstring.
* ==============================
DATA: lv_result TYPE xstring.
lv_result = zcl_arc4=>to_xstring( 'Key' ).
cl_abap_unit_assert=>assert_equals(
exp = '4B6579'
act = lv_result ).
ENDMETHOD. "string_To_Xstring_Utf8
METHOD encrypt1.
* ==============================
DATA: lv_ciphertext TYPE xstring.
lv_ciphertext = zcl_arc4=>encrypt(
iv_key = 'Key'
iv_plaintext = 'Plaintext' ).
cl_abap_unit_assert=>assert_equals(
exp = 'BBF316E8D940AF0AD3'
act = lv_ciphertext ).
ENDMETHOD. "encrypt
METHOD encrypt2.
* ==============================
DATA: lv_ciphertext TYPE xstring.
lv_ciphertext = zcl_arc4=>encrypt(
iv_key = 'Wiki'
iv_plaintext = 'pedia' ).
cl_abap_unit_assert=>assert_equals(
exp = '1021BF0420'
act = lv_ciphertext ).
ENDMETHOD. "encrypt2
METHOD encrypt3.
* ==============================
DATA: lv_ciphertext TYPE xstring.
lv_ciphertext = zcl_arc4=>encrypt(
iv_key = 'Secret'
iv_plaintext = 'Attack at dawn' ).
cl_abap_unit_assert=>assert_equals(
exp = '45A01F645FC35B383552544B9BF5'
act = lv_ciphertext ).
ENDMETHOD. "encrypt3
METHOD decrypt1.
* ==============================
CONSTANTS: lc_plaintext TYPE string VALUE 'Plaintext',
lc_key TYPE string VALUE 'Key'.
DATA: lv_plaintext TYPE string,
lv_ciphertext TYPE xstring.
lv_ciphertext = zcl_arc4=>encrypt(
iv_key = lc_key
iv_plaintext = lc_plaintext ).
lv_plaintext = zcl_arc4=>decrypt(
iv_key = lc_key
iv_ciphertext = lv_ciphertext ).
cl_abap_unit_assert=>assert_equals(
exp = lc_plaintext
act = lv_plaintext ).
ENDMETHOD. "encrypt
ENDCLASS. "lcl_Test