Remove eexecOp C extension
It hasn't been working:
6102ba7500
And it's only used to load Type1 fonts, so who cares if the Python
implementation is slow...
This commit is contained in:
parent
c745f69d8a
commit
494d9d139e
@ -5,13 +5,6 @@ charstring encryption algorithm as used by PostScript Type 1 fonts.
|
|||||||
from __future__ import print_function, division
|
from __future__ import print_function, division
|
||||||
from fontTools.misc.py23 import *
|
from fontTools.misc.py23 import *
|
||||||
|
|
||||||
# Warning: Although a Python implementation is provided here,
|
|
||||||
# all four public functions get overridden by the *much* faster
|
|
||||||
# C extension module eexecOp, if available.
|
|
||||||
|
|
||||||
error = "eexec.error"
|
|
||||||
|
|
||||||
|
|
||||||
def _decryptChar(cipher, R):
|
def _decryptChar(cipher, R):
|
||||||
cipher = byteord(cipher)
|
cipher = byteord(cipher)
|
||||||
plain = ( (cipher ^ (R>>8)) ) & 0xFF
|
plain = ( (cipher ^ (R>>8)) ) & 0xFF
|
||||||
@ -26,8 +19,6 @@ def _encryptChar(plain, R):
|
|||||||
|
|
||||||
|
|
||||||
def decrypt(cipherstring, R):
|
def decrypt(cipherstring, R):
|
||||||
# I could probably speed this up by inlining _decryptChar,
|
|
||||||
# but... we've got eexecOp, so who cares ;-)
|
|
||||||
plainList = []
|
plainList = []
|
||||||
for cipher in cipherstring:
|
for cipher in cipherstring:
|
||||||
plain, R = _decryptChar(cipher, R)
|
plain, R = _decryptChar(cipher, R)
|
||||||
@ -55,20 +46,10 @@ def deHexString(h):
|
|||||||
|
|
||||||
|
|
||||||
def _test():
|
def _test():
|
||||||
import fontTools.misc.eexecOp
|
|
||||||
testStr = "\0\0asdadads asds\265"
|
testStr = "\0\0asdadads asds\265"
|
||||||
print(decrypt, decrypt(testStr, 12321))
|
print(decrypt, decrypt(testStr, 12321))
|
||||||
print(eexecOp.decrypt, eexecOp.decrypt(testStr, 12321))
|
|
||||||
print(encrypt, encrypt(testStr, 12321))
|
print(encrypt, encrypt(testStr, 12321))
|
||||||
print(eexecOp.encrypt, eexecOp.encrypt(testStr, 12321))
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
_test()
|
_test()
|
||||||
|
|
||||||
|
|
||||||
try:
|
|
||||||
from fontTools.misc.eexecOp import *
|
|
||||||
except ImportError:
|
|
||||||
pass # Use the slow Python versions
|
|
||||||
|
|
||||||
|
@ -11,4 +11,3 @@ include Windows/README.TXT
|
|||||||
include Windows/fonttools-win-setup.iss
|
include Windows/fonttools-win-setup.iss
|
||||||
include Windows/fonttools-win-setup.txt
|
include Windows/fonttools-win-setup.txt
|
||||||
include Lib/fontTools/ttLib/tables/table_API_readme.txt
|
include Lib/fontTools/ttLib/tables/table_API_readme.txt
|
||||||
include Src/eexecOp/README.txt
|
|
||||||
|
@ -1,15 +0,0 @@
|
|||||||
eexecOp is imported by the fontTools.misc.eexec module, and the latter
|
|
||||||
provides a (slow) Python implementation in case eexecOp isn't there.
|
|
||||||
It is designed to be a shared library, to be placed in
|
|
||||||
FontTools/Lib/fontTools/misc/
|
|
||||||
but it should also work as a (possibly statically linked) top level module.
|
|
||||||
|
|
||||||
It is built automatically when you run
|
|
||||||
|
|
||||||
python setup.py build
|
|
||||||
or
|
|
||||||
python setup.py install
|
|
||||||
|
|
||||||
in the top level FontTools directory.
|
|
||||||
|
|
||||||
Just
|
|
@ -1,203 +0,0 @@
|
|||||||
/*
|
|
||||||
** Copyright 1996-2001 by Letterror: Just van Rossum, The Netherlands.
|
|
||||||
**
|
|
||||||
** Open source.
|
|
||||||
**
|
|
||||||
** Module implementing the eexec and charstring encryption algorithm as
|
|
||||||
** used by PostScript Type 1 fonts.
|
|
||||||
**
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "Python.h"
|
|
||||||
#include <ctype.h>
|
|
||||||
|
|
||||||
static PyObject *ErrorObject;
|
|
||||||
|
|
||||||
/* ----------------------------------------------------- */
|
|
||||||
|
|
||||||
static char eexec_decrypt__doc__[] =
|
|
||||||
""
|
|
||||||
;
|
|
||||||
|
|
||||||
static PyObject *
|
|
||||||
eexec_decrypt(PyObject *self, PyObject *args)
|
|
||||||
{
|
|
||||||
PyObject *_res = NULL;
|
|
||||||
unsigned short R;
|
|
||||||
int tempR; /* can't portably use unsigned shorts between Python versions */
|
|
||||||
unsigned short c1 = 52845;
|
|
||||||
unsigned short c2 = 22719;
|
|
||||||
unsigned char * inbuf;
|
|
||||||
unsigned char * outbuf;
|
|
||||||
unsigned long counter, insize;
|
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "s#i", &inbuf, &insize, &tempR))
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
R = (unsigned short)tempR;
|
|
||||||
|
|
||||||
if ((outbuf = malloc(insize)) == NULL)
|
|
||||||
{
|
|
||||||
PyErr_NoMemory();
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
for(counter = 0;counter < insize; counter++) {
|
|
||||||
outbuf[counter] = (inbuf[counter] ^ (R>>8));
|
|
||||||
R = (inbuf[counter] + R) * c1 + c2;
|
|
||||||
}
|
|
||||||
|
|
||||||
_res = Py_BuildValue("s#l", outbuf, insize, (unsigned long)R);
|
|
||||||
free(outbuf);
|
|
||||||
return _res;
|
|
||||||
}
|
|
||||||
|
|
||||||
static char eexec_encrypt__doc__[] =
|
|
||||||
""
|
|
||||||
;
|
|
||||||
|
|
||||||
static PyObject *
|
|
||||||
eexec_encrypt(PyObject *self, PyObject *args)
|
|
||||||
{
|
|
||||||
PyObject *_res = NULL;
|
|
||||||
unsigned short R;
|
|
||||||
int tempR; /* can't portably use unsigned shorts between Python versions */
|
|
||||||
unsigned short c1 = 52845;
|
|
||||||
unsigned short c2 = 22719;
|
|
||||||
unsigned char * inbuf;
|
|
||||||
unsigned char * outbuf;
|
|
||||||
unsigned long counter, insize;
|
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "s#i", &inbuf, &insize, &tempR))
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
R = (unsigned short)tempR;
|
|
||||||
|
|
||||||
if ((outbuf = malloc(insize)) == NULL)
|
|
||||||
{
|
|
||||||
PyErr_NoMemory();
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
for(counter = 0;counter < insize; counter++) {
|
|
||||||
outbuf[counter] = (inbuf[counter] ^ (R>>8));
|
|
||||||
R = (outbuf[counter] + R) * c1 + c2;
|
|
||||||
}
|
|
||||||
|
|
||||||
_res = Py_BuildValue("s#l", outbuf, insize, (unsigned long)R);
|
|
||||||
free(outbuf);
|
|
||||||
return _res;
|
|
||||||
}
|
|
||||||
|
|
||||||
static char eexec_hexString__doc__[] =
|
|
||||||
""
|
|
||||||
;
|
|
||||||
|
|
||||||
static PyObject *
|
|
||||||
eexec_hexString(PyObject *self, PyObject *args)
|
|
||||||
{
|
|
||||||
PyObject *_res = NULL;
|
|
||||||
unsigned char * inbuf;
|
|
||||||
unsigned char * outbuf;
|
|
||||||
static const unsigned char hexchars[] = "0123456789ABCDEF";
|
|
||||||
unsigned long i, insize;
|
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "s#", &inbuf, &insize))
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
outbuf = malloc(2 * insize);
|
|
||||||
if (outbuf == NULL) {
|
|
||||||
PyErr_NoMemory();
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < insize; i++) {
|
|
||||||
outbuf[2 * i] = hexchars[(inbuf[i] >> 4) & 0xF];
|
|
||||||
outbuf[2 * i + 1] = hexchars[inbuf[i] & 0xF];
|
|
||||||
}
|
|
||||||
_res = Py_BuildValue("s#", outbuf, 2 * insize);
|
|
||||||
free(outbuf);
|
|
||||||
return _res;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#define HEX2DEC(c) ((c) >= 'A' ? ((c) - 'A' + 10) : ((c) - '0'))
|
|
||||||
|
|
||||||
static char eexec_deHexString__doc__[] =
|
|
||||||
""
|
|
||||||
;
|
|
||||||
|
|
||||||
static PyObject *
|
|
||||||
eexec_deHexString(PyObject *self, PyObject *args)
|
|
||||||
{
|
|
||||||
PyObject *_res = NULL;
|
|
||||||
unsigned char * inbuf;
|
|
||||||
unsigned char * outbuf;
|
|
||||||
unsigned char c1, c2;
|
|
||||||
unsigned long insize, i;
|
|
||||||
|
|
||||||
if (!PyArg_ParseTuple(args, "s#", &inbuf, &insize))
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
if (insize % 2) {
|
|
||||||
PyErr_SetString(ErrorObject, "hex string must have even length");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
outbuf = malloc(insize / 2);
|
|
||||||
if (outbuf == NULL) {
|
|
||||||
PyErr_NoMemory();
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
for ( i = 0; i < insize; i += 2) {
|
|
||||||
c1 = toupper(inbuf[i]);
|
|
||||||
c2 = toupper(inbuf[i+1]);
|
|
||||||
if (!isxdigit(c1) || !isxdigit(c1)) {
|
|
||||||
PyErr_SetString(ErrorObject, "non-hex character found");
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
outbuf[i/2] = (HEX2DEC(c2)) | (HEX2DEC(c1) << 4);
|
|
||||||
}
|
|
||||||
_res = Py_BuildValue("s#", outbuf, insize / 2);
|
|
||||||
error:
|
|
||||||
free(outbuf);
|
|
||||||
return _res;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* List of methods defined in the module */
|
|
||||||
|
|
||||||
static struct PyMethodDef eexec_methods[] = {
|
|
||||||
{"decrypt", (PyCFunction)eexec_decrypt, METH_VARARGS, eexec_decrypt__doc__},
|
|
||||||
{"encrypt", (PyCFunction)eexec_encrypt, METH_VARARGS, eexec_encrypt__doc__},
|
|
||||||
{"hexString", (PyCFunction)eexec_hexString, METH_VARARGS, eexec_hexString__doc__},
|
|
||||||
{"deHexString", (PyCFunction)eexec_deHexString, METH_VARARGS, eexec_deHexString__doc__},
|
|
||||||
{NULL, (PyCFunction)NULL, 0, NULL} /* sentinel */
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/* Initialization function for the module (*must* be called initeexec) */
|
|
||||||
|
|
||||||
static char eexec_module_documentation[] =
|
|
||||||
""
|
|
||||||
;
|
|
||||||
|
|
||||||
void initeexecOp(void); /* prototype to shut up the compiler */
|
|
||||||
|
|
||||||
void initeexecOp(void)
|
|
||||||
{
|
|
||||||
PyObject *m, *d;
|
|
||||||
|
|
||||||
/* Create the module and add the functions */
|
|
||||||
m = Py_InitModule4("eexecOp", eexec_methods,
|
|
||||||
eexec_module_documentation,
|
|
||||||
(PyObject*)NULL,PYTHON_API_VERSION);
|
|
||||||
|
|
||||||
/* Add some symbolic constants to the module */
|
|
||||||
d = PyModule_GetDict(m);
|
|
||||||
ErrorObject = PyString_FromString("eexec.error");
|
|
||||||
PyDict_SetItemString(d, "error", ErrorObject);
|
|
||||||
|
|
||||||
/* Check for errors */
|
|
||||||
if (PyErr_Occurred())
|
|
||||||
Py_FatalError("can't initialize module eexec");
|
|
||||||
}
|
|
||||||
|
|
10
setup.py
10
setup.py
@ -80,16 +80,6 @@ setup(
|
|||||||
],
|
],
|
||||||
package_dir = {'': 'Lib'},
|
package_dir = {'': 'Lib'},
|
||||||
extra_path = 'FontTools',
|
extra_path = 'FontTools',
|
||||||
ext_modules = [
|
|
||||||
Extension(
|
|
||||||
"fontTools.misc.eexecOp",
|
|
||||||
["Src/eexecOp/eexecOpmodule.c"],
|
|
||||||
include_dirs=[],
|
|
||||||
define_macros=[],
|
|
||||||
library_dirs=[],
|
|
||||||
libraries=[],
|
|
||||||
)
|
|
||||||
],
|
|
||||||
scripts = ["Tools/ttx", "Tools/pyftsubset", "Tools/pyftinspect"],
|
scripts = ["Tools/ttx", "Tools/pyftsubset", "Tools/pyftinspect"],
|
||||||
cmdclass = {"build_ext": build_ext_optional},
|
cmdclass = {"build_ext": build_ext_optional},
|
||||||
data_files = [('share/man/man1', ["Doc/ttx.1"])],
|
data_files = [('share/man/man1', ["Doc/ttx.1"])],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user