Skip to content

Commit 4d1d1a0

Browse files
theamirocohenYossi Levy
authored andcommitted
Fix lisence and style
1 parent 669b618 commit 4d1d1a0

File tree

6 files changed

+302
-293
lines changed

6 files changed

+302
-293
lines changed
Lines changed: 77 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,166 +1,168 @@
1+
/*
2+
* Copyright (c) 2018 ARM Limited. All rights reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
* Licensed under the Apache License, Version 2.0 (the License); you may
5+
* not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
#include "base64b.h"
218

319
using namespace std;
420

521
static char IntToBase64Char(uint8_t intVal)
622
{
7-
const char* base64Digits = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
23+
const char *base64Digits = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
824
return base64Digits[intVal & 0x3F];
925
}
1026

1127
#define BASE_64_PAD 0xFF
12-
static base64_result_e Base64CharToInt(char base64, uint8_t* intVal)
28+
static base64_result_e Base64CharToInt(char base64, uint8_t *intVal)
1329
{
14-
if (NULL == intVal)
15-
{
30+
if (NULL == intVal) {
1631
return BASE64_INVALID_PARAMETER;
1732
}
1833

1934
if ((base64 >= 'A') && (base64 <= 'Z'))
20-
*intVal = base64 - 'A' ;
21-
else if((base64 >= 'a')&&(base64 <= 'z'))
22-
*intVal = base64 - 'a' + 26;
23-
else if ((base64 >= '0')&&(base64 <= '9'))
24-
*intVal = base64 - '0' + 52;
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; }
2540
else if (base64 == '+')
26-
*intVal = 62;
41+
{ *intVal = 62; }
2742
else if (base64 == '/')
28-
*intVal = 63;
43+
{ *intVal = 63; }
2944
else if (base64 == '=')
30-
*intVal = BASE_64_PAD;
31-
else
32-
{
45+
{ *intVal = BASE_64_PAD; }
46+
else {
3347
return BASE64_ERROR;
3448
}
35-
49+
3650
return BASE64_SUCCESS;
3751
}
3852

39-
base64_result_e esfs_DecodeNBase64(const char* string,
40-
uint32_t stringMaxSize,
41-
void* buffer,
42-
uint32_t bufferSize,
43-
uint32_t* lengthWritten,
44-
uint32_t* charsProcessed)
53+
base64_result_e esfs_DecodeNBase64(const char *string,
54+
uint32_t stringMaxSize,
55+
void *buffer,
56+
uint32_t bufferSize,
57+
uint32_t *lengthWritten,
58+
uint32_t *charsProcessed)
4559
{
4660
base64_result_e result = BASE64_SUCCESS;
47-
uint32_t bitOffset =0;
48-
uint8_t* writePtr = (uint8_t*)buffer;
49-
uint8_t* bufferEnd = (uint8_t*)buffer + bufferSize;
61+
uint32_t bitOffset = 0;
62+
uint8_t *writePtr = (uint8_t *)buffer;
63+
uint8_t *bufferEnd = (uint8_t *)buffer + bufferSize;
5064
uint8_t tempVal = 0;
5165
uint32_t currPos = 0;
5266
uint32_t localBytesWritten = 0;
5367
uint32_t localCharsProcessed = 0;
5468
bool isEndOfString = false;
5569

56-
if ((NULL == string) || (NULL == buffer) || (bufferSize == 0))
57-
{
70+
if ((NULL == string) || (NULL == buffer) || (bufferSize == 0)) {
5871
return BASE64_INVALID_PARAMETER;
5972
}
6073

6174
*writePtr = 0;
6275
while (( string[currPos] != 0 ) &&
6376
( currPos < stringMaxSize ) &&
6477
( writePtr < bufferEnd ) &&
65-
( !isEndOfString ))
66-
{
78+
( !isEndOfString )) {
6779
uint8_t val;
6880

6981
if (string[currPos] == 0 || currPos >= stringMaxSize)
70-
break;
71-
82+
{ break; }
83+
7284
result = Base64CharToInt(string[currPos++], &val);
7385
if (result != BASE64_SUCCESS)
74-
break;
86+
{ break; }
7587

76-
if (val != BASE_64_PAD)
77-
{
78-
if(bitOffset <= 2)
79-
{
88+
if (val != BASE_64_PAD) {
89+
if (bitOffset <= 2) {
8090
tempVal |= val << (2 - bitOffset);
81-
if (bitOffset == 2)
82-
{
91+
if (bitOffset == 2) {
8392
*writePtr++ = tempVal;
8493
tempVal = 0;
8594
}
86-
}
87-
else
88-
{
95+
} else {
8996
*writePtr++ = (uint8_t)(tempVal | (val >> (bitOffset - 2)));
9097
tempVal = (uint8_t)(val << (10 - bitOffset));
9198
}
92-
}
93-
else // found BASE_64_PAD
94-
{
99+
} else { // found BASE_64_PAD
95100
// At most two pad characters may occur at the end of the encoded stream
96101
if (bitOffset == 2)
97-
isEndOfString = true; // The last padding byte has been processed.
102+
{ isEndOfString = true; } // The last padding byte has been processed.
98103
else if (bitOffset != 4)
99-
return BASE64_ERROR; // Incorrect padding
104+
{ return BASE64_ERROR; } // Incorrect padding
100105
}
101-
106+
102107
bitOffset = (bitOffset + 6) & 0x7;
103-
if (bitOffset == 0)
104-
{
105-
localBytesWritten = (uint32_t)(writePtr - (uint8_t*)buffer);
108+
if (bitOffset == 0) {
109+
localBytesWritten = (uint32_t)(writePtr - (uint8_t *)buffer);
106110
localCharsProcessed = currPos;
107111
}
108112
}
109113
if (charsProcessed == NULL)
110-
localBytesWritten = (uint32_t)(writePtr - (uint8_t*)buffer);
111-
else
112-
*charsProcessed = localCharsProcessed;
114+
{ localBytesWritten = (uint32_t)(writePtr - (uint8_t *)buffer); }
115+
else
116+
{ *charsProcessed = localCharsProcessed; }
113117
if (lengthWritten != NULL)
114-
*lengthWritten = localBytesWritten;
118+
{ *lengthWritten = localBytesWritten; }
115119
else if (bufferSize != localBytesWritten)
116-
return BASE64_BUFFER_TOO_SMALL;
120+
{ return BASE64_BUFFER_TOO_SMALL; }
117121

118122
// Check if additional bytes should have been processed but buffer isn't sufficient.
119123
if (( result == BASE64_SUCCESS ) &&
120-
( !isEndOfString ) &&
121-
( string[currPos] != '=' ) &&
122-
( string[currPos] != 0 ) &&
123-
( currPos < stringMaxSize) )
124-
return BASE64_BUFFER_TOO_SMALL;
124+
( !isEndOfString ) &&
125+
( string[currPos] != '=' ) &&
126+
( string[currPos] != 0 ) &&
127+
( currPos < stringMaxSize) )
128+
{ return BASE64_BUFFER_TOO_SMALL; }
125129

126130
if (result != BASE64_SUCCESS)
127-
return result;
131+
{ return result; }
128132

129133
return BASE64_SUCCESS;
130134
}
131135

132-
base64_result_e esfs_EncodeBase64(const void* buffer, uint32_t bufferSize, char* string, uint32_t stringSize)
136+
base64_result_e esfs_EncodeBase64(const void *buffer, uint32_t bufferSize, char *string, uint32_t stringSize)
133137
{
134138
uint32_t bitOffset = 0;
135139

136-
const uint8_t* readPtr = (const uint8_t*)buffer;
137-
const uint8_t* bufferEnd = (const uint8_t*)buffer + bufferSize;
140+
const uint8_t *readPtr = (const uint8_t *)buffer;
141+
const uint8_t *bufferEnd = (const uint8_t *)buffer + bufferSize;
138142

139-
char* writePtr = string;
140-
char* stringEnd = string + stringSize - 1;
143+
char *writePtr = string;
144+
char *stringEnd = string + stringSize - 1;
141145

142146
if ((NULL == string) || (NULL == buffer) || (stringSize == 0))
143-
return BASE64_INVALID_PARAMETER;
147+
{ return BASE64_INVALID_PARAMETER; }
144148

145149
stringSize--;
146-
while(readPtr < bufferEnd && writePtr < stringEnd)
147-
{
150+
while (readPtr < bufferEnd && writePtr < stringEnd) {
148151
uint8_t tempVal = 0;
149-
switch (bitOffset)
150-
{
152+
switch (bitOffset) {
151153
case 0:
152154
*writePtr++ = IntToBase64Char(*readPtr >> 2); // take upper 6 bits
153155
break;
154156
case 6:
155157
tempVal = *readPtr++ << 4;
156158
if (readPtr < bufferEnd)
157-
tempVal |= *readPtr >> 4;
159+
{ tempVal |= *readPtr >> 4; }
158160
*writePtr++ = IntToBase64Char(tempVal);
159161
break;
160162
case 4:
161163
tempVal = *readPtr++ << 2;
162164
if (readPtr < bufferEnd)
163-
tempVal |= *readPtr >> 6;
165+
{ tempVal |= *readPtr >> 6; }
164166
*writePtr++ = IntToBase64Char(tempVal);
165167
break;
166168
case 2:
@@ -171,15 +173,14 @@ base64_result_e esfs_EncodeBase64(const void* buffer, uint32_t bufferSize, char*
171173
}
172174
bitOffset = (bitOffset + 6) & 0x7;
173175
}
174-
while (bitOffset > 0 && writePtr < stringEnd)
175-
{
176+
while (bitOffset > 0 && writePtr < stringEnd) {
176177
*writePtr++ = '=';
177178
bitOffset = (bitOffset + 6) & 0x7;
178179
}
179180
*writePtr = 0;
180181

181182
if ((readPtr < bufferEnd) || (bitOffset != 0))
182-
return (BASE64_BUFFER_TOO_SMALL);
183+
{ return (BASE64_BUFFER_TOO_SMALL); }
183184

184-
return(BASE64_SUCCESS);
185+
return (BASE64_SUCCESS);
185186
}

TESTS/mbed_hal/trng/base64b/base64b.h

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright (c) 2018 ARM Limited. All rights reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
* Licensed under the Apache License, Version 2.0 (the License); you may
5+
* not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
#include <stdint.h>
218
#include <stdlib.h>
319
#include <string>
@@ -7,10 +23,10 @@ typedef enum {
723
BASE64_INVALID_PARAMETER = 1,
824
BASE64_BUFFER_TOO_SMALL = 2,
925
BASE64_ERROR = 3,
10-
}base64_result_e;
26+
} base64_result_e;
1127

12-
base64_result_e esfs_EncodeBase64(const void* buffer, uint32_t bufferSize, char* string, uint32_t stringSize);
13-
base64_result_e esfs_DecodeNBase64(const char* string, uint32_t stringMaxSize, void* buffer, uint32_t bufferSize,
14-
uint32_t* lengthWritten, uint32_t* charsProcessed);
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,
30+
uint32_t *lengthWritten, uint32_t *charsProcessed);
1531

1632

TESTS/mbed_hal/trng/lzflib/lzf.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
/*
22
* Copyright (c) 2000-2008 Marc Alexander Lehmann <[email protected]>
3-
*
3+
*
44
* Redistribution and use in source and binary forms, with or without modifica-
55
* tion, are permitted provided that the following conditions are met:
6-
*
6+
*
77
* 1. Redistributions of source code must retain the above copyright notice,
88
* this list of conditions and the following disclaimer.
9-
*
9+
*
1010
* 2. Redistributions in binary form must reproduce the above copyright
1111
* notice, this list of conditions and the following disclaimer in the
1212
* documentation and/or other materials provided with the distribution.
13-
*
13+
*
1414
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
1515
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER-
1616
* CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
@@ -73,7 +73,7 @@
7373
* and lzf_c.c.
7474
*
7575
*/
76-
unsigned int
76+
unsigned int
7777
lzf_compress (const void *const in_data, unsigned int in_len,
7878
void *out_data, unsigned int out_len,
7979
unsigned char **htab);
@@ -93,7 +93,7 @@ lzf_compress (const void *const in_data, unsigned int in_len,
9393
*
9494
* This function is very fast, about as fast as a copying loop.
9595
*/
96-
unsigned int
96+
unsigned int
9797
lzf_decompress (const void *const in_data, unsigned int in_len,
9898
void *out_data, unsigned int out_len);
9999

TESTS/mbed_hal/trng/lzflib/lzfP.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
/*
22
* Copyright (c) 2000-2007 Marc Alexander Lehmann <[email protected]>
3-
*
3+
*
44
* Redistribution and use in source and binary forms, with or without modifica-
55
* tion, are permitted provided that the following conditions are met:
6-
*
6+
*
77
* 1. Redistributions of source code must retain the above copyright notice,
88
* this list of conditions and the following disclaimer.
9-
*
9+
*
1010
* 2. Redistributions in binary form must reproduce the above copyright
1111
* notice, this list of conditions and the following disclaimer in the
1212
* documentation and/or other materials provided with the distribution.
13-
*
13+
*
1414
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
1515
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER-
1616
* CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
@@ -157,20 +157,20 @@ typedef unsigned char u8;
157157

158158
#if LZF_USE_OFFSETS
159159
# define LZF_HSLOT_BIAS ((const u8 *)in_data)
160-
typedef unsigned int LZF_HSLOT;
160+
typedef unsigned int LZF_HSLOT;
161161
#else
162162
# define LZF_HSLOT_BIAS 0
163-
typedef const u8 *LZF_HSLOT;
163+
typedef const u8 *LZF_HSLOT;
164164
#endif
165165

166166
typedef LZF_HSLOT LZF_STATE[1 << (HLOG)];
167167

168168
#if !STRICT_ALIGN
169169
/* for unaligned accesses we need a 16 bit datatype. */
170170
# if USHRT_MAX == 65535
171-
typedef unsigned short u16;
171+
typedef unsigned short u16;
172172
# elif UINT_MAX == 65535
173-
typedef unsigned int u16;
173+
typedef unsigned int u16;
174174
# else
175175
# undef STRICT_ALIGN
176176
# define STRICT_ALIGN 1

0 commit comments

Comments
 (0)