mirror of https://github.com/ARMmbed/mbed-os.git
Fixing PR comments
parent
abe2b00fac
commit
1466518644
|
@ -16,7 +16,7 @@ limitations under the License.
|
|||
"""
|
||||
This script is the host script for trng test sequence, it send the
|
||||
step signaling sequence and receive and transmit data to the device after
|
||||
reset if necesarry (default lading and storing while reseting the device
|
||||
reset if necesarry (default loading and storing mechanism while reseting the device
|
||||
is NVstore, in case NVstore isn't enabled we'll use current infrastructure,
|
||||
for more details see main.cpp file)
|
||||
"""
|
||||
|
|
|
@ -31,26 +31,26 @@ static base64_result_e Base64CharToInt(char base64, uint8_t *intVal)
|
|||
return BASE64_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
if ((base64 >= 'A') && (base64 <= 'Z'))
|
||||
{ *intVal = base64 - 'A' ; }
|
||||
else if ((base64 >= 'a') && (base64 <= 'z'))
|
||||
{ *intVal = base64 - 'a' + 26; }
|
||||
else if ((base64 >= '0') && (base64 <= '9'))
|
||||
{ *intVal = base64 - '0' + 52; }
|
||||
else if (base64 == '+')
|
||||
{ *intVal = 62; }
|
||||
else if (base64 == '/')
|
||||
{ *intVal = 63; }
|
||||
else if (base64 == '=')
|
||||
{ *intVal = BASE_64_PAD; }
|
||||
else {
|
||||
if ((base64 >= 'A') && (base64 <= 'Z')) {
|
||||
*intVal = base64 - 'A' ;
|
||||
} else if ((base64 >= 'a') && (base64 <= 'z')) {
|
||||
*intVal = base64 - 'a' + 26;
|
||||
} else if ((base64 >= '0') && (base64 <= '9')) {
|
||||
*intVal = base64 - '0' + 52;
|
||||
} else if (base64 == '+') {
|
||||
*intVal = 62;
|
||||
} else if (base64 == '/') {
|
||||
*intVal = 63;
|
||||
} else if (base64 == '=') {
|
||||
*intVal = BASE_64_PAD;
|
||||
} else {
|
||||
return BASE64_ERROR;
|
||||
}
|
||||
|
||||
return BASE64_SUCCESS;
|
||||
}
|
||||
|
||||
base64_result_e esfs_DecodeNBase64(const char *string,
|
||||
base64_result_e trng_DecodeNBase64(const char *string,
|
||||
uint32_t stringMaxSize,
|
||||
void *buffer,
|
||||
uint32_t bufferSize,
|
||||
|
@ -72,18 +72,20 @@ base64_result_e esfs_DecodeNBase64(const char *string,
|
|||
}
|
||||
|
||||
*writePtr = 0;
|
||||
while (( string[currPos] != 0 ) &&
|
||||
( currPos < stringMaxSize ) &&
|
||||
while (( currPos < stringMaxSize ) &&
|
||||
( string[currPos] != 0 ) &&
|
||||
( writePtr < bufferEnd ) &&
|
||||
( !isEndOfString )) {
|
||||
uint8_t val;
|
||||
|
||||
if (string[currPos] == 0 || currPos >= stringMaxSize)
|
||||
{ break; }
|
||||
if (string[currPos] == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
result = Base64CharToInt(string[currPos++], &val);
|
||||
if (result != BASE64_SUCCESS)
|
||||
{ break; }
|
||||
if (result != BASE64_SUCCESS) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (val != BASE_64_PAD) {
|
||||
if (bitOffset <= 2) {
|
||||
|
@ -98,10 +100,11 @@ base64_result_e esfs_DecodeNBase64(const char *string,
|
|||
}
|
||||
} else { // found BASE_64_PAD
|
||||
// At most two pad characters may occur at the end of the encoded stream
|
||||
if (bitOffset == 2)
|
||||
{ isEndOfString = true; } // The last padding byte has been processed.
|
||||
else if (bitOffset != 4)
|
||||
{ return BASE64_ERROR; } // Incorrect padding
|
||||
if (bitOffset == 2) {
|
||||
isEndOfString = true; // The last padding byte has been processed.
|
||||
} else if (bitOffset != 4) {
|
||||
return BASE64_ERROR; // Incorrect padding
|
||||
}
|
||||
}
|
||||
|
||||
bitOffset = (bitOffset + 6) & 0x7;
|
||||
|
@ -110,30 +113,34 @@ base64_result_e esfs_DecodeNBase64(const char *string,
|
|||
localCharsProcessed = currPos;
|
||||
}
|
||||
}
|
||||
if (charsProcessed == NULL)
|
||||
{ localBytesWritten = (uint32_t)(writePtr - (uint8_t *)buffer); }
|
||||
else
|
||||
{ *charsProcessed = localCharsProcessed; }
|
||||
if (lengthWritten != NULL)
|
||||
{ *lengthWritten = localBytesWritten; }
|
||||
else if (bufferSize != localBytesWritten)
|
||||
{ return BASE64_BUFFER_TOO_SMALL; }
|
||||
if (charsProcessed == NULL) {
|
||||
localBytesWritten = (uint32_t)(writePtr - (uint8_t *)buffer);
|
||||
} else {
|
||||
*charsProcessed = localCharsProcessed;
|
||||
}
|
||||
if (lengthWritten != NULL) {
|
||||
*lengthWritten = localBytesWritten;
|
||||
} else if (bufferSize != localBytesWritten) {
|
||||
return BASE64_BUFFER_TOO_SMALL;
|
||||
}
|
||||
|
||||
// Check if additional bytes should have been processed but buffer isn't sufficient.
|
||||
if (( result == BASE64_SUCCESS ) &&
|
||||
( !isEndOfString ) &&
|
||||
( string[currPos] != '=' ) &&
|
||||
( currPos < stringMaxSize ) &&
|
||||
( string[currPos] != 0 ) &&
|
||||
( currPos < stringMaxSize) )
|
||||
{ return BASE64_BUFFER_TOO_SMALL; }
|
||||
( string[currPos] != '=' ) ) {
|
||||
return BASE64_BUFFER_TOO_SMALL;
|
||||
}
|
||||
|
||||
if (result != BASE64_SUCCESS)
|
||||
{ return result; }
|
||||
if (result != BASE64_SUCCESS) {
|
||||
return result;
|
||||
}
|
||||
|
||||
return BASE64_SUCCESS;
|
||||
}
|
||||
|
||||
base64_result_e esfs_EncodeBase64(const void *buffer, uint32_t bufferSize, char *string, uint32_t stringSize)
|
||||
base64_result_e trng_EncodeBase64(const void *buffer, uint32_t bufferSize, char *string, uint32_t stringSize)
|
||||
{
|
||||
uint32_t bitOffset = 0;
|
||||
|
||||
|
@ -143,8 +150,9 @@ base64_result_e esfs_EncodeBase64(const void *buffer, uint32_t bufferSize, char
|
|||
char *writePtr = string;
|
||||
char *stringEnd = string + stringSize - 1;
|
||||
|
||||
if ((NULL == string) || (NULL == buffer) || (stringSize == 0))
|
||||
{ return BASE64_INVALID_PARAMETER; }
|
||||
if ((NULL == string) || (NULL == buffer) || (stringSize == 0)) {
|
||||
return BASE64_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
stringSize--;
|
||||
while (readPtr < bufferEnd && writePtr < stringEnd) {
|
||||
|
@ -155,14 +163,16 @@ base64_result_e esfs_EncodeBase64(const void *buffer, uint32_t bufferSize, char
|
|||
break;
|
||||
case 6:
|
||||
tempVal = *readPtr++ << 4;
|
||||
if (readPtr < bufferEnd)
|
||||
{ tempVal |= *readPtr >> 4; }
|
||||
if (readPtr < bufferEnd) {
|
||||
tempVal |= *readPtr >> 4;
|
||||
}
|
||||
*writePtr++ = IntToBase64Char(tempVal);
|
||||
break;
|
||||
case 4:
|
||||
tempVal = *readPtr++ << 2;
|
||||
if (readPtr < bufferEnd)
|
||||
{ tempVal |= *readPtr >> 6; }
|
||||
if (readPtr < bufferEnd) {
|
||||
tempVal |= *readPtr >> 6;
|
||||
}
|
||||
*writePtr++ = IntToBase64Char(tempVal);
|
||||
break;
|
||||
case 2:
|
||||
|
@ -179,8 +189,9 @@ base64_result_e esfs_EncodeBase64(const void *buffer, uint32_t bufferSize, char
|
|||
}
|
||||
*writePtr = 0;
|
||||
|
||||
if ((readPtr < bufferEnd) || (bitOffset != 0))
|
||||
{ return (BASE64_BUFFER_TOO_SMALL); }
|
||||
if ((readPtr < bufferEnd) || (bitOffset != 0)) {
|
||||
return (BASE64_BUFFER_TOO_SMALL);
|
||||
}
|
||||
|
||||
return (BASE64_SUCCESS);
|
||||
}
|
||||
|
|
|
@ -25,8 +25,8 @@ typedef enum {
|
|||
BASE64_ERROR = 3,
|
||||
} base64_result_e;
|
||||
|
||||
base64_result_e esfs_EncodeBase64(const void *buffer, uint32_t bufferSize, char *string, uint32_t stringSize);
|
||||
base64_result_e esfs_DecodeNBase64(const char *string, uint32_t stringMaxSize, void *buffer, uint32_t bufferSize,
|
||||
base64_result_e trng_EncodeBase64(const void *buffer, uint32_t bufferSize, char *string, uint32_t stringSize);
|
||||
base64_result_e trng_DecodeNBase64(const char *string, uint32_t stringMaxSize, void *buffer, uint32_t bufferSize,
|
||||
uint32_t *lengthWritten, uint32_t *charsProcessed);
|
||||
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
/*
|
||||
* The test is based on the assumption that trng will generate random data, random so
|
||||
* there will not be any similar patterns in it, that kind of data will be impossible to
|
||||
* compress, if compression will acuur the test will result in failure.
|
||||
* compress, if compression will occur the test will result in failure.
|
||||
*
|
||||
* The test is composed out of three parts:
|
||||
* 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)
|
|||
/*Using base64 to decode data sent from host*/
|
||||
uint32_t lengthWritten = 0;
|
||||
uint32_t charsProcessed = 0;
|
||||
result = esfs_DecodeNBase64((const char *)value, MSG_VALUE_LEN, buffer, BUFFER_LEN, &lengthWritten, &charsProcessed);
|
||||
result = trng_DecodeNBase64((const char *)value, MSG_VALUE_LEN, buffer, BUFFER_LEN, &lengthWritten, &charsProcessed);
|
||||
TEST_ASSERT_EQUAL(0, result);
|
||||
#endif
|
||||
memcpy(input_buf, buffer, BUFFER_LEN);
|
||||
|
@ -181,7 +181,7 @@ static void compress_and_compare(char *key, char *value)
|
|||
TEST_ASSERT_EQUAL(NVSTORE_SUCCESS, result);
|
||||
#else
|
||||
/*Using base64 to encode data sending from host*/
|
||||
result = esfs_EncodeBase64(buffer, BUFFER_LEN, (char *)out_comp_buf, sizeof(out_comp_buf));
|
||||
result = trng_EncodeBase64(buffer, BUFFER_LEN, (char *)out_comp_buf, sizeof(out_comp_buf));
|
||||
TEST_ASSERT_EQUAL(NVSTORE_SUCCESS, result);
|
||||
greentea_send_kv(MSG_TRNG_BUFFER, (const char *)out_comp_buf);
|
||||
#endif
|
||||
|
|
|
@ -128,7 +128,6 @@ PITHY_STATIC_INLINE char *pithy_EmitCopy(char *op, size_t offset, size_t l
|
|||
#else
|
||||
#define PITHY_32BIT_MOVE64
|
||||
PITHY_STATIC_INLINE uint64_t pithy_Load64(const void *p) { uint64_t t; memcpy(&t, p, sizeof(t)); return (t); }
|
||||
PITHY_STATIC_INLINE void pithy_Store64(void *p, uint64_t v) { memcpy(p, &v, sizeof(v)); }
|
||||
#endif
|
||||
|
||||
#else // not __arm__
|
||||
|
|
Loading…
Reference in New Issue