def testdigest(self):
     """Check the registration of a digest"""
     results = timevouchclient.registerdigest(sha256(open('testdata', 'rb').read()).hexdigest(),
                                              self.secretword)
     for key, value in (
         ('registered', '2011-03-08T18:42:24Z'),
         ('olddigest', True),
         ('digest', '103f381bbdf93f1ea674b35e6177f7204bdd0618054ddd65f2190e130f7f35f3')):
         self.assertEqual(results[key], value)
Beispiel #2
0
    def sendfile(self):
        """Send the digest (and possibly secret word) to the
        TimeVouch.com server and display the results"""

        try:
            json = timevouchclient.registerdigest(self.digest.text(), self.secretword.text())
        except IOError as errordict:
            QtGui.QMessageBox.warning(self, 'Error condition - %s' % errordict['error'], errordict['message'])
            return
        
        message = QtGui.QMessageBox()
        olddoc = json['olddigest']
        if olddoc:
            message.setWindowTitle('TimeVouch.com results - verified registration')
            message.setText('This file has already been registered. Its contents have '
                            'not been modified in any way since that time.')
        else:
            message.setWindowTitle('TimeVouch.com results - new registration')
            message.setText('This file had never been seen before, and has now been registered.')

        def maketr(key, value, style=None):
            """Turn the given key, value, and optional CSS style into
            a table row"""
            if style:
                stylestr = ' style="%s"' % style
            else:
                stylestr = ''
            key = key.replace(' ', ' ')
            return '<tr><td>%s</td><td%s>%s</td></tr>' % (key, stylestr, value)

        lines = []
        lines.append(maketr('Digest:', json['digest'], 'color: blue;'))
        lines.append(maketr('Registered:', json['registered'], 'color: green;'))
        lines.append(maketr('Current time:', json['currenttime'], 'color: green;'))
        if olddoc:
            validatesummarycolor = {'unavailable' : 'blue',
                                    'successful'  : 'green',
                                    'unsuccessful': 'red',}[json['validatesummary']]
            lines.append(maketr('Extended validation:', json['validatesummary'], 'color: %s;' % validatesummarycolor))
        text = '<table>' + '\n'.join(lines) + '</table>'
        if olddoc:
            text += '<p>%s</p>' % json['validatemessage']
        message.setInformativeText(text)
        message.setDetailedText(str(json))
        message.exec_()