diff options
author | Sebastian Reichel <sre@ring0.de> | 2013-02-09 20:21:04 +0100 |
---|---|---|
committer | Sebastian Reichel <sre@ring0.de> | 2013-02-09 20:21:04 +0100 |
commit | 5e0f885f9d0f48f5644810278b184e1999f21c99 (patch) | |
tree | 9c483962da2d288212d96107102961d31968e85c | |
parent | b2ce62eb3017e90773d99f3577db839d277d805d (diff) | |
download | serial-barcode-scanner-5e0f885f9d0f48f5644810278b184e1999f21c99.tar.bz2 |
implement gpg methods for the KtT Shop System
* list_keys()
* get_key()
-rw-r--r-- | src/admin.vala | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/src/admin.vala b/src/admin.vala index 6ba0c0a..c37c761 100644 --- a/src/admin.vala +++ b/src/admin.vala @@ -101,6 +101,9 @@ public class PGPKeyArchive { /* set home directory */ var info = gpg.get_engine_info(); gpg.set_engine_info(info.protocol, info.file_name, keyring); + + /* enable ascii armor */ + gpg.set_armor(true); } public void read() { @@ -143,11 +146,35 @@ public class PGPKeyArchive { } } - /* TODO: implement method, which list all keys available in the gpg keyring */ + public string[] list_keys() { + string[] result = {}; + GPG.Key key; + + gpg.op_keylist_start(); + + while(gpg.op_keylist_next(out key) == GPGError.ErrorCode.NO_ERROR) { + result += key.subkeys[0].fpr; + } - /* TODO: implement method, which gets a key by keyid from gpg keyring */ + gpg.op_keylist_end(); - /* TODO: implement method, which signs a message */ + return result; + } - /* TODO: implement method, which signs & encrypts a message */ + public string get_key(string fingerprint) { + GPG.Data keydata; + GPG.Data.create(out keydata); + + if(gpg.op_export(fingerprint, 0, keydata) == GPGError.ErrorCode.NO_ERROR) { + long size = keydata.seek(0, Posix.FILE.SEEK_END); + keydata.seek(0, Posix.FILE.SEEK_SET); + stdout.printf("size: %ld\n", size); + uint8[] data = new uint8[size]; + keydata.read(data); + return (string) data; + } else { + stdout.printf("error!\n"); + return ""; + } + } } |