Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 28 additions & 6 deletions src/BER.h
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,16 @@ class BER: public Base {
uint8_t* encodeNumeric(T value, uint8_t *buffer) {
uint8_t *pointer = BER::encode(buffer);
for (uint8_t index = 0; index < _length; ++index) {
#if ARDUINO_ARCH_ESP32
uint8_t shift = _length - index - 1;
if (shift == sizeof(T)) {
*pointer++ = 0;
} else {
*pointer++ = value >> (shift << 3);
}
#else
*pointer++ = value >> ((_length - index - 1) << 3);
#endif
}
return pointer;
}
Expand Down Expand Up @@ -1482,6 +1491,7 @@ class NullBER: public BER {
*
* | Object Identifier | Encoding |
* |:-----------------------------|:---------------------------------------------|
* | 1 | 06 01 01 |
* | 1.3.6.1.2.1.2.2.1.8.4096 | 06 0B 2B 06 01 02 01 02 02 01 08 A0 00 |
* | 1.3.6.1.4.1.54858.81.1.1.1.0 | 06 0D 2B 06 01 04 01 83 AC 4A 51 01 01 01 00 |
*/
Expand Down Expand Up @@ -1517,12 +1527,18 @@ class ObjectIdentifierBER: public BER {
BER::encode(stream);
char *token = const_cast<char*>(_value.c_str());
while (token != NULL) {
char *next = strchr(token + 1, '.');
switch (index) {
case 0:
subidentifier = atoi(token);
break;
if (next) {
break;
}
// No break
case 1:
subidentifier = subidentifier * 40 + atoi(++token);
if (index) {
subidentifier = subidentifier * 40 + atoi(++token);
}
stream.write(subidentifier);
_size++;
break;
Expand All @@ -1540,7 +1556,7 @@ class ObjectIdentifierBER: public BER {
}
break;
}
token = strchr(token, '.');
token = next;
index++;
}
}
Expand Down Expand Up @@ -1594,12 +1610,18 @@ class ObjectIdentifierBER: public BER {
uint8_t *pointer = BER::encode(buffer);
char *token = const_cast<char*>(_value.c_str());
while (token != NULL) {
char *next = strchr(token + 1, '.');
switch (index) {
case 0:
subidentifier = atoi(token);
break;
if (next) {
break;
}
// No break
case 1:
if (index) {
subidentifier = subidentifier * 40 + atoi(++token);
}
*pointer = subidentifier;
break;
;
Expand All @@ -1616,7 +1638,7 @@ class ObjectIdentifierBER: public BER {
}
break;
}
token = strchr(token, '.');
token = next;
index++;
}
return ++pointer;
Expand Down Expand Up @@ -1679,10 +1701,10 @@ class ObjectIdentifierBER: public BER {
switch (index) {
case 0:
subidentifier = atoi(token);
_length++;
break;
case 1:
subidentifier = subidentifier * 40 + atoi(++token);
_length++;
break;
default: {
subidentifier = atol(++token);
Expand Down