2
0

Some type fixes.

This commit is contained in:
Maarten Billemont 2017-08-10 21:29:59 -04:00
parent 2033ebdc72
commit b374d9e04a
6 changed files with 25 additions and 25 deletions

View File

@ -57,7 +57,7 @@
#include "base64.h"
/* aaaack but it's fast and const should make it shared text page. */
static const unsigned char b64ToBits[256] =
static const uint8_t b64ToBits[256] =
{
/* ASCII table */
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
@ -97,20 +97,20 @@ int mpw_base64_decode(uint8_t *plainBuf, const char *b64Text) {
b64Cursor = (uint8_t *)b64Text;
register uint8_t *plainCursor = plainBuf;
while (b64Remaining > 4) {
*(plainCursor++) = (b64ToBits[b64Cursor[0]] << 2 | b64ToBits[b64Cursor[1]] >> 4);
*(plainCursor++) = (b64ToBits[b64Cursor[1]] << 4 | b64ToBits[b64Cursor[2]] >> 2);
*(plainCursor++) = (b64ToBits[b64Cursor[2]] << 6 | b64ToBits[b64Cursor[3]]);
*(plainCursor++) = (uint8_t)(b64ToBits[b64Cursor[0]] << 2 | b64ToBits[b64Cursor[1]] >> 4);
*(plainCursor++) = (uint8_t)(b64ToBits[b64Cursor[1]] << 4 | b64ToBits[b64Cursor[2]] >> 2);
*(plainCursor++) = (uint8_t)(b64ToBits[b64Cursor[2]] << 6 | b64ToBits[b64Cursor[3]]);
b64Cursor += 4;
b64Remaining -= 4;
}
/* Note: (b64Size == 1) would be an error, so just ingore that case */
if (b64Remaining > 1)
*(plainCursor++) = (b64ToBits[b64Cursor[0]] << 2 | b64ToBits[b64Cursor[1]] >> 4);
*(plainCursor++) = (uint8_t)(b64ToBits[b64Cursor[0]] << 2 | b64ToBits[b64Cursor[1]] >> 4);
if (b64Remaining > 2)
*(plainCursor++) = (b64ToBits[b64Cursor[1]] << 4 | b64ToBits[b64Cursor[2]] >> 2);
*(plainCursor++) = (uint8_t)(b64ToBits[b64Cursor[1]] << 4 | b64ToBits[b64Cursor[2]] >> 2);
if (b64Remaining > 3)
*(plainCursor++) = (b64ToBits[b64Cursor[2]] << 6 | b64ToBits[b64Cursor[3]]);
*(plainCursor++) = (uint8_t)(b64ToBits[b64Cursor[2]] << 6 | b64ToBits[b64Cursor[3]]);
return (int)(plainCursor - plainBuf);
}
@ -126,7 +126,7 @@ size_t mpw_base64_encode_max(size_t plainSize) {
int mpw_base64_encode(char *b64Text, const uint8_t *plainBuf, size_t plainSize) {
int plainCursor = 0;
size_t plainCursor = 0;
char *b64Cursor = b64Text;
for (; plainCursor < plainSize - 2; plainCursor += 3) {
*b64Cursor++ = basis_64[((plainBuf[plainCursor] >> 2)) & 0x3F];

View File

@ -76,14 +76,14 @@ const char *mpw_get_json_string(
return json_object_get_string( json_value );
}
int32_t mpw_get_json_int(
json_object *obj, const char *section, int32_t defaultValue) {
int64_t mpw_get_json_int(
json_object *obj, const char *section, int64_t defaultValue) {
json_object *json_value = mpw_get_json_section( obj, section );
if (!json_value)
return defaultValue;
return json_object_get_int( json_value );
return json_object_get_int64( json_value );
}
bool mpw_get_json_boolean(

View File

@ -50,8 +50,8 @@ const char *mpw_get_json_string(
/** Search for an integer in a JSON object tree.
* @param section A dot-delimited list of JSON object keys to walk toward the child object.
* @return The integer value or defaultValue if one of the section's object keys was not found in the source object's tree. */
int32_t mpw_get_json_int(
json_object *obj, const char *section, int32_t defaultValue);
int64_t mpw_get_json_int(
json_object *obj, const char *section, int64_t defaultValue);
/** Search for a boolean in a JSON object tree.
* @param section A dot-delimited list of JSON object keys to walk toward the child object.
* @return The boolean value or defaultValue if one of the section's object keys was not found in the source object's tree. */

View File

@ -187,7 +187,7 @@ static bool mpw_marshall_write_flat(
}
mpw_free( masterKey, MPMasterKeySize );
*error = (MPMarshallError){ MPMarshallSuccess };
*error = (MPMarshallError){ .type = MPMarshallSuccess };
return true;
}
@ -305,7 +305,7 @@ static bool mpw_marshall_write_json(
mpw_free( masterKey, MPMasterKeySize );
json_object_put( json_file );
*error = (MPMarshallError){ MPMarshallSuccess };
*error = (MPMarshallError){ .type = MPMarshallSuccess };
return true;
}
@ -537,14 +537,14 @@ static MPMarshalledUser *mpw_marshall_read_flat(
mpw_free_string( keyID );
mpw_free( masterKey, MPMasterKeySize );
*error = (MPMarshallError){ MPMarshallSuccess };
*error = (MPMarshallError){ .type = MPMarshallSuccess };
return user;
}
static MPMarshalledUser *mpw_marshall_read_json(
char *in, const char *masterPassword, MPMarshallError *error) {
*error = (MPMarshallError){ MPMarshallErrorInternal };
*error = (MPMarshallError){ MPMarshallErrorInternal, "Unexpected internal error." };
// Parse JSON.
enum json_tokener_error json_error = json_tokener_success;
@ -560,7 +560,7 @@ static MPMarshalledUser *mpw_marshall_read_json(
MPMarshalledUser *user = NULL;
// Section: "export"
unsigned int fileFormat = (unsigned int)mpw_get_json_int( json_file, "export.format", 0 );
int64_t fileFormat = mpw_get_json_int( json_file, "export.format", 0 );
if (fileFormat < 1) {
*error = (MPMarshallError){ MPMarshallErrorFormat, mpw_str( "Unsupported format: %u", fileFormat ) };
return NULL;
@ -572,7 +572,7 @@ static MPMarshalledUser *mpw_marshall_read_json(
const char *fullName = mpw_get_json_string( json_file, "user.full_name", NULL );
const char *str_lastUsed = mpw_get_json_string( json_file, "user.last_used", NULL );
const char *keyID = mpw_get_json_string( json_file, "user.key_id", NULL );
int32_t value = mpw_get_json_int( json_file, "user.algorithm", MPAlgorithmVersionCurrent );
int64_t value = mpw_get_json_int( json_file, "user.algorithm", MPAlgorithmVersionCurrent );
if (value < MPAlgorithmVersionFirst || value > MPAlgorithmVersionLast) {
*error = (MPMarshallError){ MPMarshallErrorIllegal, mpw_str( "Invalid user algorithm version: %u", value ) };
return NULL;
@ -614,13 +614,13 @@ static MPMarshalledUser *mpw_marshall_read_json(
json_object *json_sites = mpw_get_json_section( json_file, "sites" );
json_object_object_foreachC( json_sites, json_site ) {
const char *siteName = json_site.key;
value = mpw_get_json_int( json_site.val, "algorithm", user->algorithm );
value = mpw_get_json_int( json_site.val, "algorithm", (int32_t)user->algorithm );
if (value < MPAlgorithmVersionFirst || value > MPAlgorithmVersionLast) {
*error = (MPMarshallError){ MPMarshallErrorIllegal, mpw_str( "Invalid site algorithm version: %s: %d", siteName, value ) };
return NULL;
}
MPAlgorithmVersion siteAlgorithm = (MPAlgorithmVersion)value;
MPResultType siteType = (MPResultType)mpw_get_json_int( json_site.val, "type", user->defaultType );
MPResultType siteType = (MPResultType)mpw_get_json_int( json_site.val, "type", (int32_t)user->defaultType );
if (!mpw_nameForType( siteType )) {
*error = (MPMarshallError){ MPMarshallErrorIllegal, mpw_str( "Invalid site type: %s: %u", siteName, siteType ) };
return NULL;
@ -679,7 +679,7 @@ static MPMarshalledUser *mpw_marshall_read_json(
}
json_object_put( json_file );
*error = (MPMarshallError){ MPMarshallSuccess };
*error = (MPMarshallError){ .type = MPMarshallSuccess };
return user;
}

View File

@ -45,7 +45,7 @@ bool mpw_push_buf(uint8_t **const buffer, size_t *const bufferSize, const void *
if (!buffer || !bufferSize || !pushBuffer || !pushSize)
return false;
if (*bufferSize == ERR)
if (*bufferSize == (size_t)ERR)
// The buffer was marked as broken, it is missing a previous push. Abort to avoid corrupt content.
return false;

View File

@ -299,7 +299,7 @@ int main(int argc, char *const argv[]) {
fclose( sitesFile );
// Parse file.
MPMarshallError marshallError = { MPMarshallSuccess };
MPMarshallError marshallError = { .type = MPMarshallSuccess };
user = mpw_marshall_read( buf, sitesFormat, masterPassword, &marshallError );
if (marshallError.type == MPMarshallErrorMasterPassword) {
// Incorrect master password.
@ -550,7 +550,7 @@ int main(int argc, char *const argv[]) {
else {
char *buf = NULL;
MPMarshallError marshallError = { MPMarshallSuccess };
MPMarshallError marshallError = { .type = MPMarshallSuccess };
if (!mpw_marshall_write( &buf, sitesFormat, user, &marshallError ) || marshallError.type != MPMarshallSuccess)
wrn( "Couldn't encode updated configuration file:\n %s: %s\n", sitesPath, marshallError.description );