示例#1
0
    def test_crypttextfile(self):
        t = CryptoTrace(os.path.join(PATH,"text.txt.crypted.trc"), "w")
        with open(os.path.join(PATH,"fixtures/text.txt"), 'r') as f:
            for l in f:
                t.write(l)
        t.flush()
        t.close()
        
        # check encrypted file on disk did not change
        self.assertEquals('995EB32D1067C5681B386E58305D14B5', 
            hashfile(os.path.join(PATH,"text.txt.crypted.trc")))

        # check round trip
        t2 = CryptoTrace(os.path.join(PATH,"text.txt.crypted.trc"), "r")
        with open(os.path.join(PATH,"text.txt.roundtrip"), 'w') as f:
            while True:
                data = t2.read(1024)
                if len(data) == 0:
                    break
                f.write(data)
        t2.close()

        # check decrypted file on disk same as original
        self.assertEquals('1F439C7547B1EF1C1D3085483A87AD2E',
            hashfile(os.path.join(PATH,"text.txt.roundtrip")))