Ejemplo n.º 1
0
    def test_dump_quoteattr_cr(self):
        from hwp5.xmlmodel import XmlEvents
        from hwp5.importhelper import importStringIO
        from hwp5.treeop import STARTEVENT, ENDEVENT
        from hwp5.binmodel import ControlChar
        StringIO = importStringIO()
        sio = StringIO()

        context = dict()
        attrs = dict(char='\r')
        events = [(STARTEVENT, (ControlChar, attrs, context)),
                  (ENDEVENT, (ControlChar, attrs, context))]
        xmlevents = XmlEvents(iter(events))
        xmlevents.dump(sio)

        data = sio.getvalue()
        self.assertTrue('
' in data)
Ejemplo n.º 2
0
    def test_dump_quoteattr_cr(self):
        from hwp5.xmlmodel import XmlEvents
        from hwp5.importhelper import importStringIO
        from hwp5.treeop import STARTEVENT, ENDEVENT
        from hwp5.binmodel import ControlChar
        StringIO = importStringIO()
        sio = StringIO()

        context = dict()
        attrs = dict(char='\r')
        events = [(STARTEVENT, (ControlChar, attrs, context)),
                  (ENDEVENT, (ControlChar, attrs, context))]
        xmlevents = XmlEvents(iter(events))
        xmlevents.dump(sio)

        data = sio.getvalue()
        self.assertTrue('
' in data)
Ejemplo n.º 3
0
#   You should have received a copy of the GNU Affero General Public License
#   along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
''' Decode distribute docs.

Based on the algorithm described by Changwoo Ryu
See https://groups.google.com/forum/#!topic/hwp-foss/d2KL2ypR89Q
'''
import logging

from hwp5.recordstream import read_record
from hwp5.tagids import HWPTAG_DISTRIBUTE_DOC_DATA
from hwp5.importhelper import importStringIO
from hwp5.plat import get_aes128ecb_decrypt

StringIO = importStringIO()

logger = logging.getLogger(__name__)


def decode(stream):
    distdoc_data_record = read_record(stream, 0)
    if distdoc_data_record['tagid'] != HWPTAG_DISTRIBUTE_DOC_DATA:
        raise IOError('the first record is not an HWPTAG_DISTRIBUTE_DOC_DATA')
    distdoc_data = distdoc_data_record['payload']
    key = decode_head_to_key(distdoc_data)
    tail = stream.read()
    decrypted = decrypt_tail(key, tail)
    return StringIO(decrypted)