documentation and nice API

APPLEMAIL-24 0.2
Volker Birk 4 years ago
parent 7cccd31145
commit b6672b63f6

@ -13,17 +13,6 @@ namespace pEp {
namespace UpdateClient {
using namespace CryptoPP;
PublicKey load_key(string filename)
{
ByteQueue queue;
FileSource file("public.der", true);
file.TransferTo(queue);
queue.MessageEnd();
CryptoPP::RSA::PublicKey key;
key.Load(queue);
return key;
}
UpdateDevice::UpdateDevice(const product p)
: _https({HTTPSDevice()}, ios::binary), _p(p),
_key(32), _src(nullptr), _str(nullptr)

@ -25,7 +25,6 @@ namespace pEp {
};
typedef CryptoPP::RSA::PublicKey PublicKey;
PublicKey load_key(string filename);
class UpdateDevice : public io::source {
HTTPSStream _https;

@ -8,6 +8,24 @@
namespace pEp {
namespace UpdateClient {
PublicKey load_key(string filename)
{
CryptoPP::RSA::PublicKey key;
try {
CryptoPP::ByteQueue queue;
CryptoPP::FileSource file("public.der", true);
file.TransferTo(queue);
queue.MessageEnd();
key.Load(queue);
}
catch (exception&) {
throw CannotLoadKey(filename);
}
return key;
}
string update(product p, PublicKey update_key)
{
UpdateStream us { UpdateDevice(p) };

@ -14,7 +14,48 @@ namespace pEp {
DownloadError() : runtime_error("download not possible") { }
};
struct CannotLoadKey : runtime_error {
CannotLoadKey(string filename)
: runtime_error("cannot load key from " + filename)
{
}
};
// load_key() - load BER encoded RSA public key
//
// params:
// filename (in) keyfile to load from
//
// returns:
// CryptoPP::RSA::PublicKey
//
// throws:
// CannotLoadKey if key cannot be loaded
PublicKey load_key(string filename);
// update() - download update for a product if available
//
// params:
// p (in) product to update with:
// name (in) product name
// url (in) download URL with GET param:
// hash serial number
// update_key (in) Update Key as CryptoPP::RSA::PublicKey
//
// returns:
// filename of downloaded file
//
// caveat:
// this function is using the current directory to download
// therefore, the current directory has to be writable
//
// see sample in test_updater.cc
string update(product p, PublicKey update_key);
// update() - convenience function doing load_key() and update()
string update(product p, string keyfile);
}
}

@ -10,28 +10,6 @@ using namespace pEp::UpdateClient;
int main()
{
/*
product p { "pEp for Something", "https://fdik.org/cgidownload?hash=23232323234242" };
UpdateStream us { UpdateDevice(p) };
cout << "downloading...\n";
PublicKey update_key = load_key("public.der");
try {
us->open(update_key);
}
catch (exception&) { }
if (us->filename() != "") {
cout << "downloaded " << us->filename() << "\n";
}
else {
stringstream str;
str << us.rdbuf();
cout << str.str() << "\n";
}
*/
cout << "downloading...\n";
product p { "pEp for Something", "https://fdik.org/cgidownload?hash=23232323234242" };

Loading…
Cancel
Save