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
|
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
|
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,
|
is NVstore, in case NVstore isn't enabled we'll use current infrastructure,
|
||||||
for more details see main.cpp file)
|
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;
|
return BASE64_INVALID_PARAMETER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((base64 >= 'A') && (base64 <= 'Z'))
|
if ((base64 >= 'A') && (base64 <= 'Z')) {
|
||||||
{ *intVal = base64 - 'A' ; }
|
*intVal = base64 - 'A' ;
|
||||||
else if ((base64 >= 'a') && (base64 <= 'z'))
|
} else if ((base64 >= 'a') && (base64 <= 'z')) {
|
||||||
{ *intVal = base64 - 'a' + 26; }
|
*intVal = base64 - 'a' + 26;
|
||||||
else if ((base64 >= '0') && (base64 <= '9'))
|
} else if ((base64 >= '0') && (base64 <= '9')) {
|
||||||
{ *intVal = base64 - '0' + 52; }
|
*intVal = base64 - '0' + 52;
|
||||||
else if (base64 == '+')
|
} else if (base64 == '+') {
|
||||||
{ *intVal = 62; }
|
*intVal = 62;
|
||||||
else if (base64 == '/')
|
} else if (base64 == '/') {
|
||||||
{ *intVal = 63; }
|
*intVal = 63;
|
||||||
else if (base64 == '=')
|
} else if (base64 == '=') {
|
||||||
{ *intVal = BASE_64_PAD; }
|
*intVal = BASE_64_PAD;
|
||||||
else {
|
} else {
|
||||||
return BASE64_ERROR;
|
return BASE64_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
return BASE64_SUCCESS;
|
return BASE64_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
base64_result_e esfs_DecodeNBase64(const char *string,
|
base64_result_e trng_DecodeNBase64(const char *string,
|
||||||
uint32_t stringMaxSize,
|
uint32_t stringMaxSize,
|
||||||
void *buffer,
|
void *buffer,
|
||||||
uint32_t bufferSize,
|
uint32_t bufferSize,
|
||||||
|
@ -72,18 +72,20 @@ base64_result_e esfs_DecodeNBase64(const char *string,
|
||||||
}
|
}
|
||||||
|
|
||||||
*writePtr = 0;
|
*writePtr = 0;
|
||||||
while (( string[currPos] != 0 ) &&
|
while (( currPos < stringMaxSize ) &&
|
||||||
( currPos < stringMaxSize ) &&
|
( string[currPos] != 0 ) &&
|
||||||
( writePtr < bufferEnd ) &&
|
( writePtr < bufferEnd ) &&
|
||||||
( !isEndOfString )) {
|
( !isEndOfString )) {
|
||||||
uint8_t val;
|
uint8_t val;
|
||||||
|
|
||||||
if (string[currPos] == 0 || currPos >= stringMaxSize)
|
if (string[currPos] == 0) {
|
||||||
{ break; }
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
result = Base64CharToInt(string[currPos++], &val);
|
result = Base64CharToInt(string[currPos++], &val);
|
||||||
if (result != BASE64_SUCCESS)
|
if (result != BASE64_SUCCESS) {
|
||||||
{ break; }
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (val != BASE_64_PAD) {
|
if (val != BASE_64_PAD) {
|
||||||
if (bitOffset <= 2) {
|
if (bitOffset <= 2) {
|
||||||
|
@ -98,10 +100,11 @@ base64_result_e esfs_DecodeNBase64(const char *string,
|
||||||
}
|
}
|
||||||
} else { // found BASE_64_PAD
|
} else { // found BASE_64_PAD
|
||||||
// At most two pad characters may occur at the end of the encoded stream
|
// At most two pad characters may occur at the end of the encoded stream
|
||||||
if (bitOffset == 2)
|
if (bitOffset == 2) {
|
||||||
{ isEndOfString = true; } // The last padding byte has been processed.
|
isEndOfString = true; // The last padding byte has been processed.
|
||||||
else if (bitOffset != 4)
|
} else if (bitOffset != 4) {
|
||||||
{ return BASE64_ERROR; } // Incorrect padding
|
return BASE64_ERROR; // Incorrect padding
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bitOffset = (bitOffset + 6) & 0x7;
|
bitOffset = (bitOffset + 6) & 0x7;
|
||||||
|
@ -110,30 +113,34 @@ base64_result_e esfs_DecodeNBase64(const char *string,
|
||||||
localCharsProcessed = currPos;
|
localCharsProcessed = currPos;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (charsProcessed == NULL)
|
if (charsProcessed == NULL) {
|
||||||
{ localBytesWritten = (uint32_t)(writePtr - (uint8_t *)buffer); }
|
localBytesWritten = (uint32_t)(writePtr - (uint8_t *)buffer);
|
||||||
else
|
} else {
|
||||||
{ *charsProcessed = localCharsProcessed; }
|
*charsProcessed = localCharsProcessed;
|
||||||
if (lengthWritten != NULL)
|
}
|
||||||
{ *lengthWritten = localBytesWritten; }
|
if (lengthWritten != NULL) {
|
||||||
else if (bufferSize != localBytesWritten)
|
*lengthWritten = localBytesWritten;
|
||||||
{ return BASE64_BUFFER_TOO_SMALL; }
|
} else if (bufferSize != localBytesWritten) {
|
||||||
|
return BASE64_BUFFER_TOO_SMALL;
|
||||||
|
}
|
||||||
|
|
||||||
// Check if additional bytes should have been processed but buffer isn't sufficient.
|
// Check if additional bytes should have been processed but buffer isn't sufficient.
|
||||||
if (( result == BASE64_SUCCESS ) &&
|
if (( result == BASE64_SUCCESS ) &&
|
||||||
( !isEndOfString ) &&
|
( !isEndOfString ) &&
|
||||||
( string[currPos] != '=' ) &&
|
( currPos < stringMaxSize ) &&
|
||||||
( string[currPos] != 0 ) &&
|
( string[currPos] != 0 ) &&
|
||||||
( currPos < stringMaxSize) )
|
( string[currPos] != '=' ) ) {
|
||||||
{ return BASE64_BUFFER_TOO_SMALL; }
|
return BASE64_BUFFER_TOO_SMALL;
|
||||||
|
}
|
||||||
|
|
||||||
if (result != BASE64_SUCCESS)
|
if (result != BASE64_SUCCESS) {
|
||||||
{ return result; }
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
return BASE64_SUCCESS;
|
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;
|
uint32_t bitOffset = 0;
|
||||||
|
|
||||||
|
@ -143,8 +150,9 @@ base64_result_e esfs_EncodeBase64(const void *buffer, uint32_t bufferSize, char
|
||||||
char *writePtr = string;
|
char *writePtr = string;
|
||||||
char *stringEnd = string + stringSize - 1;
|
char *stringEnd = string + stringSize - 1;
|
||||||
|
|
||||||
if ((NULL == string) || (NULL == buffer) || (stringSize == 0))
|
if ((NULL == string) || (NULL == buffer) || (stringSize == 0)) {
|
||||||
{ return BASE64_INVALID_PARAMETER; }
|
return BASE64_INVALID_PARAMETER;
|
||||||
|
}
|
||||||
|
|
||||||
stringSize--;
|
stringSize--;
|
||||||
while (readPtr < bufferEnd && writePtr < stringEnd) {
|
while (readPtr < bufferEnd && writePtr < stringEnd) {
|
||||||
|
@ -155,14 +163,16 @@ base64_result_e esfs_EncodeBase64(const void *buffer, uint32_t bufferSize, char
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 6:
|
||||||
tempVal = *readPtr++ << 4;
|
tempVal = *readPtr++ << 4;
|
||||||
if (readPtr < bufferEnd)
|
if (readPtr < bufferEnd) {
|
||||||
{ tempVal |= *readPtr >> 4; }
|
tempVal |= *readPtr >> 4;
|
||||||
|
}
|
||||||
*writePtr++ = IntToBase64Char(tempVal);
|
*writePtr++ = IntToBase64Char(tempVal);
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
tempVal = *readPtr++ << 2;
|
tempVal = *readPtr++ << 2;
|
||||||
if (readPtr < bufferEnd)
|
if (readPtr < bufferEnd) {
|
||||||
{ tempVal |= *readPtr >> 6; }
|
tempVal |= *readPtr >> 6;
|
||||||
|
}
|
||||||
*writePtr++ = IntToBase64Char(tempVal);
|
*writePtr++ = IntToBase64Char(tempVal);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
|
@ -179,8 +189,9 @@ base64_result_e esfs_EncodeBase64(const void *buffer, uint32_t bufferSize, char
|
||||||
}
|
}
|
||||||
*writePtr = 0;
|
*writePtr = 0;
|
||||||
|
|
||||||
if ((readPtr < bufferEnd) || (bitOffset != 0))
|
if ((readPtr < bufferEnd) || (bitOffset != 0)) {
|
||||||
{ return (BASE64_BUFFER_TOO_SMALL); }
|
return (BASE64_BUFFER_TOO_SMALL);
|
||||||
|
}
|
||||||
|
|
||||||
return (BASE64_SUCCESS);
|
return (BASE64_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,8 +25,8 @@ typedef enum {
|
||||||
BASE64_ERROR = 3,
|
BASE64_ERROR = 3,
|
||||||
} base64_result_e;
|
} base64_result_e;
|
||||||
|
|
||||||
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);
|
||||||
base64_result_e esfs_DecodeNBase64(const char *string, uint32_t stringMaxSize, void *buffer, uint32_t bufferSize,
|
base64_result_e trng_DecodeNBase64(const char *string, uint32_t stringMaxSize, void *buffer, uint32_t bufferSize,
|
||||||
uint32_t *lengthWritten, uint32_t *charsProcessed);
|
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
|
* 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
|
* 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 test is composed out of three parts:
|
||||||
* the first, generate a trng buffer and try to compress it, at the end of first part
|
* 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*/
|
/*Using base64 to decode data sent from host*/
|
||||||
uint32_t lengthWritten = 0;
|
uint32_t lengthWritten = 0;
|
||||||
uint32_t charsProcessed = 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);
|
TEST_ASSERT_EQUAL(0, result);
|
||||||
#endif
|
#endif
|
||||||
memcpy(input_buf, buffer, BUFFER_LEN);
|
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);
|
TEST_ASSERT_EQUAL(NVSTORE_SUCCESS, result);
|
||||||
#else
|
#else
|
||||||
/*Using base64 to encode data sending from host*/
|
/*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);
|
TEST_ASSERT_EQUAL(NVSTORE_SUCCESS, result);
|
||||||
greentea_send_kv(MSG_TRNG_BUFFER, (const char *)out_comp_buf);
|
greentea_send_kv(MSG_TRNG_BUFFER, (const char *)out_comp_buf);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -128,7 +128,6 @@ PITHY_STATIC_INLINE char *pithy_EmitCopy(char *op, size_t offset, size_t l
|
||||||
#else
|
#else
|
||||||
#define PITHY_32BIT_MOVE64
|
#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 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
|
#endif
|
||||||
|
|
||||||
#else // not __arm__
|
#else // not __arm__
|
||||||
|
|
Loading…
Reference in New Issue