Public feed #600888

Stuff

public text v1 · immutable
Raw Edit
·published 2007-07-03 04:18 UTC
rendered paste body
#!/usr/bin/python

import cStringIO
import time
import sys

import gpgme

import database

def decrypt_ciphertext(db, ctx, ciphertext_id, cycle, ciphertext):
    try:
        decrypt_start = time.time()

        ciphertext_io = cStringIO.StringIO(ciphertext)
        plaintext_io = cStringIO.StringIO()

        ctx.decrypt_verify(ciphertext_io, plaintext_io)
        
        plaintext = plaintext_io.getvalue()
        
        decrypt_end = time.time()
        
        db.accept_plaintext(ciphertext_id, cycle, decrypt_start, decrypt_end, plaintext)

        sys.stderr.write('Decrypted dataset for cycle %s:\n' % cycle)
        sys.stderr.write('    Ciphertext length: %i bytes\n' % len(ciphertext))
        sys.stderr.write('    Plaintext length:  %i bytes\n' % len(plaintext))

    except gpgme.GpgmeError, e:
        sys.stdout.write('Unable to decrypt encrypted dataset for cycle %s:\n' % cycle)
        sys.stdout.write('    %i %i %s\n' % (e.source, e.code, e.message))
    
db = database.Database()
ctx = gpgme.Context()

for ciphertext_id, cycle, ciphertext in db.need_decrypted():
    decrypt_ciphertext(db, ctx, ciphertext_id, cycle, ciphertext)