Skip to content

Md5 #1345

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 9, 2016
Merged

Md5 #1345

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion cores/esp8266/FS.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ class File : public Stream
int read() override;
int peek() override;
void flush() override;

size_t readBytes(char *buffer, size_t length) override {
return read((uint8_t*)buffer, length);
}
size_t read(uint8_t* buf, size_t size);
bool seek(uint32_t pos, SeekMode mode);
size_t position() const;
Expand Down
40 changes: 40 additions & 0 deletions cores/esp8266/MD5Builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,46 @@ void MD5Builder::addHexString(const char * data){
free(tmp);
}

bool MD5Builder::addStream(Stream & stream, const size_t total_len) {
const int buf_size = 512;
int bytesleft = total_len;
uint8_t * buf = (uint8_t*) malloc(buf_size);
if(buf) {
while((stream.available() > -1) && (bytesleft > 0)) {

// get available data size
int sizeAvailable = stream.available();
if(sizeAvailable) {
int readBytes = sizeAvailable;

// read only the asked bytes
if(readBytes > bytesleft) {
readBytes = bytesleft ;
}

// not read more the buffer can handle
if(readBytes > buf_size) {
readBytes = buf_size;
}

// read data
int bytesread = stream.readBytes(buf, readBytes);
bytesleft -= bytesread;
if(bytesread > 0) {
MD5Update(&_ctx, buf, bytesread);
}
}
// time for network streams
delay(0);
}
// not free null ptr
free(buf);
return (bytesleft == 0);
} else {
return false;
}
}

void MD5Builder::calculate(void){
MD5Final(_buf, &_ctx);
}
Expand Down
1 change: 1 addition & 0 deletions cores/esp8266/MD5Builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class MD5Builder {
void addHexString(const char * data);
void addHexString(char * data){ addHexString((const char*)data); }
void addHexString(String data){ addHexString(data.c_str()); }
bool addStream(Stream & stream, const size_t total_len);
void calculate(void);
void getBytes(uint8_t * output);
void getChars(char * output);
Expand Down
4 changes: 2 additions & 2 deletions cores/esp8266/Stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ class Stream: public Print {

float parseFloat(); // float version of parseInt

size_t readBytes(char *buffer, size_t length); // read chars from stream into buffer
size_t readBytes(uint8_t *buffer, size_t length) {
virtual size_t readBytes(char *buffer, size_t length); // read chars from stream into buffer
virtual size_t readBytes(uint8_t *buffer, size_t length) {
return readBytes((char *) buffer, length);
}
// terminates if length characters have been read or timeout (see setTimeout)
Expand Down