#include "handler.ih"

namespace 
{
    char const beginSignature[] = "-----BEGIN PGP SIGNATURE-----";
    char const endSignature[] = "-----END PGP SIGNATURE-----";
}

void Handler::saveSignature(string const &signature)
{
    string line;
    while (getline(cin, line) && 
            line.find(beginSignature) == string::npos)
        ;

    ofstream out(signature);

    do
    {
        out << line << '\n';
        if (line.find(endSignature) != string::npos)
            return;
    }
    while (getline(cin, line));

    throw Exception{REPLY} << 
            "saveSignature: cannot find PGP signature block";
}
