pdfminer.six/tests/test_pdfminer_crypto.py

54 lines
1.6 KiB
Python
Raw Normal View History

"""Test of various compression/encoding modules (previously in doctests)
"""
import binascii
2014-09-04 07:36:19 +00:00
Enforce pep8 coding-style (#345) * Code Refractor: Use code-style enforcement #312 * Add flake8 to travis-ci * Remove python 2 3 comment on six library. 891 errors > 870 errors. * Remove class and functions comments that consist of just the name. 870 errors > 855 errors. * Fix flake8 errors in pdftypes.py. 855 errors > 833 errors. * Moving flake8 testing from .travis.yml to tox.ini to ensure local testing before commiting * Cleanup pdfinterp.py and add documentation from PDF Reference * Cleanup pdfpage.py * Cleanup pdffont.py * Clean psparser.py * Cleanup high_level.py * Cleanup layout.py * Cleanup pdfparser.py * Cleanup pdfcolor.py * Cleanup rijndael.py * Cleanup converter.py * Rename klass to cls if it is the class variable, to be more consistent with standard practice * Cleanup cmap.py * Cleanup pdfdevice.py * flake8 ignore fontmetrics.py * Cleanup test_pdfminer_psparser.py * Fix flake8 in pdfdocument.py; 339 errors to go * Fix flake8 utils.py; 326 errors togo * pep8 correction for few files in /tools/ 328 > 160 to go (#342) * pep8 correction for few files in /tools/ 328 > 160 to go * pep8 correction: 160 > 5 to go * Fix ascii85.py errors * Fix error in getting index from target that does not exists * Remove commented print lines * Fix flake8 error in pdfinterp.py * Fix python2 specific error by removing argument from print statement * Ignore invalid python2 syntax * Update contributing.md * Added changelog * Remove unused import Co-authored-by: Fakabbir Amin <f4amin@gmail.com>
2019-12-29 20:20:20 +00:00
from pdfminer.arcfour import Arcfour
from pdfminer.ascii85 import asciihexdecode, ascii85decode
from pdfminer.lzw import lzwdecode
from pdfminer.runlength import rldecode
def hex(b):
"""encode('hex')"""
return binascii.hexlify(b)
def dehex(b):
"""decode('hex')"""
return binascii.unhexlify(b)
2014-09-04 07:36:19 +00:00
class TestAscii85():
def test_ascii85decode(self):
Enforce pep8 coding-style (#345) * Code Refractor: Use code-style enforcement #312 * Add flake8 to travis-ci * Remove python 2 3 comment on six library. 891 errors > 870 errors. * Remove class and functions comments that consist of just the name. 870 errors > 855 errors. * Fix flake8 errors in pdftypes.py. 855 errors > 833 errors. * Moving flake8 testing from .travis.yml to tox.ini to ensure local testing before commiting * Cleanup pdfinterp.py and add documentation from PDF Reference * Cleanup pdfpage.py * Cleanup pdffont.py * Clean psparser.py * Cleanup high_level.py * Cleanup layout.py * Cleanup pdfparser.py * Cleanup pdfcolor.py * Cleanup rijndael.py * Cleanup converter.py * Rename klass to cls if it is the class variable, to be more consistent with standard practice * Cleanup cmap.py * Cleanup pdfdevice.py * flake8 ignore fontmetrics.py * Cleanup test_pdfminer_psparser.py * Fix flake8 in pdfdocument.py; 339 errors to go * Fix flake8 utils.py; 326 errors togo * pep8 correction for few files in /tools/ 328 > 160 to go (#342) * pep8 correction for few files in /tools/ 328 > 160 to go * pep8 correction: 160 > 5 to go * Fix ascii85.py errors * Fix error in getting index from target that does not exists * Remove commented print lines * Fix flake8 error in pdfinterp.py * Fix python2 specific error by removing argument from print statement * Ignore invalid python2 syntax * Update contributing.md * Added changelog * Remove unused import Co-authored-by: Fakabbir Amin <f4amin@gmail.com>
2019-12-29 20:20:20 +00:00
"""The sample string is taken from:
http://en.wikipedia.org/w/index.php?title=Ascii85"""
assert ascii85decode(b'9jqo^BlbD-BleB1DJ+*+F(f,q') \
== b'Man is distinguished'
assert ascii85decode(b'E,9)oF*2M7/c~>') == b'pleasure.'
2014-09-04 07:36:19 +00:00
def test_asciihexdecode(self):
assert asciihexdecode(b'61 62 2e6364 65') == b'ab.cde'
assert asciihexdecode(b'61 62 2e6364 657>') == b'ab.cdep'
assert asciihexdecode(b'7>') == b'p'
2014-09-04 07:36:19 +00:00
class TestArcfour():
def test(self):
assert hex(Arcfour(b'Key').process(b'Plaintext')) \
== b'bbf316e8d940af0ad3'
assert hex(Arcfour(b'Wiki').process(b'pedia')) == b'1021bf0420'
assert hex(Arcfour(b'Secret').process(b'Attack at dawn')) \
== b'45a01f645fc35b383552544b9bf5'
2014-09-04 07:36:19 +00:00
class TestLzw():
def test_lzwdecode(self):
assert lzwdecode(b'\x80\x0b\x60\x50\x22\x0c\x0c\x85\x01') \
== b'\x2d\x2d\x2d\x2d\x2d\x41\x2d\x2d\x2d\x42'
2014-09-04 07:36:19 +00:00
class TestRunlength():
def test_rldecode(self):
assert rldecode(b'\x05123456\xfa7\x04abcde\x80junk') \
== b'1234567777777abcde'