'''
Created on 23.02.2013

@author: thomas
'''
import gnupg

class Crypt(object):
    
    def __init__(self,home):
        self.home=home
        self.gpg=gnupg.GPG(gnupghome=self.home)
        self.list_keys=self.gpg.list_keys
        pass

    """
    maps to gnupg, note that key generation is terribly slow if you do not 
    provide enough entropy
    """
    def create(self,email,passphrase, key_length=4096):
        auth = self.gpg.gen_key_input(name_email=email,
                                      name_comment ='generated by cloudestine',
                                      name_real = "auto generated" ,
                                      passphrase = passphrase,key_type="RSA", 
                                      key_length = key_length)
        key = self.gpg.gen_key(auth)
        with open(self.home+'/'+key.fingerprint,'w') as f:
            f.write(self.gpg.export_keys(key, True))
            f.close
            
        return key
    
    