Add GPG-wrapper script for Git

This commit is contained in:
Roman Zeyde 2016-04-18 23:02:14 +03:00
parent 96592269b6
commit af6d0caf33

31
gpg/git_gpg_wrapper.py Executable file
View File

@ -0,0 +1,31 @@
#!/usr/bin/env python
import sys
import subprocess as sp
import time
import logging
import os
import signer
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s %(levelname)-10s %(message)s')
def main():
args = sys.argv[1:]
if '--verify' in args:
sp.check_call(['gpg2'] + args)
else:
user_id = os.environ['GPG_USER_ID']
user_id = user_id.encode('ascii')
pubkey = signer.load_from_gpg(user_id)
s = signer.Signer(user_id=user_id, created=pubkey['created'])
assert s.key_id() == pubkey['key_id']
data = sys.stdin.read()
sig = s.sign(data)
sig = signer.armor(sig, 'SIGNATURE')
sys.stdout.write(sig)
s.close()
if __name__ == '__main__':
main()