Skip to content

Commit 79dac44

Browse files
authored
ci(python): 파이썬 CI 설정 (#31)
* ci(python): 파이썬 CI 설정 * ci(python): 빌드 커맨드 수정 * fix(hwp): 종속성 수정 * ci(python): 릴리즈 추가 * ci(python): PR 제거
1 parent 55f1bc4 commit 79dac44

File tree

8 files changed

+151
-98
lines changed

8 files changed

+151
-98
lines changed

.github/workflows/python.yml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: Python
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
release:
8+
types: [published]
9+
10+
jobs:
11+
linux:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v3
15+
- uses: messense/maturin-action@v1
16+
with:
17+
manylinux: auto
18+
command: build
19+
args: --release --sdist -o dist --find-interpreter -m crates/python/Cargo.toml
20+
- name: Upload wheels
21+
uses: actions/upload-artifact@v2
22+
with:
23+
name: wheels
24+
path: dist
25+
26+
windows:
27+
runs-on: windows-latest
28+
steps:
29+
- uses: actions/checkout@v3
30+
- uses: messense/maturin-action@v1
31+
with:
32+
command: build
33+
args: --release -o dist --find-interpreter -m crates/python/Cargo.toml
34+
- name: Upload wheels
35+
uses: actions/upload-artifact@v2
36+
with:
37+
name: wheels
38+
path: dist
39+
40+
macos:
41+
runs-on: macos-latest
42+
steps:
43+
- uses: actions/checkout@v3
44+
- uses: messense/maturin-action@v1
45+
with:
46+
command: build
47+
args: --release -o dist --universal2 --find-interpreter -m crates/python/Cargo.toml
48+
- name: Upload wheels
49+
uses: actions/upload-artifact@v2
50+
with:
51+
name: wheels
52+
path: dist
53+
54+
release:
55+
name: Release
56+
runs-on: ubuntu-latest
57+
if: "startsWith(github.ref, 'refs/tags/')"
58+
needs: [macos, windows, linux]
59+
steps:
60+
- uses: actions/download-artifact@v2
61+
with:
62+
name: wheels
63+
- name: Publish to PyPI
64+
uses: messense/maturin-action@v1
65+
env:
66+
MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
67+
with:
68+
command: upload
69+
args: --skip-existing *

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,6 @@ $RECYCLE.BIN/
7474

7575
# Windows shortcuts
7676
*.lnk
77+
78+
### PyO3 ###
79+
/dist

Cargo.lock

Lines changed: 64 additions & 65 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/hwp/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ version = "0.1.0"
44
edition = "2021"
55

66
[dependencies]
7+
aes = "0.8"
78
byteorder = "1"
89
cfb = "0.7"
910
hwp_macro = { path = "../macro" }
1011
flate2 = "1.0"
1112
num = "0.4"
1213
num-traits = "0.2"
1314
num-derive = "0.3"
14-
openssl = "0.10"

crates/hwp/src/hwp/section.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ impl Section {
8484
let mut encrypted: Vec<u8> = Vec::new();
8585
stream.read_to_end(&mut encrypted).unwrap();
8686

87-
let decrypted = decrypt_aes_128_ecb(&decryption_key, &encrypted).unwrap();
87+
let decrypted = decrypt_aes_128_ecb(&decryption_key, &encrypted);
8888

8989
let cursor = Cursor::new(decrypted);
9090

crates/hwp/src/hwp/utils/crypto.rs

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,15 @@
1-
use openssl::{
2-
error::ErrorStack,
3-
symm::{Cipher, Crypter, Mode},
4-
};
1+
use aes::cipher::KeyInit;
2+
use aes::cipher::{generic_array::GenericArray, BlockDecrypt};
3+
use aes::Aes128;
54

6-
/// openssl의 cipher함수에 pad를 끄는 기능을 적용한 패치
7-
///
8-
/// openssl의 aes_128_ecb를 사용하면 padding이 있는걸로 간주하기때문에 제대로 압축해제되지 않는다
9-
///
10-
/// 참고:
11-
/// https://github.com/sfackler/rust-openssl/blob/openssl-v0.10.42/openssl/src/symm.rs#L690
12-
pub fn decrypt_aes_128_ecb(key: &[u8], data: &[u8]) -> Result<Vec<u8>, ErrorStack> {
13-
let cipher = Cipher::aes_128_ecb();
14-
let mut c = Crypter::new(cipher, Mode::Decrypt, key, None)?;
15-
// 패치한 부분
16-
c.pad(false);
17-
let mut out = vec![0; data.len() + cipher.block_size()];
18-
let count = c.update(data, &mut out)?;
19-
let rest = c.finalize(&mut out[count..])?;
20-
out.truncate(count + rest);
21-
Ok(out)
5+
pub fn decrypt_aes_128_ecb(key: &[u8], data: &[u8]) -> Vec<u8> {
6+
let mut blocks = Vec::new();
7+
(0..data.len()).step_by(16).for_each(|x| {
8+
blocks.push(GenericArray::clone_from_slice(&data[x..x + 16]));
9+
});
10+
11+
let cipher = Aes128::new_from_slice(&key).unwrap();
12+
cipher.decrypt_blocks(&mut blocks);
13+
14+
blocks.into_iter().flatten().map(|x| x as u8).collect()
2215
}

crates/python/README.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,3 @@ for section in hwp.body_texts.sections:
3939
for paragraph in section.paragraphs:
4040
print(paragraph_to_string(paragraph.chars()))
4141
```
42-
43-
# Develop
44-
```
45-
pip install maturin
46-
maturin develop
47-
python
48-
```

crates/python/src/paragraph/mod.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ pub struct PyParagraph {
2020

2121
#[pymethods]
2222
impl PyParagraph {
23-
fn __str__(&self) -> String {
24-
self.char_list.to_string()
25-
}
26-
2723
fn chars(&self) -> Vec<Py<PyAny>> {
2824
let mut chars = Vec::new();
2925
for char in &self.char_list.chars {

0 commit comments

Comments
 (0)