[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Apso-devel] Types (unsigned int/size_t, uint8_t/char)

From: Jeronimo Pellegrini
Subject: [Apso-devel] Types (unsigned int/size_t, uint8_t/char)
Date: Sat, 18 Nov 2006 06:49:43 -0200
User-agent: Mutt/1.5.13 (2006-08-11)

Hi guys.

Apso has one little portability problem today.

We have a mix of uint8_t/char and size_t/unsigned int
being used for arrays and their length.

Basically, we need to make sure that each element of the
arrays is 8 bits *exactly* (and not "at least"). This is
important, at least for Nettle, because its API deals with
uint8_t arrays.

But we also need char*, so we can build string objects.

Right now, if we compile Apso in some architecture where a char
has some different number of bits, we'll be asking for trouble.

The idea then would be to use uint8_t only.

So, we'd have to:

1) Rework the bdata class. 

One of two things would happen to it:

1.1) It could store things in one format (char, uint8_t, whatever),
    but have methods like:
    uint8_t * get_data_uint8()
    size_t    get_size_uint8()

    char    * get_data_char()
    size_t    get_size_char()

    For example, get_data_char() would cast the internal pointer to
    char. get_size_char() would do the math and adjust the reported
    size for char.
    If a char is 16 bits, then we'd have:
    uint8_t * data; // size == 10

    get_data_uint8() // return data;
    get_data_char()  // return (char*) data;

    get_size_uint8() // returns 10
    get_size_char()  // returns 5

    Some more work may be necessary, like adding a padding element,

1.2) It could be a template:
    bdata<uint8_t> mydata(mystring, size);

In the case we choose 1.2, we'd probably need conversion methods also,
so a bdata<uint8_t> could be converted into a bdata<char>.

We don't need all this for Apso immediately, but it would be nice to
have things clean and extensible if we ever want to use the class
anywhere else. :-)

2) Check every method that uses bdata, char* and uint8_t*. They should
   all use bdata only, *except*, of course, the cryptengine methods that
   need to pass uint8_t for the crypto library (we can't change that for
   Nettle, since it's a C program!)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]