/* system implementation headers */
#include <string.h>
+#include <stdio.h>
// Constants for MD5Transform routine.
#define S11 7
//////////////////////////////
// return hex representation of digest as string
-// std::string MD5::hexdigest() const
-// {
-// if (!finalized)
-// return "";
+std::string MD5::hexdigest() const
+{
+ if (!finalized)
+ return "";
-// char buf[33];
-// for (int i = 0; i < 16; i++)
-// sprintf(buf + i * 2, "%02x", digest[i]);
-// buf[32] = 0;
+ char buf[33];
+ for (int i = 0; i < 16; i++)
+ sprintf(buf + i * 2, "%02x", digest[i]);
+ buf[32] = 0;
-// return std::string(buf);
-// }
+ return std::string(buf);
+}
// return the slected number of bytes from the digest
void MD5::bindigest(void *buf, int len) const
//////////////////////////////
-std::string md5(const std::string str)
-{
- MD5 md5 = MD5(str);
+// std::string md5(const std::string str)
+// {
+// MD5 md5 = MD5(str);
- return md5.hexdigest();
-}
+// return md5.hexdigest();
+// }
#include "SwitchPublicAccess.h"
#include "SDFAT.h"
#include "Thermistor.h"
+#include "md5.h"
#include "system_LPC17xx.h"
#include "LPC17xx.h"
{"remount", SimpleShell::remount_command},
{"calc_thermistor", SimpleShell::calc_thermistor_command},
{"thermistors", SimpleShell::print_thermistors_command},
+ {"md5sum", SimpleShell::md5sum_command},
// unknown command
{NULL, NULL}
}
}
+void SimpleShell::md5sum_command( string parameters, StreamOutput *stream )
+{
+ string filename = absolute_from_relative(parameters);
+
+ // Open file
+ FILE *lp = fopen(filename.c_str(), "r");
+ if (lp == NULL) {
+ stream->printf("File not found: %s\r\n", filename.c_str());
+ return;
+ }
+ MD5 md5;
+ uint8_t buf[64];
+ do {
+ size_t n= fread(buf, 1, sizeof buf, lp);
+ if(n > 0) md5.update(buf, n);
+ } while(!feof(lp));
+
+ stream->printf("%s %s\n", md5.finalize().hexdigest().c_str(), filename.c_str());
+ fclose(lp);
+}
+
+
+
void SimpleShell::help_command( string parameters, StreamOutput *stream )
{
stream->printf("Commands:\r\n");
stream->printf("upload filename - saves a stream of text to the named file\r\n");
stream->printf("calc_thermistor [-s0] T1,R1,T2,R2,T3,R3 - calculate the Steinhart Hart coefficients for a thermistor\r\n");
stream->printf("thermistors - print out the predefined thermistors\r\n");
+ stream->printf("md5sum file - prints md5 sum of the given file\r\n");
}
static void set_temp_command(string parameters, StreamOutput *stream );
static void calc_thermistor_command( string parameters, StreamOutput *stream);
static void print_thermistors_command( string parameters, StreamOutput *stream);
+ static void md5sum_command( string parameters, StreamOutput *stream);
static void switch_command(string parameters, StreamOutput *stream );
static void mem_command(string parameters, StreamOutput *stream );