예제 #1
0
class Pkcs7Manager(object):
    from imzaci.digest.file_operations import DirHashHandler

    def __init__(self):
        self.sm_module = SMIME 
        self.sm=self.sm_module.SMIME()
        #That one will keep the pkcs7 document
        self.p7=None
        self.file_hash = None 
    def makebuf(self,txt):
        """ Makes a text buffer"""
        return BIO.MemoryBuffer(txt)
    
    def get_sign_hash(self,sign_dir,except_list = None):
        """
        That is an util method which gives back the final
        hash of a directory ...
        """
        from imzaci.digest.digest_util import DigestUtil
        from imzaci.digest.file_operations import DirHashHandler
        
        tmp_store_file = "tmp.txt"

        self.dir_hash = DirHashHandler(sign_dir,except_list)
        self.dir_hash.store_final_hash(tmp_store_file)
        #that is the hash of teh hashes ...
        self.file_hash = DigestUtil.digest_from_file(tmp_store_file)
        print "The final hash is ...:",self.file_hash
        #the buffer to be signed
        self.tosign_buffer=self.makebuf(self.file_hash)
        os.remove(tmp_store_file)
예제 #2
0
def test_dir_hash_creator():
    """
    It is a comparison between threadded and straight impl
    """
    result_file_name = "result.txt"
    import os
    if os.path.exists(result_file_name):
        os.remove(result_file_name)

    straight = compute_hash_without_thread(TEST_DIR)
    #print straight
    for i in range(0,1000):
        dh = DirHashHandler(TEST_DIR)
        threaded = dh.get_final_hash_dict()
        #print threaded
        assert straight.keys().sort() == threaded.keys().sort()
        assert straight.values().sort() == threaded.values().sort()
        if i%100==0:
            print "The %d of tests completed"%(i)

    result = dh.store_final_hash(result_file_name)
    assert result == True
예제 #3
0
    def get_sign_hash(self,sign_dir,except_list = None):
        """
        That is an util method which gives back the final
        hash of a directory ...
        """
        from imzaci.digest.digest_util import DigestUtil
        from imzaci.digest.file_operations import DirHashHandler
        
        tmp_store_file = "tmp.txt"

        self.dir_hash = DirHashHandler(sign_dir,except_list)
        self.dir_hash.store_final_hash(tmp_store_file)
        #that is the hash of teh hashes ...
        self.file_hash = DigestUtil.digest_from_file(tmp_store_file)
        print "The final hash is ...:",self.file_hash
        #the buffer to be signed
        self.tosign_buffer=self.makebuf(self.file_hash)
        os.remove(tmp_store_file)