-
Notifications
You must be signed in to change notification settings - Fork 0
/
createproposal.py
56 lines (45 loc) · 1.28 KB
/
createproposal.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
from hashlib import md5
from datetime import datetime
import pyme.core, pyme.constants.sig
import yaml
def getPassphrase(hint, desc, prev_bad):
#print "Passphrase Callback! %s %s %s" % (hint, desc, prev_bad)
#sys.stdout.write("Enter passphrase: ")
#return sys.stdin.readline().strip()
return "123456"
c = pyme.core.Context()
c.set_armor(1)
c.set_passphrase_cb(getPassphrase)
topic = {}
topic['type']='proposal'
topic['path']='58BD0CCEB421BFB9BE694135F66EA1A3025BA2BF/lunch/2009-07-16/place'
topic['title']='Sushi'
topic['id']=md5(topic['path']+topic['title']).hexdigest()
topic['short']='We shall eat tasty miso soup and rice rolls.'
topic['text']=None
topic['author']='futterbot'
blob = pyme.core.Data(yaml.dump(topic))
#print ("Fetching authority key")
c.op_keylist_start('Authority', 0)
r = c.op_keylist_next()
#print(r)
if not r:
print ("No such key found.")
sys.exit(1)
#print ("Exporting key")
key = pyme.core.Data()
c.op_export('Authority', 0, key)
#print ("Signing data with key %s." % str(r))
sig = pyme.core.Data()
c.signers_add(r)
#print ("So far, so good.")
c.op_sign(blob, sig, pyme.constants.sig.mode.CLEAR)
data = {}
sig.seek(0,0)
data['sig'] = sig.read()
#key.seek(0,0)
#data['key'] = key.read()
print(yaml.dump(data))