From f2d1ba9365a037ebc9479401c8ec3b64fcbe06d0 Mon Sep 17 00:00:00 2001 From: Mirek Kratochvil Date: Fri, 24 Jan 2014 10:30:13 +0100 Subject: [PATCH] actions: be helpful on missing ascii-armor option Refs #4 on github --- src/actions.cpp | 15 +++++++++++++++ src/envelope.cpp | 5 +++++ src/envelope.h | 6 ++++++ 3 files changed, 26 insertions(+) diff --git a/src/actions.cpp b/src/actions.cpp index 3265531..0b03f90 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -240,6 +240,9 @@ int action_decrypt (bool armor, sencode*M = sencode_decode (data); if (!M) { err ("error: could not parse input sencode"); + if (!armor && envelope_lookalike (data) ) + err ("notice: input looks ascii-armored, " + "try using the armor option"); return 1; } @@ -599,6 +602,9 @@ int action_verify (bool armor, const std::string&detach, sencode*M = sencode_decode (data); if (!M) { err ("error: could not parse input sencode"); + if (!armor && envelope_lookalike (data) ) + err ("notice: input looks ascii-armored, " + "try using the armor option"); return 1; } @@ -821,6 +827,9 @@ int action_decrypt_verify (bool armor, bool yes, sencode*M = sencode_decode (data); if (!M) { err ("error: could not parse input sencode"); + if (!armor && envelope_lookalike (data) ) + err ("notice: input looks ascii-armored, " + "try using the armor option"); return 1; } @@ -1033,6 +1042,9 @@ int action_import (bool armor, bool no_action, bool yes, bool fp, sencode*S = sencode_decode (data); if (!S) { err ("error: could not parse input sencode"); + if (!armor && envelope_lookalike (data) ) + err ("notice: input looks ascii-armored, " + "try using the armor option"); return 1; } @@ -1301,6 +1313,9 @@ int action_import_sec (bool armor, bool no_action, bool yes, bool fp, sencode*S = sencode_decode (data); if (!S) { err ("error: could not parse input sencode"); + if (!armor && envelope_lookalike (data) ) + err ("notice: input looks ascii-armored, " + "try using the armor option"); return 1; } diff --git a/src/envelope.cpp b/src/envelope.cpp index bedcd4b..8ea57d5 100644 --- a/src/envelope.cpp +++ b/src/envelope.cpp @@ -216,3 +216,8 @@ std::string envelope_format (const std::string&type, return res; } } + +bool envelope_lookalike (const std::string&data) +{ + return data.find ("------ccr begin ") != data.npos; +} diff --git a/src/envelope.h b/src/envelope.h index 5d677e8..094a0cf 100644 --- a/src/envelope.h +++ b/src/envelope.h @@ -48,4 +48,10 @@ std::string envelope_format (const std::string&type, const std::vector& parts, prng&rng); +/* + * guesses whether input looks like an envelope + */ +bool envelope_lookalike (const std::string&); + + #endif