globalplatform
Data Structures | Functions
util.h File Reference
#include "globalplatform/types.h"
#include "globalplatform/library.h"
#include "globalplatform/error.h"
Include dependency graph for util.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  TLV
 
struct  GP_SIMPLE_TLV
 

Functions

OPGP_NO_API LONG read_TLV (const BYTE *buffer, DWORD length, TLV *tlv)
 Reads a TLV struct from the given buffer. More...
 
OPGP_NO_API LONG parse_simple_tlv (const BYTE *buffer, DWORD length, GP_SIMPLE_TLV *tlv)
 Reads a TLV view from the given buffer without copying the value.
 
OPGP_NO_API OPGP_ERROR_STATUS append_tlv (PBYTE buffer, DWORD bufferSize, PDWORD offset, USHORT tag, const BYTE *value, DWORD valueLength)
 Appends a TLV to the given buffer.
 
OPGP_NO_API DWORD convert_byte (BYTE b)
 Converts a ISO 7816-4 Le Byte into its value. More...
 
OPGP_NO_API DWORD get_short (PBYTE buf, DWORD offset)
 Returns an unsigned short int from the given position. More...
 
OPGP_NO_API DWORD get_int (PBYTE buf, DWORD offset)
 Returns an unsigned int from the given position. More...
 
DWORD get_number (PBYTE buf, DWORD offset, BYTE numLength)
 Returns an unsigned int from the given position by taking just numLength bytes starting at offset into account. More...
 
OPGP_NO_API LONG parse_apdu_case (PBYTE apduCommand, DWORD apduCommandLength, PBYTE caseAPDU, PDWORD lc, PDWORD le)
 Parse the APDU case.
 
OPGP_NO_API LONG write_TLV_length (PBYTE buffer, DWORD offset, DWORD lengthLeft, USHORT length)
 Writes a TLV length field following DER BER rules. More...
 
OPGP_NO_API LONG parse_OID_numeric_string (PBYTE oid, DWORD oidLength, char *out, DWORD outLength)
 Parses a DER encoded OID into a numeric string (e.g. "1.2.840.113549").
 

Detailed Description

This file contains all GlobalPlatform utility functionality.

Function Documentation

◆ convert_byte()

OPGP_NO_API DWORD convert_byte ( BYTE  b)

Converts a ISO 7816-4 Le Byte into its value.

Parameters
b[in] The Le BYTE.
Returns
Value of b.

◆ get_int()

OPGP_NO_API DWORD get_int ( PBYTE  buf,
DWORD  offset 
)

Returns an unsigned int from the given position.

Parameters
buf[in] The buffer.
offset[in] The offset in the buffer.
Returns
the unsigned int value.

◆ get_number()

DWORD get_number ( PBYTE  buf,
DWORD  offset,
BYTE  numLength 
)

Returns an unsigned int from the given position by taking just numLength bytes starting at offset into account.

Parameters
buf[in] The buffer.
offset[in] The offset in the buffer.
numLengthThe length of the number.
Returns
the unsigned int value.

◆ get_short()

OPGP_NO_API DWORD get_short ( PBYTE  buf,
DWORD  offset 
)

Returns an unsigned short int from the given position.

Parameters
buf[in] The buffer.
offset[in] The offset in the buffer.
Returns
the unsigned short int value.

◆ read_TLV()

OPGP_NO_API LONG read_TLV ( const BYTE buffer,
DWORD  length,
TLV tlv 
)

Reads a TLV struct from the given buffer.

The tag must be coded on at most two octet and the length must be < 65535.

Parameters
buffer[in] The buffer.
length[in] The length of the buffer.
*tlv[out] the returned TLV struct.
Returns
-1 in case of error, consumed length otherwise.

◆ write_TLV_length()

OPGP_NO_API LONG write_TLV_length ( PBYTE  buffer,
DWORD  offset,
DWORD  lengthLeft,
USHORT  length 
)

Writes a TLV length field following DER BER rules.

Writes a TLV length field following DER BER rules.

Parameters
buffer[out] The byte array to write to.
offset[in] The offset in the buffer.
lengthLeft[in] The length left in the buffer.
length[in] The length value to encode (0-65535).
Returns
Number of bytes written, or -1 if insufficient space.