@@ -24,43 +24,42 @@ void MD5Builder::addHexString(const char * data){
24
24
}
25
25
26
26
bool MD5Builder::addStream (Stream & stream, const size_t total_len) {
27
- const int buf_size = 512 ;
28
- int bytesleft = total_len;
29
- uint8_t * buf = (uint8_t *) malloc (buf_size);
30
- if (buf) {
31
- while ((stream.available () > -1 ) && (bytesleft > 0 )) {
27
+ const int buf_size = 512 ;
28
+ int bytesleft = total_len;
29
+ uint8_t * buf = (uint8_t *) malloc (buf_size);
30
+ if (buf) {
31
+ while ((stream.available () > -1 ) && (bytesleft > 0 )) {
32
+ // get available data size
33
+ int sizeAvailable = stream.available ();
34
+ if (sizeAvailable) {
35
+ int readBytes = sizeAvailable;
32
36
33
- // get available data size
34
- int sizeAvailable = stream.available ();
35
- if (sizeAvailable) {
36
- int readBytes = sizeAvailable;
37
-
38
- // read only the asked bytes
39
- if (readBytes > bytesleft) {
40
- readBytes = bytesleft ;
41
- }
37
+ // read only the asked bytes
38
+ if (readBytes > bytesleft) {
39
+ readBytes = bytesleft ;
40
+ }
42
41
43
- // not read more the buffer can handle
44
- if (readBytes > buf_size) {
45
- readBytes = buf_size;
46
- }
42
+ // not read more the buffer can handle
43
+ if (readBytes > buf_size) {
44
+ readBytes = buf_size;
45
+ }
47
46
48
- // read data
49
- int bytesread = stream.readBytes (buf, readBytes);
50
- bytesleft -= bytesread;
51
- if (bytesread > 0 ) {
52
- MD5Update (&_ctx, buf, bytesread);
53
- }
54
- }
55
- // time for network streams
56
- delay (0 );
47
+ // read data
48
+ int bytesread = stream.readBytes (buf, readBytes);
49
+ bytesleft -= bytesread;
50
+ if (bytesread > 0 ) {
51
+ MD5Update (&_ctx, buf, bytesread);
57
52
}
58
- // not free null ptr
59
- free (buf);
60
- return (bytesleft == 0 );
61
- } else {
62
- return false ;
53
+ }
54
+ // time for network streams
55
+ delay (0 );
63
56
}
57
+ // guaranteed not null
58
+ free (buf);
59
+ return (bytesleft == 0 );
60
+ } else {
61
+ return false ;
62
+ }
64
63
}
65
64
66
65
void MD5Builder::calculate (void ){
@@ -77,7 +76,7 @@ void MD5Builder::getChars(char * output){
77
76
}
78
77
79
78
String MD5Builder::toString (void ){
80
- char out[32 ];
79
+ char out[33 ];
81
80
getChars (out);
82
81
return String (out);
83
82
}
0 commit comments