Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement cl_sec_sxml_writer=>crypt_aes_ctr() #877

Merged
merged 3 commits into from
Apr 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"license": "MIT",
"dependencies": {
"@abaplint/cli": "^2.106.5",
"@abaplint/runtime": "^2.8.23",
"@abaplint/runtime": "^2.8.24",
"@abaplint/database-sqlite": "^2.8.0",
"@abaplint/transpiler-cli": "^2.8.23"
"@abaplint/transpiler-cli": "^2.8.24"
}
}
34 changes: 34 additions & 0 deletions src/sxml/cl_sec_sxml_writer.clas.abap
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
CLASS cl_sec_sxml_writer DEFINITION PUBLIC.
PUBLIC SECTION.
CONSTANTS co_aes128_algorithm TYPE string VALUE 'http://www.w3.org/2001/04/xmlenc#aes128-cbc' ##NO_TEXT.
CONSTANTS co_aes192_algorithm TYPE string VALUE 'http://www.w3.org/2001/04/xmlenc#aes192-cbc' ##NO_TEXT.
CONSTANTS co_aes256_algorithm TYPE string VALUE 'http://www.w3.org/2001/04/xmlenc#aes256-cbc' ##NO_TEXT.

CLASS-METHODS crypt_aes_ctr
IMPORTING
input TYPE xstring
key TYPE xstring
iv TYPE xstring
algorithm TYPE string DEFAULT co_aes128_algorithm
EXPORTING
result TYPE xstring.
ENDCLASS.

CLASS cl_sec_sxml_writer IMPLEMENTATION.

METHOD crypt_aes_ctr.
ASSERT algorithm = co_aes128_algorithm.

WRITE '@KERNEL const crypto = await import("crypto");'.

WRITE '@KERNEL const js_key = Buffer.from(key.get(), "hex");'.
WRITE '@KERNEL const js_iv = Buffer.from(iv.get(), "hex");'.
WRITE '@KERNEL const js_input = Buffer.from(input.get(), "hex");'.

WRITE '@KERNEL const cipher = crypto.createDecipheriv("aes-128-ctr", js_key, js_iv);'.
WRITE '@KERNEL const encrypted = cipher.update(js_input);'.

WRITE '@KERNEL result.set(encrypted.toString("hex").toUpperCase());'.
ENDMETHOD.

ENDCLASS.
33 changes: 33 additions & 0 deletions src/sxml/cl_sec_sxml_writer.clas.testclasses.abap
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
CLASS ltcl_test DEFINITION FOR TESTING RISK LEVEL HARMLESS DURATION SHORT FINAL.

PRIVATE SECTION.
METHODS crypt_aes_ctr FOR TESTING RAISING cx_static_check.

ENDCLASS.

CLASS ltcl_test IMPLEMENTATION.

METHOD crypt_aes_ctr.

DATA lv_emptyiv TYPE xstring VALUE '00000000000000000000000000000000'.
DATA lv_hash TYPE xstring.
DATA lv_key TYPE xstring.

lv_key = '00112233445566778899112233445566'.

cl_sec_sxml_writer=>crypt_aes_ctr(
EXPORTING
input = lv_emptyiv
key = lv_key
iv = lv_emptyiv
algorithm = cl_sec_sxml_writer=>co_aes128_algorithm
IMPORTING
result = lv_hash ).

cl_abap_unit_assert=>assert_equals(
act = lv_hash
exp = '7223C1833065A1AFB8C900B221EDE011' ).

ENDMETHOD.

ENDCLASS.
Loading