3 M(ÌYã@sXdZddlZddlmZmZedƒZdZejdeƒdd„Z d d „Z d d „Z d d„Z dS)ajVARBLOCK file support .. deprecated:: 3.4 The VARBLOCK format is NOT recommended for general use, has been deprecated since Python-RSA 3.4, and will be removed in a future release. It's vulnerable to a number of attacks: 1. decrypt/encrypt_bigfile() does not implement `Authenticated encryption`_ nor uses MACs to verify messages before decrypting public key encrypted messages. 2. decrypt/encrypt_bigfile() does not use hybrid encryption (it uses plain RSA) and has no method for chaining, so block reordering is possible. See `issue #19 on Github`_ for more information. .. _Authenticated encryption: https://en.wikipedia.org/wiki/Authenticated_encryption .. _issue #19 on Github: https://github.com/sybrenstuvel/python-rsa/issues/13 The VARBLOCK file format is as follows, where || denotes byte concatenation: FILE := VERSION || BLOCK || BLOCK ... BLOCK := LENGTH || DATA LENGTH := varint-encoded length of the subsequent data. Varint comes from Google Protobuf, and encodes an integer into a variable number of bytes. Each byte uses the 7 lowest bits to encode the value. The highest bit set to 1 indicates the next byte is also part of the varint. The last byte will have this bit set to 0. This file format is called the VARBLOCK format, in line with the varint format used to denote the block sizes. éN)ÚbyteÚbúézÀThe 'rsa.varblock' module was deprecated in Python-RSA version 3.4 due to security issues in the VARBLOCK format. See https://github.com/sybrenstuvel/python-rsa/issues/13 for more information.cCstd}d}xf|jdƒ}t|ƒdkr8|dkr,dStd|ƒ‚t|ƒ}||d@d|>7}|d7}|d@s ||fSq WdS) axReads a varint from the file. When the first byte to be read indicates EOF, (0, 0) is returned. When an EOF occurs when at least one byte has been read, an EOFError exception is raised. :param infile: the file-like object to read from. It should have a read() method. :returns: (varint, length), the read varint and the number of read bytes. rrz,EOF while reading varint, value is %i so farééé€N)rr)ÚreadÚlenÚEOFErrorÚord)ÚinfileZvarintÚ read_bytesÚcharr©rú3/private/tmp/pip-build-nl73fm5q/rsa/rsa/varblock.pyÚ read_varintCs   rcCsb|dkr|jtƒdSd}xB|dkr\|d@}|dL}|dkrD|dO}|jt|ƒƒ|d7}qW|S)zªWrites a varint to a file. :param outfile: the file-like object to write to. It should have a write() method. :returns: the number of written bytes. rrrrr)ÚwriteÚ ZERO_BYTEr)ÚoutfileÚvalueZ written_bytesZto_writerrrÚ write_varintcs    rccs’|jdƒ}t|ƒdkrtdƒ‚t|ƒ}|tkr:td|ƒ‚xRt|ƒ\}}|dkrZ|dkrZP|j|ƒ}t|ƒ}||kr„td||fƒ‚|Vq4s "