Skip to content

Commit 1466518

Browse files
theamirocohenYossi Levy
authored andcommitted
Fixing PR comments
1 parent abe2b00 commit 1466518

File tree

5 files changed

+63
-53
lines changed

5 files changed

+63
-53
lines changed

TESTS/host_tests/trng_reset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"""
1717
This script is the host script for trng test sequence, it send the
1818
step signaling sequence and receive and transmit data to the device after
19-
reset if necesarry (default lading and storing while reseting the device
19+
reset if necesarry (default loading and storing mechanism while reseting the device
2020
is NVstore, in case NVstore isn't enabled we'll use current infrastructure,
2121
for more details see main.cpp file)
2222
"""

TESTS/mbed_hal/trng/base64b/base64b.cpp

Lines changed: 57 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,26 @@ static base64_result_e Base64CharToInt(char base64, uint8_t *intVal)
3131
return BASE64_INVALID_PARAMETER;
3232
}
3333

34-
if ((base64 >= 'A') && (base64 <= 'Z'))
35-
{ *intVal = base64 - 'A' ; }
36-
else if ((base64 >= 'a') && (base64 <= 'z'))
37-
{ *intVal = base64 - 'a' + 26; }
38-
else if ((base64 >= '0') && (base64 <= '9'))
39-
{ *intVal = base64 - '0' + 52; }
40-
else if (base64 == '+')
41-
{ *intVal = 62; }
42-
else if (base64 == '/')
43-
{ *intVal = 63; }
44-
else if (base64 == '=')
45-
{ *intVal = BASE_64_PAD; }
46-
else {
34+
if ((base64 >= 'A') && (base64 <= 'Z')) {
35+
*intVal = base64 - 'A' ;
36+
} else if ((base64 >= 'a') && (base64 <= 'z')) {
37+
*intVal = base64 - 'a' + 26;
38+
} else if ((base64 >= '0') && (base64 <= '9')) {
39+
*intVal = base64 - '0' + 52;
40+
} else if (base64 == '+') {
41+
*intVal = 62;
42+
} else if (base64 == '/') {
43+
*intVal = 63;
44+
} else if (base64 == '=') {
45+
*intVal = BASE_64_PAD;
46+
} else {
4747
return BASE64_ERROR;
4848
}
4949

5050
return BASE64_SUCCESS;
5151
}
5252

53-
base64_result_e esfs_DecodeNBase64(const char *string,
53+
base64_result_e trng_DecodeNBase64(const char *string,
5454
uint32_t stringMaxSize,
5555
void *buffer,
5656
uint32_t bufferSize,
@@ -72,18 +72,20 @@ base64_result_e esfs_DecodeNBase64(const char *string,
7272
}
7373

7474
*writePtr = 0;
75-
while (( string[currPos] != 0 ) &&
76-
( currPos < stringMaxSize ) &&
75+
while (( currPos < stringMaxSize ) &&
76+
( string[currPos] != 0 ) &&
7777
( writePtr < bufferEnd ) &&
7878
( !isEndOfString )) {
7979
uint8_t val;
8080

81-
if (string[currPos] == 0 || currPos >= stringMaxSize)
82-
{ break; }
81+
if (string[currPos] == 0) {
82+
break;
83+
}
8384

8485
result = Base64CharToInt(string[currPos++], &val);
85-
if (result != BASE64_SUCCESS)
86-
{ break; }
86+
if (result != BASE64_SUCCESS) {
87+
break;
88+
}
8789

8890
if (val != BASE_64_PAD) {
8991
if (bitOffset <= 2) {
@@ -98,10 +100,11 @@ base64_result_e esfs_DecodeNBase64(const char *string,
98100
}
99101
} else { // found BASE_64_PAD
100102
// At most two pad characters may occur at the end of the encoded stream
101-
if (bitOffset == 2)
102-
{ isEndOfString = true; } // The last padding byte has been processed.
103-
else if (bitOffset != 4)
104-
{ return BASE64_ERROR; } // Incorrect padding
103+
if (bitOffset == 2) {
104+
isEndOfString = true; // The last padding byte has been processed.
105+
} else if (bitOffset != 4) {
106+
return BASE64_ERROR; // Incorrect padding
107+
}
105108
}
106109

107110
bitOffset = (bitOffset + 6) & 0x7;
@@ -110,30 +113,34 @@ base64_result_e esfs_DecodeNBase64(const char *string,
110113
localCharsProcessed = currPos;
111114
}
112115
}
113-
if (charsProcessed == NULL)
114-
{ localBytesWritten = (uint32_t)(writePtr - (uint8_t *)buffer); }
115-
else
116-
{ *charsProcessed = localCharsProcessed; }
117-
if (lengthWritten != NULL)
118-
{ *lengthWritten = localBytesWritten; }
119-
else if (bufferSize != localBytesWritten)
120-
{ return BASE64_BUFFER_TOO_SMALL; }
116+
if (charsProcessed == NULL) {
117+
localBytesWritten = (uint32_t)(writePtr - (uint8_t *)buffer);
118+
} else {
119+
*charsProcessed = localCharsProcessed;
120+
}
121+
if (lengthWritten != NULL) {
122+
*lengthWritten = localBytesWritten;
123+
} else if (bufferSize != localBytesWritten) {
124+
return BASE64_BUFFER_TOO_SMALL;
125+
}
121126

122127
// Check if additional bytes should have been processed but buffer isn't sufficient.
123128
if (( result == BASE64_SUCCESS ) &&
124129
( !isEndOfString ) &&
125-
( string[currPos] != '=' ) &&
130+
( currPos < stringMaxSize ) &&
126131
( string[currPos] != 0 ) &&
127-
( currPos < stringMaxSize) )
128-
{ return BASE64_BUFFER_TOO_SMALL; }
132+
( string[currPos] != '=' ) ) {
133+
return BASE64_BUFFER_TOO_SMALL;
134+
}
129135

130-
if (result != BASE64_SUCCESS)
131-
{ return result; }
136+
if (result != BASE64_SUCCESS) {
137+
return result;
138+
}
132139

133140
return BASE64_SUCCESS;
134141
}
135142

136-
base64_result_e esfs_EncodeBase64(const void *buffer, uint32_t bufferSize, char *string, uint32_t stringSize)
143+
base64_result_e trng_EncodeBase64(const void *buffer, uint32_t bufferSize, char *string, uint32_t stringSize)
137144
{
138145
uint32_t bitOffset = 0;
139146

@@ -143,8 +150,9 @@ base64_result_e esfs_EncodeBase64(const void *buffer, uint32_t bufferSize, char
143150
char *writePtr = string;
144151
char *stringEnd = string + stringSize - 1;
145152

146-
if ((NULL == string) || (NULL == buffer) || (stringSize == 0))
147-
{ return BASE64_INVALID_PARAMETER; }
153+
if ((NULL == string) || (NULL == buffer) || (stringSize == 0)) {
154+
return BASE64_INVALID_PARAMETER;
155+
}
148156

149157
stringSize--;
150158
while (readPtr < bufferEnd && writePtr < stringEnd) {
@@ -155,14 +163,16 @@ base64_result_e esfs_EncodeBase64(const void *buffer, uint32_t bufferSize, char
155163
break;
156164
case 6:
157165
tempVal = *readPtr++ << 4;
158-
if (readPtr < bufferEnd)
159-
{ tempVal |= *readPtr >> 4; }
166+
if (readPtr < bufferEnd) {
167+
tempVal |= *readPtr >> 4;
168+
}
160169
*writePtr++ = IntToBase64Char(tempVal);
161170
break;
162171
case 4:
163172
tempVal = *readPtr++ << 2;
164-
if (readPtr < bufferEnd)
165-
{ tempVal |= *readPtr >> 6; }
173+
if (readPtr < bufferEnd) {
174+
tempVal |= *readPtr >> 6;
175+
}
166176
*writePtr++ = IntToBase64Char(tempVal);
167177
break;
168178
case 2:
@@ -179,8 +189,9 @@ base64_result_e esfs_EncodeBase64(const void *buffer, uint32_t bufferSize, char
179189
}
180190
*writePtr = 0;
181191

182-
if ((readPtr < bufferEnd) || (bitOffset != 0))
183-
{ return (BASE64_BUFFER_TOO_SMALL); }
192+
if ((readPtr < bufferEnd) || (bitOffset != 0)) {
193+
return (BASE64_BUFFER_TOO_SMALL);
194+
}
184195

185196
return (BASE64_SUCCESS);
186197
}

TESTS/mbed_hal/trng/base64b/base64b.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ typedef enum {
2525
BASE64_ERROR = 3,
2626
} base64_result_e;
2727

28-
base64_result_e esfs_EncodeBase64(const void *buffer, uint32_t bufferSize, char *string, uint32_t stringSize);
29-
base64_result_e esfs_DecodeNBase64(const char *string, uint32_t stringMaxSize, void *buffer, uint32_t bufferSize,
28+
base64_result_e trng_EncodeBase64(const void *buffer, uint32_t bufferSize, char *string, uint32_t stringSize);
29+
base64_result_e trng_DecodeNBase64(const char *string, uint32_t stringMaxSize, void *buffer, uint32_t bufferSize,
3030
uint32_t *lengthWritten, uint32_t *charsProcessed);
3131

3232

TESTS/mbed_hal/trng/main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
/*
1818
* The test is based on the assumption that trng will generate random data, random so
1919
* there will not be any similar patterns in it, that kind of data will be impossible to
20-
* compress, if compression will acuur the test will result in failure.
20+
* compress, if compression will occur the test will result in failure.
2121
*
2222
* The test is composed out of three parts:
2323
* the first, generate a trng buffer and try to compress it, at the end of first part
@@ -119,7 +119,7 @@ static void compress_and_compare(char *key, char *value)
119119
/*Using base64 to decode data sent from host*/
120120
uint32_t lengthWritten = 0;
121121
uint32_t charsProcessed = 0;
122-
result = esfs_DecodeNBase64((const char *)value, MSG_VALUE_LEN, buffer, BUFFER_LEN, &lengthWritten, &charsProcessed);
122+
result = trng_DecodeNBase64((const char *)value, MSG_VALUE_LEN, buffer, BUFFER_LEN, &lengthWritten, &charsProcessed);
123123
TEST_ASSERT_EQUAL(0, result);
124124
#endif
125125
memcpy(input_buf, buffer, BUFFER_LEN);
@@ -181,7 +181,7 @@ static void compress_and_compare(char *key, char *value)
181181
TEST_ASSERT_EQUAL(NVSTORE_SUCCESS, result);
182182
#else
183183
/*Using base64 to encode data sending from host*/
184-
result = esfs_EncodeBase64(buffer, BUFFER_LEN, (char *)out_comp_buf, sizeof(out_comp_buf));
184+
result = trng_EncodeBase64(buffer, BUFFER_LEN, (char *)out_comp_buf, sizeof(out_comp_buf));
185185
TEST_ASSERT_EQUAL(NVSTORE_SUCCESS, result);
186186
greentea_send_kv(MSG_TRNG_BUFFER, (const char *)out_comp_buf);
187187
#endif

TESTS/mbed_hal/trng/pithy/pithy.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ PITHY_STATIC_INLINE char *pithy_EmitCopy(char *op, size_t offset, size_t l
128128
#else
129129
#define PITHY_32BIT_MOVE64
130130
PITHY_STATIC_INLINE uint64_t pithy_Load64(const void *p) { uint64_t t; memcpy(&t, p, sizeof(t)); return (t); }
131-
PITHY_STATIC_INLINE void pithy_Store64(void *p, uint64_t v) { memcpy(p, &v, sizeof(v)); }
132131
#endif
133132

134133
#else // not __arm__

0 commit comments

Comments
 (0)