summaryrefslogtreecommitdiffstats
path: root/crypt.cpp
diff options
context:
space:
mode:
authorKyle K <kylek389@gmail.com>2011-02-21 14:47:20 -0600
committerKamil Kaminski <kamilkss@gmail.com>2011-02-21 14:47:20 -0600
commit660300b28954f6120ca472940146556c11982307 (patch)
tree9249d4f2e7f7f57047b2f6338d8891e3ada89753 /crypt.cpp
parent6f39a3ebc807f66a32201ad24794ed7881151217 (diff)
downloadrsacrypt-660300b28954f6120ca472940146556c11982307.tar.gz
rsacrypt-660300b28954f6120ca472940146556c11982307.tar.bz2
rsacrypt-660300b28954f6120ca472940146556c11982307.zip
few small changesHEADmaster
Diffstat (limited to 'crypt.cpp')
-rw-r--r--crypt.cpp22
1 files changed, 20 insertions, 2 deletions
diff --git a/crypt.cpp b/crypt.cpp
index 5f0d01d..f59a704 100644
--- a/crypt.cpp
+++ b/crypt.cpp
@@ -17,25 +17,37 @@ extern char *outfname;
struct rsakey_t
{
- long unsigned e, d, n;
+ unsigned long e, d, n;
+ bool valid_rsa_tag;
};
/* parse pubkey xml file */
struct rsakey_t parse_key(FILE *file)
{
struct rsakey_t key = { 0, 0, 0};
+ key.valid_rsa_tag = false;
/* used for line reading */
size_t line_sz = 0;
char *line = NULL;
+ bool rsa_opening_tag = false;
+ bool rsa_closing_tag = false;
+
while (getline(&line, &line_sz, file) != -1)
{
+ if (strcmp(line, "<rsakey>\n") == 0)
+ rsa_opening_tag = true;
sscanf(line, "\t<dvalue>%lu</dvalue>\n", &key.d);
sscanf(line, "\t<evalue>%lu</evalue>\n", &key.e);
sscanf(line, "\t<nvalue>%lu</nvalue>\n", &key.n);
+ if (strcmp(line, "</rsakey>\n") == 0)
+ rsa_closing_tag = true;
}
+ if (rsa_opening_tag && rsa_closing_tag)
+ key.valid_rsa_tag = true;
+
if (line)
free(line);
@@ -74,7 +86,13 @@ int main(int argc, char **argv)
int mode = -1;
struct rsakey_t key = parse_key(keyfname_fl);
- if (key.d == 0 && key.e && key.n)
+ if (!key.valid_rsa_tag)
+ {
+ fprintf(stderr, "invalid key or invalid xml\n");
+ exit(EXIT_FAILURE);
+ }
+
+ else if (key.d == 0 && key.e && key.n)
{
cout << "public key (" << key.e << ", " << key.n
<< ") detected, will perform encryption" << endl;