Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/esp8266/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Links2004 committed Jan 9, 2016
2 parents a276e81 + 39f36d4 commit f8cf215
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 3 deletions.
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

0 comments on commit f8cf215

Please sign in to comment.