hopefully fixed pgp test, added pgp export function

master
Kevin Froman 2018-01-20 11:59:44 -06:00
parent 0042e2fe51
commit 26c1983a61
No known key found for this signature in database
GPG Key ID: 0D414D0FE405B63B
2 changed files with 14 additions and 3 deletions

View File

@ -18,10 +18,11 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
'''
# Misc functions that do not fit in the main api, but are useful
import getpass, sys, requests, configparser, os, socket
import getpass, sys, requests, configparser, os, socket, gnupg
class OnionrUtils():
'''Various useful functions'''
def __init__(self):
self.fingerprintFile = 'data/own-fingerprint.txt'
return
def printErr(self, text='an error occured'):
'''Print an error message to stderr with a new line'''
@ -60,4 +61,13 @@ class OnionrUtils():
retVal = True
finally:
sock.close()
return retVal
return retVal
def exportMyPubkey(self):
'''Export our PGP key if it exists'''
if not os.path.exists(self.fingerprintFile):
raise Exception("No fingerprint found, cannot export our PGP key.")
gpg = gnupg.GPG(gnupghome='./data/pgp/')
with open(self.fingerprintFile,'r') as f:
fingerprint = f.read()
ascii_armored_public_keys = gpg.export_keys(fingerprint)
return ascii_armored_public_keys

View File

@ -82,12 +82,13 @@ class OnionrTests(unittest.TestCase):
def testPGPGen(self):
print('--------------------------')
print('Testing PGP key generation')
torID = open('data/hs/hostname').read()
if os.path.exists('data/pgp/'):
self.assertTrue(True)
else:
import core
myCore = core.Core()
myCore.generateMainPGP()
myCore.generateMainPGP(torID)
if os.path.exists('data/pgp/'):
self.assertTrue(True)
def testHMACGen(self):