-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
31 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import cython | ||
|
||
from libc.stdlib cimport malloc | ||
|
||
|
||
cdef extern from "crypt_wrapper.h": | ||
void _encrypt_into(const char * unencrypted, char * encrypted) | ||
void _decrypt_into(const char * encrypted, char * unencrypted) | ||
|
||
cdef char* _decrypt(const char *encrypted): | ||
cdef char* unencrypted = <char *> malloc((len(encrypted)) * sizeof(char)) | ||
if not unencrypted: | ||
return NULL # malloc failed | ||
_decrypt_into(encrypted, unencrypted) | ||
return unencrypted | ||
|
||
cdef char* _encrypt(const char *unencrypted): | ||
cdef char* encrypted = <char *> malloc((len(unencrypted)) * sizeof(char)) | ||
if not encrypted: | ||
return NULL # malloc failed | ||
_decrypt_into(unencrypted, encrypted) | ||
return encrypted | ||
|
||
def encrypt(string: str) -> bytes: | ||
return _encrypt(string.encode('ascii')) | ||
|
||
|
||
def decrypt(string: bytes) -> str: | ||
return _decrypt(string).decode('ascii') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters