-
Notifications
You must be signed in to change notification settings - Fork 476
add: возможность копировать интегралки текстом #8483
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
base: master220
Are you sure you want to change the base?
Changes from 20 commits
61242d6
af7d70b
9f3e797
513e377
c568d19
64ff86a
9579f06
dbe516a
8dc93e4
cd8fdcb
382acf4
17fa8a2
4330cb8
c692dd3
1a8b313
3f70cbd
f47371f
7bce7a2
880f026
56e0689
0204376
c2b428d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,6 +62,14 @@ | |
| for(var/i in 1 to times) | ||
| . += string | ||
|
|
||
| // Создает строку используя список из ASCII | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Рекомендация по стилю: Согласно стайлгайду (пункт 4.1, правило о комментариях), все комментарии в коде должны быть на английском языке. References
|
||
| /proc/ascii_list2text(list/ascii_text) | ||
| . = "" | ||
| for(var/ascii_char in ascii_text) | ||
| if(ascii_char < 32 || ascii_char > 127) | ||
| CRASH("ascii_list2text: invalid ASCII code") | ||
| . += ascii2text(ascii_char) | ||
|
|
||
| /// Runs sanitize and strip_html_simple | ||
| /// I believe strip_html_simple() is required to run first to prevent '<' from displaying as '<' after sanitize() calls byond's html_encode() | ||
| /proc/strip_html(t, limit=MAX_MESSAGE_LEN) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -309,6 +309,34 @@ using metal and glass, it uses glass and reagents (usually sulfuric acis). | |
|
|
||
| update_static_data_for_all_viewers() | ||
|
|
||
| // Проверяет наличие всех данных | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Рекомендация по стилю: Комментарий в коде должен быть на английском языке. Это требование стайлгайда (пункт 4.1, строка 68) для обеспечения согласованности кодовой базы. References
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Рекомендация по стилю: Согласно стайлгайду (пункт 4.1, правило о комментариях), все комментарии в коде должны быть на английском языке. В этом файле несколько таких комментариев. References
|
||
| /obj/machinery/r_n_d/circuit_imprinter/proc/can_save_circuit_by_json(mob/living/user, json_data) | ||
| var/list/data = json_decode(json_data) | ||
| var/list/required_keys = list("dupe_data", "name", "materials", "integrated_circuit", "Icon", "IconState", "desc") | ||
| for(var/key in required_keys) | ||
| if(!LAZYACCESS(data, key)) | ||
| return FALSE | ||
| return TRUE | ||
|
Comment on lines
313
to
321
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Рекомендация: Обнаружена потенциальная ошибка выполнения в процедуре References
|
||
|
|
||
| // Для иморта платы | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Рекомендация по стилю: Комментарий в коде должен быть на английском языке. Это требование стайлгайда (пункт 4.1, строка 68) для обеспечения согласованности кодовой базы. References
|
||
| /obj/machinery/r_n_d/circuit_imprinter/proc/save_circuit_by_json(mob/living/user, json_data) | ||
| if(!can_save_circuit_by_json(user, json_data)) | ||
| return | ||
|
|
||
| var/list/data = json_decode(json_data) | ||
|
Comment on lines
+324
to
+328
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Рекомендация по производительности: Процедура |
||
|
|
||
| for(var/list/component_data as anything in scanned_designs) | ||
| if(component_data["name"] == data["name"]) | ||
| balloon_alert(user, "название занято!") | ||
| return | ||
|
|
||
| LAZYADD(scanned_designs, list(data)) | ||
|
|
||
| balloon_alert(user, "схема сохранена") | ||
| playsound(src, 'sound/machines/ping.ogg', 50) | ||
|
|
||
| update_static_data_for_all_viewers() | ||
|
|
||
| /obj/machinery/r_n_d/circuit_imprinter/proc/print_module(list/design) | ||
| flick("[base_icon_state]_ani", src) | ||
|
|
||
|
|
@@ -376,6 +404,66 @@ using metal and glass, it uses glass and reagents (usually sulfuric acis). | |
| LAZYREMOVE(scanned_designs, design) | ||
|
|
||
| update_static_data_for_all_viewers() | ||
| if("export") | ||
| var/design_id = text2num(params["designId"]) | ||
|
|
||
| if(design_id < 1 || design_id > length(scanned_designs)) | ||
| return TRUE | ||
|
|
||
| var/list/design = LAZYACCESS(scanned_designs, design_id) | ||
|
|
||
| var/mob/user= ui.user | ||
|
|
||
| var/json_data = json_encode(design) | ||
|
|
||
| var/hmac_key = CONFIG_GET(string/hmac_key) ? CONFIG_GET(string/hmac_key) : "" | ||
|
|
||
| // Создает HMAC если ключ корректен | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Рекомендация по стилю: Комментарий в коде должен быть на английском языке. Это требование стайлгайда (пункт 4.1, строка 68) для обеспечения согласованности кодовой базы. References
|
||
| var/hmac_base64 = "" | ||
| if(validate_hmac_key(hmac_key)) | ||
| hmac_base64 = hmac_md5_base64(hmac_key, json_data) | ||
|
|
||
| if(!hmac_base64) | ||
| tgui_alert(user, "Ошибка создания электронной подписи!", "Ошибка экспорта") | ||
| return TRUE | ||
|
|
||
| var/json_base64 = rustg_encode_base64(json_data) | ||
| var/final_text = rustg_encode_base64("[json_base64].[hmac_base64]") | ||
|
|
||
| // Окно в вводом из которого можно скопировать текст | ||
| tgui_input_text(user, "Скопируйте текст схемы:", "Экспорт схемы", default = final_text, max_length=999999999) | ||
|
|
||
| if("import") | ||
| var/mob/user = ui.user | ||
|
|
||
| var/text = tgui_input_text(user, "Вставьте текст интегральной платы", "Импорт схемы", encode=FALSE, max_length = 999999999) | ||
| text = text && ascii_list2text(rustlib_decode_base64(text)) ? ascii_list2text(rustlib_decode_base64(text)) : "" | ||
|
||
|
|
||
| var/hmac_key = CONFIG_GET(string/hmac_key) ? CONFIG_GET(string/hmac_key) : "" | ||
|
|
||
| if(!text || !findtext(text, ".")) | ||
| tgui_alert(user, "Ошибка расшифровки. Убедитесь в корректности данных", "Ошибка импорта") | ||
| return TRUE | ||
|
|
||
| var/list/parts = splittext(text, ".") // [1] - json в виде списка ASCII [2] - HMAC в виде списка ASCII | ||
|
|
||
| var/json_data = ascii_list2text(rustlib_decode_base64(parts[1])) ? ascii_list2text(rustlib_decode_base64(parts[1])) : "" | ||
|
||
|
|
||
| if(!json_data) | ||
| tgui_alert(user, "Некорректный JSON! Проверьте корректность данных.", "Ошибка импорта") | ||
| return TRUE | ||
|
|
||
| // Создает HMAC если ключ корректен | ||
| var/hmac_base64 = "" | ||
| if(validate_hmac_key(hmac_key) && json_data) | ||
| hmac_base64 = hmac_md5_base64(hmac_key, json_data) | ||
|
|
||
| // Сравнивает переданный и полученный HMAC | ||
| if(parts[2] != hmac_base64) | ||
| tgui_alert(user, "Ошибка электронной подписи! Проверьте корректность данных.", "Ошибка импорта") | ||
| return TRUE | ||
|
|
||
| save_circuit_by_json(user, json_data) | ||
|
|
||
| return TRUE | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| #define HMAC_BLOCK_SIZE 64 | ||
| #define HMAC_IPAD 54 // ASCII "6" | ||
| #define HMAC_OPAD 92 // ASCII "\" | ||
|
|
||
| /* | ||
| * Основная функция HMAC-MD5 | ||
| * hex_key - ключ в hex-формате | ||
| * data - данные для подписи | ||
| */ | ||
|
Comment on lines
+5
to
+9
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Рекомендация по стилю: Согласно стайлгайду (пункт 4.1, правило о комментариях), все комментарии в коде должны быть на английском языке. References
|
||
| /proc/hmac_md5_hex(hex_key, data) | ||
| var/key_bin = hex_to_bin(hex_key) | ||
|
|
||
| if(!key_bin) | ||
| CRASH("hmac_md5_hex: Invalid hex key for HMAC") | ||
|
|
||
| if(length(key_bin) > HMAC_BLOCK_SIZE) | ||
| key_bin = hex_to_bin(md5(key_bin)) | ||
|
|
||
| if(length(key_bin) < HMAC_BLOCK_SIZE) | ||
| key_bin += repeat_string(HMAC_BLOCK_SIZE - length(key_bin), "0") | ||
|
Comment on lines
+19
to
+20
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 Критично: Некорректная реализация HMAC. Ключ дополняется ASCII-символами '0' ( |
||
|
|
||
| var/ipad = repeat_string(HMAC_BLOCK_SIZE, ascii2text(HMAC_IPAD)) | ||
| var/opad = repeat_string(HMAC_BLOCK_SIZE, ascii2text(HMAC_OPAD)) | ||
|
|
||
| var/i_key = xor_strings(key_bin, ipad) | ||
| var/o_key = xor_strings(key_bin, opad) | ||
|
|
||
| var/inner_hash = md5(i_key + data) | ||
|
|
||
| var/inner_hash_bin = hex_to_bin(inner_hash) | ||
| var/hmac_hex = md5(o_key + inner_hash_bin) | ||
|
|
||
| return hmac_hex | ||
|
|
||
| /proc/hmac_md5_base64(hex_key, data) | ||
| var/hmac_hex = hmac_md5_hex(hex_key, data) | ||
| var/hmac_bin = hex_to_bin(hmac_hex) | ||
| return rustg_encode_base64(hmac_bin) | ||
|
|
||
| /proc/xor_strings(a, b) | ||
| if(length(a) != length(b)) | ||
| CRASH("XOR: strings of different lengths ([length(a)] vs [length(b)])") | ||
|
|
||
| var/result = "" | ||
| for(var/i = 1; i <= length(a); i++) | ||
| var/byte_a = text2ascii(copytext(a, i, i+1)) | ||
| var/byte_b = text2ascii(copytext(b, i, i+1)) | ||
| result += ascii2text(byte_a ^ byte_b) | ||
|
|
||
| return result | ||
|
|
||
| /proc/hex_to_bin(hex_string) | ||
| if(!istext(hex_string)) | ||
| return null | ||
|
|
||
| hex_string = replacetext(hex_string, " ", "") | ||
| hex_string = replacetext(hex_string, "\n", "") | ||
| hex_string = replacetext(hex_string, "\t", "") | ||
|
|
||
| if(length(hex_string) % 2 != 0) | ||
| hex_string = "0" + hex_string | ||
|
|
||
| var/bin = "" | ||
| for(var/i = 1; i <= length(hex_string); i += 2) | ||
| var/hex_pair = copytext(hex_string, i, i+2) | ||
| var/num = hex2num(hex_pair) | ||
|
|
||
| if(isnull(num)) | ||
| return null | ||
|
|
||
| bin += ascii2text(num) | ||
|
|
||
| return bin | ||
|
|
||
| /proc/bin_to_hex(bin_string) | ||
| if(!istext(bin_string)) | ||
| return "" | ||
|
|
||
| var/hex = "" | ||
| for(var/i = 1; i <= length(bin_string); i++) | ||
| var/byte = text2ascii(copytext(bin_string, i, i+1)) | ||
| hex += num2hex(byte, 2) | ||
|
|
||
| return lowertext(hex) | ||
|
|
||
| /proc/validate_hmac_key(hex_key) | ||
| if(!istext(hex_key)) | ||
| return FALSE | ||
|
|
||
| var/len = length(hex_key) | ||
| if(len != 40 && len != HMAC_BLOCK_SIZE) | ||
| return FALSE | ||
|
|
||
| var/valid_chars = "0123456789abcdefABCDEF" | ||
| for(var/i = 1; i <= len; i++) | ||
| var/char = copytext(hex_key, i, i+1) | ||
| if(!findtext(valid_chars, char)) | ||
| return FALSE | ||
|
|
||
| return TRUE | ||
|
|
||
| #undef HMAC_BLOCK_SIZE | ||
| #undef HMAC_IPAD | ||
| #undef HMAC_OPAD | ||
Large diffs are not rendered by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Рекомендация по стилю: Комментарий в коде должен быть на английском языке. Это требование стайлгайда (пункт 4.1, строка 68) для обеспечения согласованности кодовой базы.
References