mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-20 05:13:46 -07:00
less inline calls
This commit is contained in:
parent
24a138eeb1
commit
0e84860c2f
4 changed files with 20 additions and 20 deletions
|
@ -232,21 +232,21 @@ static inline void put64(void *where, uint64_t v) {
|
||||||
memcpy(where, &v, sizeof(v));
|
memcpy(where, &v, sizeof(v));
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool would_overflow(CborEncoder *encoder, size_t len) {
|
static bool would_overflow(CborEncoder *encoder, size_t len) {
|
||||||
ptrdiff_t remaining = (ptrdiff_t)encoder->end;
|
ptrdiff_t remaining = (ptrdiff_t)encoder->end;
|
||||||
remaining -= remaining ? (ptrdiff_t)encoder->data.ptr : encoder->data.bytes_needed;
|
remaining -= remaining ? (ptrdiff_t)encoder->data.ptr : encoder->data.bytes_needed;
|
||||||
remaining -= (ptrdiff_t)len;
|
remaining -= (ptrdiff_t)len;
|
||||||
return unlikely(remaining < 0);
|
return unlikely(remaining < 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void advance_ptr(CborEncoder *encoder, size_t n) {
|
static void advance_ptr(CborEncoder *encoder, size_t n) {
|
||||||
if (encoder->end)
|
if (encoder->end)
|
||||||
encoder->data.ptr += n;
|
encoder->data.ptr += n;
|
||||||
else
|
else
|
||||||
encoder->data.bytes_needed += n;
|
encoder->data.bytes_needed += n;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline CborError append_to_buffer(CborEncoder *encoder, const void *data, size_t len) {
|
static CborError append_to_buffer(CborEncoder *encoder, const void *data, size_t len) {
|
||||||
if (would_overflow(encoder, len)) {
|
if (would_overflow(encoder, len)) {
|
||||||
if (encoder->end != NULL) {
|
if (encoder->end != NULL) {
|
||||||
len -= encoder->end - encoder->data.ptr;
|
len -= encoder->end - encoder->data.ptr;
|
||||||
|
@ -263,11 +263,11 @@ static inline CborError append_to_buffer(CborEncoder *encoder, const void *data,
|
||||||
return CborNoError;
|
return CborNoError;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline CborError append_byte_to_buffer(CborEncoder *encoder, uint8_t byte) {
|
static CborError append_byte_to_buffer(CborEncoder *encoder, uint8_t byte) {
|
||||||
return append_to_buffer(encoder, &byte, 1);
|
return append_to_buffer(encoder, &byte, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline CborError encode_number_no_update(CborEncoder *encoder, uint64_t ui, uint8_t shiftedMajorType) {
|
static CborError encode_number_no_update(CborEncoder *encoder, uint64_t ui, uint8_t shiftedMajorType) {
|
||||||
/* Little-endian would have been so much more convenient here:
|
/* Little-endian would have been so much more convenient here:
|
||||||
* We could just write at the beginning of buf but append_to_buffer
|
* We could just write at the beginning of buf but append_to_buffer
|
||||||
* only the necessary bytes.
|
* only the necessary bytes.
|
||||||
|
|
|
@ -142,19 +142,19 @@
|
||||||
* \endif
|
* \endif
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static inline uint16_t get16(const uint8_t *ptr) {
|
static uint16_t get16(const uint8_t *ptr) {
|
||||||
uint16_t result;
|
uint16_t result;
|
||||||
memcpy(&result, ptr, sizeof(result));
|
memcpy(&result, ptr, sizeof(result));
|
||||||
return cbor_ntohs(result);
|
return cbor_ntohs(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline uint32_t get32(const uint8_t *ptr) {
|
static uint32_t get32(const uint8_t *ptr) {
|
||||||
uint32_t result;
|
uint32_t result;
|
||||||
memcpy(&result, ptr, sizeof(result));
|
memcpy(&result, ptr, sizeof(result));
|
||||||
return cbor_ntohl(result);
|
return cbor_ntohl(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline uint64_t get64(const uint8_t *ptr) {
|
static uint64_t get64(const uint8_t *ptr) {
|
||||||
uint64_t result;
|
uint64_t result;
|
||||||
memcpy(&result, ptr, sizeof(result));
|
memcpy(&result, ptr, sizeof(result));
|
||||||
return cbor_ntohll(result);
|
return cbor_ntohll(result);
|
||||||
|
@ -949,7 +949,7 @@ CborError cbor_value_calculate_string_length(const CborValue *value, size_t *len
|
||||||
return _cbor_value_copy_string(value, NULL, len, NULL);
|
return _cbor_value_copy_string(value, NULL, len, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void prepare_string_iteration(CborValue *it) {
|
static void prepare_string_iteration(CborValue *it) {
|
||||||
if (!cbor_value_is_length_known(it)) {
|
if (!cbor_value_is_length_known(it)) {
|
||||||
/* chunked string: we're before the first chunk;
|
/* chunked string: we're before the first chunk;
|
||||||
* advance to the first chunk */
|
* advance to the first chunk */
|
||||||
|
|
|
@ -342,7 +342,7 @@ static void asn1_tag_dump_object_id(const struct tlv *tlv, const struct asn1_tag
|
||||||
if (jsondesc) {
|
if (jsondesc) {
|
||||||
PrintAndLogEx(NORMAL, " - %s" NOLF, jsondesc);
|
PrintAndLogEx(NORMAL, " - %s" NOLF, jsondesc);
|
||||||
} else {
|
} else {
|
||||||
const char *ppstr;
|
const char *ppstr = NULL;
|
||||||
mbedtls_oid_get_attr_short_name(&asn1_buf, &ppstr);
|
mbedtls_oid_get_attr_short_name(&asn1_buf, &ppstr);
|
||||||
if (ppstr && strnlen(ppstr, 1)) {
|
if (ppstr && strnlen(ppstr, 1)) {
|
||||||
PrintAndLogEx(NORMAL, " (%s)", ppstr);
|
PrintAndLogEx(NORMAL, " (%s)", ppstr);
|
||||||
|
|
|
@ -160,32 +160,32 @@ uint64_t bytes_to_num(uint8_t *src, size_t len) {
|
||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline uint16_t MemLeToUint2byte(const uint8_t *data) {
|
uint16_t MemLeToUint2byte(const uint8_t *data) {
|
||||||
return (uint16_t)(
|
return (uint16_t)((uint16_t)
|
||||||
(data[1] << 8) + data[0]
|
(data[1] << 8) + data[0]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline uint32_t MemLeToUint3byte(const uint8_t *data) {
|
uint32_t MemLeToUint3byte(const uint8_t *data) {
|
||||||
return (uint32_t)(
|
return (uint32_t)((uint32_t)
|
||||||
(data[2] << 16) + (data[1] << 8) + data[0]
|
(data[2] << 16) + (data[1] << 8) + data[0]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline uint32_t MemLeToUint4byte(const uint8_t *data) {
|
uint32_t MemLeToUint4byte(const uint8_t *data) {
|
||||||
return (uint32_t)(
|
return (uint32_t)((uint32_t)
|
||||||
(data[3] << 24) + (data[2] << 16) + (data[1] << 8) + data[0]
|
(data[3] << 24) + (data[2] << 16) + (data[1] << 8) + data[0]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline uint16_t MemBeToUint2byte(const uint8_t *data) {
|
uint16_t MemBeToUint2byte(const uint8_t *data) {
|
||||||
return (uint16_t)(
|
return (uint16_t)((uint16_t)
|
||||||
(data[0] << 8) + data[1]
|
(data[0] << 8) + data[1]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline uint32_t MemBeToUint3byte(const uint8_t *data) {
|
uint32_t MemBeToUint3byte(const uint8_t *data) {
|
||||||
return (uint32_t)(
|
return (uint32_t)((uint32_t)
|
||||||
(data[0] << 16) + (data[1] << 8) + data[2]
|
(data[0] << 16) + (data[1] << 8) + data[2]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue