summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndres Morales <anmorales@google.com>2015-03-30 16:47:47 -0700
committerAndres Morales <anmorales@google.com>2015-03-30 17:05:46 -0700
commit11ed52a7139a6c867850113aa19293c05581fcfc (patch)
tree8557caaf71ce92c5bdb2ff541463add769d3f450
parent4a29dcb5222110a2ea09cb8b52167c91cf3ab3c5 (diff)
downloadgatekeeper-11ed52a7139a6c867850113aa19293c05581fcfc.tar.gz
Use uint32_t instead of size_t
Must be compatible with code running on arbitrary architectures. Change-Id: I7223f02792929422f21c52024efe073940248fca
-rw-r--r--gatekeeper.cpp12
-rw-r--r--gatekeeper_messages.cpp19
-rw-r--r--include/gatekeeper/gatekeeper.h22
-rw-r--r--include/gatekeeper/gatekeeper_messages.h20
-rw-r--r--include/gatekeeper/soft_gatekeeper.h24
-rw-r--r--softgatekeeper/native_gatekeeper_file_io.h4
-rw-r--r--softgatekeeper/soft_gatekeeper_device.cpp14
-rw-r--r--softgatekeeper/soft_gatekeeper_device.h14
-rw-r--r--tests/gatekeeper_device_test.cpp20
-rw-r--r--tests/gatekeeper_messages_test.cpp28
-rw-r--r--tests/gatekeeper_test.cpp4
11 files changed, 91 insertions, 90 deletions
diff --git a/gatekeeper.cpp b/gatekeeper.cpp
index 2e9391a..305ceff 100644
--- a/gatekeeper.cpp
+++ b/gatekeeper.cpp
@@ -115,7 +115,7 @@ void GateKeeper::Verify(const VerifyRequest &request, VerifyResponse *response)
bool GateKeeper::CreatePasswordHandle(SizedBuffer *password_handle_buffer, salt_t salt,
secure_id_t user_id, secure_id_t authenticator_id, const uint8_t *password,
- size_t password_length) {
+ uint32_t password_length) {
password_handle_buffer->buffer.reset(new uint8_t[sizeof(password_handle_t)]);
password_handle_buffer->length = sizeof(password_handle_t);
@@ -126,14 +126,14 @@ bool GateKeeper::CreatePasswordHandle(SizedBuffer *password_handle_buffer, salt_
password_handle->user_id = user_id;
password_handle->authenticator_id = authenticator_id;
- size_t metadata_length = sizeof(user_id) /* user id */
+ uint32_t metadata_length = sizeof(user_id) /* user id */
+ sizeof(authenticator_id) /* auth id */ + sizeof(uint8_t) /* version */;
uint8_t to_sign[password_length + metadata_length];
memcpy(to_sign, &password_handle->version, metadata_length);
memcpy(to_sign + metadata_length, password, password_length);
const uint8_t *password_key = NULL;
- size_t password_key_length = 0;
+ uint32_t password_key_length = 0;
GetPasswordKey(&password_key, &password_key_length);
if (!password_key || password_key_length == 0) {
@@ -169,7 +169,7 @@ bool GateKeeper::ValidatePasswordFile(uint32_t uid, const SizedBuffer &provided_
== 0;
}
-void GateKeeper::MintAuthToken(UniquePtr<uint8_t> *auth_token, size_t *length,
+void GateKeeper::MintAuthToken(UniquePtr<uint8_t> *auth_token, uint32_t *length,
uint32_t timestamp, secure_id_t user_id, secure_id_t authenticator_id) {
if (auth_token == NULL) return;
@@ -183,10 +183,10 @@ void GateKeeper::MintAuthToken(UniquePtr<uint8_t> *auth_token, size_t *length,
token->timestamp = timestamp;
const uint8_t *auth_token_key = NULL;
- size_t key_len = 0;
+ uint32_t key_len = 0;
GetAuthTokenKey(&auth_token_key, &key_len);
- size_t hash_len = (size_t)((uint8_t *)&token->hmac - (uint8_t *)token);
+ uint32_t hash_len = (uint32_t)((uint8_t *)&token->hmac - (uint8_t *)token);
ComputeSignature(token->hmac, sizeof(token->hmac), auth_token_key, key_len,
reinterpret_cast<uint8_t *>(token), hash_len);
diff --git a/gatekeeper_messages.cpp b/gatekeeper_messages.cpp
index cc700b1..e89ba68 100644
--- a/gatekeeper_messages.cpp
+++ b/gatekeeper_messages.cpp
@@ -19,6 +19,7 @@
#include <string.h>
+using namespace std;
namespace gatekeeper {
@@ -31,8 +32,8 @@ struct __attribute__((__packed__)) serial_header_t {
uint32_t user_id;
};
-static inline size_t serialized_buffer_size(const SizedBuffer &buf) {
- return sizeof(uint32_t) + buf.length;
+static inline uint32_t serialized_buffer_size(const SizedBuffer &buf) {
+ return sizeof(buf.length) + buf.length;
}
static inline void append_to_buffer(uint8_t **buffer, const SizedBuffer *to_append) {
@@ -62,7 +63,7 @@ static inline gatekeeper_error_t read_from_buffer(const uint8_t **buffer, const
}
-size_t GateKeeperMessage::GetSerializedSize() const {
+uint32_t GateKeeperMessage::GetSerializedSize() const {
if (error == ERROR_NONE) {
return 2 * sizeof(uint32_t) + nonErrorSerializedSize();
} else {
@@ -70,8 +71,8 @@ size_t GateKeeperMessage::GetSerializedSize() const {
}
}
-size_t GateKeeperMessage::Serialize(uint8_t *buffer, const uint8_t *end) const {
- size_t bytes_written = 0;
+uint32_t GateKeeperMessage::Serialize(uint8_t *buffer, const uint8_t *end) const {
+ uint32_t bytes_written = 0;
if (buffer + GetSerializedSize() > end) {
return 0;
}
@@ -134,7 +135,7 @@ VerifyRequest::~VerifyRequest() {
}
}
-size_t VerifyRequest::nonErrorSerializedSize() const {
+uint32_t VerifyRequest::nonErrorSerializedSize() const {
return serialized_buffer_size(password_handle) + serialized_buffer_size(provided_password);
}
@@ -183,7 +184,7 @@ void VerifyResponse::SetVerificationToken(SizedBuffer *auth_token) {
this->auth_token.length = auth_token->length;
}
-size_t VerifyResponse::nonErrorSerializedSize() const {
+uint32_t VerifyResponse::nonErrorSerializedSize() const {
return serialized_buffer_size(auth_token);
}
@@ -245,7 +246,7 @@ EnrollRequest::~EnrollRequest() {
}
}
-size_t EnrollRequest::nonErrorSerializedSize() const {
+uint32_t EnrollRequest::nonErrorSerializedSize() const {
return serialized_buffer_size(provided_password) + serialized_buffer_size(enrolled_password)
+ serialized_buffer_size(password_handle);
}
@@ -307,7 +308,7 @@ void EnrollResponse::SetEnrolledPasswordHandle(SizedBuffer *enrolled_password_ha
this->enrolled_password_handle.length = enrolled_password_handle->length;
}
-size_t EnrollResponse::nonErrorSerializedSize() const {
+uint32_t EnrollResponse::nonErrorSerializedSize() const {
return serialized_buffer_size(enrolled_password_handle);
}
diff --git a/include/gatekeeper/gatekeeper.h b/include/gatekeeper/gatekeeper.h
index f68a4f4..8effc15 100644
--- a/include/gatekeeper/gatekeeper.h
+++ b/include/gatekeeper/gatekeeper.h
@@ -91,7 +91,7 @@ protected:
* Ownership of the auth_token_key pointer is maintained by the implementor.
*
*/
- virtual void GetAuthTokenKey(const uint8_t **auth_token_key, size_t *length)
+ virtual void GetAuthTokenKey(const uint8_t **auth_token_key, uint32_t *length)
const = 0;
/**
* The key used to sign and verify password data.
@@ -104,7 +104,7 @@ protected:
* Ownership of the password_key pointer is maintained by the implementor.
*
*/
- virtual void GetPasswordKey(const uint8_t **password_key, size_t *length) = 0;
+ virtual void GetPasswordKey(const uint8_t **password_key, uint32_t *length) = 0;
/**
* Uses platform-specific routines to compute a signature on the provided password.
@@ -115,9 +115,9 @@ protected:
*
* Writes the signature_length size signature to the 'signature' pointer.
*/
- virtual void ComputePasswordSignature(uint8_t *signature, size_t signature_length,
- const uint8_t *key, size_t key_length, const uint8_t *password,
- size_t password_length, salt_t salt) const = 0;
+ virtual void ComputePasswordSignature(uint8_t *signature, uint32_t signature_length,
+ const uint8_t *key, uint32_t key_length, const uint8_t *password,
+ uint32_t password_length, salt_t salt) const = 0;
/**
* Retrieves a unique, cryptographically randomly generated buffer for use in password
@@ -125,16 +125,16 @@ protected:
*
* Assings the random to the random UniquePtr, relinquishing ownership to the caller
*/
- virtual void GetRandom(void *random, size_t requested_size) const = 0;
+ virtual void GetRandom(void *random, uint32_t requested_size) const = 0;
/**
* Uses platform-specific routines to compute a signature on the provided message.
*
* Writes the signature_length size signature to the 'signature' pointer.
*/
- virtual void ComputeSignature(uint8_t *signature, size_t signature_length,
- const uint8_t *key, size_t key_length, const uint8_t *message,
- const size_t length) const = 0;
+ virtual void ComputeSignature(uint8_t *signature, uint32_t signature_length,
+ const uint8_t *key, uint32_t key_length, const uint8_t *message,
+ const uint32_t length) const = 0;
/**
* Write the password file to persistent storage.
@@ -160,7 +160,7 @@ private:
* The format is consistent with that of AuthToken above.
* Also returns the length in length if it is not null.
*/
- void MintAuthToken(UniquePtr<uint8_t> *auth_token, size_t *length, uint32_t timestamp,
+ void MintAuthToken(UniquePtr<uint8_t> *auth_token, uint32_t *length, uint32_t timestamp,
secure_id_t user_id, secure_id_t authenticator_id);
/**
@@ -179,7 +179,7 @@ private:
*/
bool CreatePasswordHandle(SizedBuffer *password_handle, salt_t salt,
secure_id_t secure_id, secure_id_t authenticator_id, const uint8_t *password,
- size_t password_length);
+ uint32_t password_length);
};
}
diff --git a/include/gatekeeper/gatekeeper_messages.h b/include/gatekeeper/gatekeeper_messages.h
index 8b4abba..a98e1c5 100644
--- a/include/gatekeeper/gatekeeper_messages.h
+++ b/include/gatekeeper/gatekeeper_messages.h
@@ -43,7 +43,7 @@ struct SizedBuffer {
* Constructs a SizedBuffer of a provided
* length.
*/
- SizedBuffer(size_t length) {
+ SizedBuffer(uint32_t length) {
if (length != 0) {
buffer.reset(new uint8_t[length]);
} else {
@@ -57,13 +57,13 @@ struct SizedBuffer {
* Takes ownership of the buf pointer, and deallocates it
* when destructed.
*/
- SizedBuffer(uint8_t *buf, size_t len) {
+ SizedBuffer(uint8_t *buf, uint32_t len) {
buffer.reset(buf);
length = len;
}
UniquePtr<uint8_t> buffer;
- size_t length;
+ uint32_t length;
};
/*
@@ -80,7 +80,7 @@ struct GateKeeperMessage {
* Returns serialized size in bytes of the current state of the
* object.
*/
- size_t GetSerializedSize() const;
+ uint32_t GetSerializedSize() const;
/**
* Converts the object into its serialized representation.
*
@@ -88,7 +88,7 @@ struct GateKeeperMessage {
*
* Returns the number of bytes written or 0 on error.
*/
- size_t Serialize(uint8_t *payload, const uint8_t *end) const;
+ uint32_t Serialize(uint8_t *payload, const uint8_t *end) const;
/**
* Inflates the object from its serial representation.
@@ -105,7 +105,7 @@ struct GateKeeperMessage {
* Returns the size of serializing only the elements specific to the
* current sublclass.
*/
- virtual size_t nonErrorSerializedSize() const { return 0; } ;
+ virtual uint32_t nonErrorSerializedSize() const { return 0; } ;
/**
* Takes a pointer to a buffer prepared by Serialize and writes
* the subclass specific data into it. The size of the buffer must be exactly
@@ -132,7 +132,7 @@ struct VerifyRequest : public GateKeeperMessage {
VerifyRequest();
~VerifyRequest();
- virtual size_t nonErrorSerializedSize() const;
+ virtual uint32_t nonErrorSerializedSize() const;
virtual void nonErrorSerialize(uint8_t *buffer) const;
virtual gatekeeper_error_t nonErrorDeserialize(const uint8_t *payload, const uint8_t *end);
@@ -147,7 +147,7 @@ struct VerifyResponse : public GateKeeperMessage {
void SetVerificationToken(SizedBuffer *auth_token);
- virtual size_t nonErrorSerializedSize() const;
+ virtual uint32_t nonErrorSerializedSize() const;
virtual void nonErrorSerialize(uint8_t *buffer) const;
virtual gatekeeper_error_t nonErrorDeserialize(const uint8_t *payload, const uint8_t *end);
@@ -160,7 +160,7 @@ struct EnrollRequest : public GateKeeperMessage {
EnrollRequest();
~EnrollRequest();
- virtual size_t nonErrorSerializedSize() const;
+ virtual uint32_t nonErrorSerializedSize() const;
virtual void nonErrorSerialize(uint8_t *buffer) const;
virtual gatekeeper_error_t nonErrorDeserialize(const uint8_t *payload, const uint8_t *end);
@@ -187,7 +187,7 @@ public:
void SetEnrolledPasswordHandle(SizedBuffer *enrolled_password_handle);
- virtual size_t nonErrorSerializedSize() const;
+ virtual uint32_t nonErrorSerializedSize() const;
virtual void nonErrorSerialize(uint8_t *buffer) const;
virtual gatekeeper_error_t nonErrorDeserialize(const uint8_t *payload, const uint8_t *end);
diff --git a/include/gatekeeper/soft_gatekeeper.h b/include/gatekeeper/soft_gatekeeper.h
index aca9b0d..2927cd7 100644
--- a/include/gatekeeper/soft_gatekeeper.h
+++ b/include/gatekeeper/soft_gatekeeper.h
@@ -35,13 +35,13 @@ namespace gatekeeper {
class GateKeeperFileIo {
public:
virtual ~GateKeeperFileIo() {}
- virtual void Write(const char *filename, const uint8_t *bytes, size_t length) = 0;
- virtual size_t Read(const char *filename, UniquePtr<uint8_t> *bytes) const = 0;
+ virtual void Write(const char *filename, const uint8_t *bytes, uint32_t length) = 0;
+ virtual uint32_t Read(const char *filename, UniquePtr<uint8_t> *bytes) const = 0;
};
class SoftGateKeeper : public GateKeeper {
public:
- static const size_t SIGNATURE_LENGTH_BYTES = 32;
+ static const uint32_t SIGNATURE_LENGTH_BYTES = 32;
// scrypt params
static const uint64_t N = 16384;
@@ -61,33 +61,33 @@ public:
}
virtual void GetAuthTokenKey(const uint8_t **auth_token_key,
- size_t *length) const {
+ uint32_t *length) const {
if (auth_token_key == NULL || length == NULL) return;
*auth_token_key = const_cast<const uint8_t *>(key_.get());
*length = SIGNATURE_LENGTH_BYTES;
}
- virtual void GetPasswordKey(const uint8_t **password_key, size_t *length) {
+ virtual void GetPasswordKey(const uint8_t **password_key, uint32_t *length) {
if (password_key == NULL || length == NULL) return;
*password_key = const_cast<const uint8_t *>(key_.get());
*length = SIGNATURE_LENGTH_BYTES;
}
- virtual void ComputePasswordSignature(uint8_t *signature, size_t signature_length,
- const uint8_t *, size_t, const uint8_t *password,
- size_t password_length, salt_t salt) const {
+ virtual void ComputePasswordSignature(uint8_t *signature, uint32_t signature_length,
+ const uint8_t *, uint32_t, const uint8_t *password,
+ uint32_t password_length, salt_t salt) const {
if (signature == NULL) return;
crypto_scrypt(password, password_length, reinterpret_cast<uint8_t *>(&salt),
sizeof(salt), N, r, p, signature, signature_length);
}
- virtual void GetRandom(void *random, size_t requested_length) const {
+ virtual void GetRandom(void *random, uint32_t requested_length) const {
if (random == NULL) return;
RAND_pseudo_bytes((uint8_t *) random, requested_length);
}
- virtual void ComputeSignature(uint8_t *signature, size_t signature_length,
- const uint8_t *, size_t, const uint8_t *, const size_t) const {
+ virtual void ComputeSignature(uint8_t *signature, uint32_t signature_length,
+ const uint8_t *, uint32_t, const uint8_t *, const uint32_t) const {
if (signature == NULL) return;
memset(signature, 0, signature_length);
}
@@ -96,7 +96,7 @@ public:
char buf[MAX_UINT_32_CHARS];
sprintf(buf, "%u", uid);
UniquePtr<uint8_t> password_buffer;
- size_t length = file_io_->Read(buf, &password_buffer);
+ uint32_t length = file_io_->Read(buf, &password_buffer);
password_file->buffer.reset(password_buffer.release());
password_file->length = length;
}
diff --git a/softgatekeeper/native_gatekeeper_file_io.h b/softgatekeeper/native_gatekeeper_file_io.h
index b16dcf1..6b29bde 100644
--- a/softgatekeeper/native_gatekeeper_file_io.h
+++ b/softgatekeeper/native_gatekeeper_file_io.h
@@ -23,11 +23,11 @@ namespace gatekeeper {
class NativeGateKeeperFileIo : public ::gatekeeper::GateKeeperFileIo {
public:
- virtual void Write(const char *filename, const uint8_t *bytes, size_t length) {
+ virtual void Write(const char *filename, const uint8_t *bytes, uint32_t length) {
// TODO
}
- virtual size_t Read(const char *filename, UniquePtr<uint8_t> *bytes) const {
+ virtual uint32_t Read(const char *filename, UniquePtr<uint8_t> *bytes) const {
// TODO
return 0;
}
diff --git a/softgatekeeper/soft_gatekeeper_device.cpp b/softgatekeeper/soft_gatekeeper_device.cpp
index 03cc686..12bc9a1 100644
--- a/softgatekeeper/soft_gatekeeper_device.cpp
+++ b/softgatekeeper/soft_gatekeeper_device.cpp
@@ -92,10 +92,10 @@ int SoftGateKeeperDevice::close_device(hw_device_t* dev) {
}
int SoftGateKeeperDevice::Enroll(const struct gatekeeper_device *dev, uint32_t uid,
- const uint8_t *current_password_handle, size_t current_password_handle_length,
- const uint8_t *current_password, size_t current_password_length,
- const uint8_t *desired_password, size_t desired_password_length,
- uint8_t **enrolled_password_handle, size_t *enrolled_password_handle_length) {
+ const uint8_t *current_password_handle, uint32_t current_password_handle_length,
+ const uint8_t *current_password, uint32_t current_password_length,
+ const uint8_t *desired_password, uint32_t desired_password_length,
+ uint8_t **enrolled_password_handle, uint32_t *enrolled_password_handle_length) {
if (dev == NULL ||
enrolled_password_handle == NULL || enrolled_password_handle_length == NULL ||
@@ -140,9 +140,9 @@ int SoftGateKeeperDevice::Enroll(const struct gatekeeper_device *dev, uint32_t u
}
int SoftGateKeeperDevice::Verify(const struct gatekeeper_device *dev, uint32_t uid,
- const uint8_t *enrolled_password_handle, size_t enrolled_password_handle_length,
- const uint8_t *provided_password, size_t provided_password_length,
- uint8_t **auth_token, size_t *auth_token_length) {
+ const uint8_t *enrolled_password_handle, uint32_t enrolled_password_handle_length,
+ const uint8_t *provided_password, uint32_t provided_password_length,
+ uint8_t **auth_token, uint32_t *auth_token_length) {
if (dev == NULL || enrolled_password_handle == NULL ||
provided_password == NULL) {
diff --git a/softgatekeeper/soft_gatekeeper_device.h b/softgatekeeper/soft_gatekeeper_device.h
index 88bb59f..e9459bf 100644
--- a/softgatekeeper/soft_gatekeeper_device.h
+++ b/softgatekeeper/soft_gatekeeper_device.h
@@ -51,10 +51,10 @@ private:
* On error, enrolled_password_handle will not be allocated.
*/
static int Enroll(const struct gatekeeper_device *dev, uint32_t uid,
- const uint8_t *current_password_handle, size_t current_password_handle_length,
- const uint8_t *current_password, size_t current_password_length,
- const uint8_t *desired_password, size_t desired_password_length,
- uint8_t **enrolled_password_handle, size_t *enrolled_password_handle_length);
+ const uint8_t *current_password_handle, uint32_t current_password_handle_length,
+ const uint8_t *current_password, uint32_t current_password_length,
+ const uint8_t *desired_password, uint32_t desired_password_length,
+ uint8_t **enrolled_password_handle, uint32_t *enrolled_password_handle_length);
/**
* Verifies provided_password matches enrolled_password_handle.
*
@@ -69,9 +69,9 @@ private:
* On error, verification token will not be allocated
*/
static int Verify(const struct gatekeeper_device *dev, uint32_t uid,
- const uint8_t *enrolled_password_handle, size_t enrolled_password_handle_length,
- const uint8_t *provided_password, size_t provided_password_length,
- uint8_t **auth_token, size_t *auth_token_length);
+ const uint8_t *enrolled_password_handle, uint32_t enrolled_password_handle_length,
+ const uint8_t *provided_password, uint32_t provided_password_length,
+ uint8_t **auth_token, uint32_t *auth_token_length);
gatekeeper_device device_;
UniquePtr<GateKeeper> impl_;
diff --git a/tests/gatekeeper_device_test.cpp b/tests/gatekeeper_device_test.cpp
index 31b573b..1d7e74b 100644
--- a/tests/gatekeeper_device_test.cpp
+++ b/tests/gatekeeper_device_test.cpp
@@ -50,12 +50,12 @@ public:
};
TEST_F(GateKeeperDeviceTest, EnrollAndVerify) {
- size_t password_len = 50;
+ uint32_t password_len = 50;
uint8_t password_payload[password_len];
uint8_t *password_handle;
- size_t password_handle_length;
+ uint32_t password_handle_length;
uint8_t *auth_token;
- size_t auth_token_len;
+ uint32_t auth_token_len;
int ret;
ret = device->enroll(device, 0, NULL, 0, NULL, 0, password_payload, password_len,
@@ -70,12 +70,12 @@ TEST_F(GateKeeperDeviceTest, EnrollAndVerify) {
}
TEST_F(GateKeeperDeviceTest, EnrollAndVerifyBadPassword) {
- size_t password_len = 50;
+ uint32_t password_len = 50;
uint8_t password_payload[password_len];
uint8_t *password_handle;
- size_t password_handle_length;
+ uint32_t password_handle_length;
uint8_t *auth_token = NULL;
- size_t auth_token_len;
+ uint32_t auth_token_len;
int ret;
ret = device->enroll(device, 0, NULL, 0, NULL, 0, password_payload, password_len,
@@ -93,10 +93,10 @@ TEST_F(GateKeeperDeviceTest, EnrollAndVerifyBadPassword) {
}
TEST_F(GateKeeperDeviceTest, UntrustedReEnroll) {
- size_t password_len = 50;
+ uint32_t password_len = 50;
uint8_t password_payload[password_len];
uint8_t *password_handle;
- size_t password_handle_length;
+ uint32_t password_handle_length;
int ret;
ret = device->enroll(device, 0, NULL, 0, NULL, 0, password_payload, password_len,
@@ -117,10 +117,10 @@ TEST_F(GateKeeperDeviceTest, UntrustedReEnroll) {
TEST_F(GateKeeperDeviceTest, TrustedReEnroll) {
- size_t password_len = 50;
+ uint32_t password_len = 50;
uint8_t password_payload[password_len];
uint8_t *password_handle;
- size_t password_handle_length;
+ uint32_t password_handle_length;
int ret;
ret = device->enroll(device, 0, NULL, 0, NULL, 0, password_payload, password_len,
diff --git a/tests/gatekeeper_messages_test.cpp b/tests/gatekeeper_messages_test.cpp
index 14007a2..1a18e82 100644
--- a/tests/gatekeeper_messages_test.cpp
+++ b/tests/gatekeeper_messages_test.cpp
@@ -32,13 +32,13 @@ using std::endl;
static const uint32_t USER_ID = 3857;
-static SizedBuffer *make_buffer(size_t size) {
+static SizedBuffer *make_buffer(uint32_t size) {
SizedBuffer *result = new SizedBuffer;
result->length = size;
uint8_t *buffer = new uint8_t[size];
srand(size);
- for (size_t i = 0; i < size; i++) {
+ for (uint32_t i = 0; i < size; i++) {
buffer[i] = rand();
}
@@ -47,7 +47,7 @@ static SizedBuffer *make_buffer(size_t size) {
}
TEST(RoundTripTest, EnrollRequestNullEnrolledNullHandle) {
- const size_t password_size = 512;
+ const uint32_t password_size = 512;
SizedBuffer *provided_password = make_buffer(password_size);
const SizedBuffer *deserialized_password;
// create request, serialize, deserialize, and validate
@@ -66,15 +66,15 @@ TEST(RoundTripTest, EnrollRequestNullEnrolledNullHandle) {
ASSERT_EQ(USER_ID, deserialized_msg.user_id);
ASSERT_EQ((uint32_t) password_size, deserialized_password->length);
ASSERT_EQ(0, memcmp(msg.provided_password.buffer.get(), deserialized_password->buffer.get(), password_size));
- ASSERT_EQ((size_t) 0, deserialized_msg.enrolled_password.length);
+ ASSERT_EQ((uint32_t) 0, deserialized_msg.enrolled_password.length);
ASSERT_EQ(NULL, deserialized_msg.enrolled_password.buffer.get());
- ASSERT_EQ((size_t) 0, deserialized_msg.password_handle.length);
+ ASSERT_EQ((uint32_t) 0, deserialized_msg.password_handle.length);
ASSERT_EQ(NULL, deserialized_msg.password_handle.buffer.get());
delete provided_password;
}
TEST(RoundTripTest, EnrollRequestEmptyEnrolledEmptyHandle) {
- const size_t password_size = 512;
+ const uint32_t password_size = 512;
SizedBuffer *provided_password = make_buffer(password_size);
SizedBuffer enrolled;
SizedBuffer handle;
@@ -95,15 +95,15 @@ TEST(RoundTripTest, EnrollRequestEmptyEnrolledEmptyHandle) {
ASSERT_EQ(USER_ID, deserialized_msg.user_id);
ASSERT_EQ((uint32_t) password_size, deserialized_password->length);
ASSERT_EQ(0, memcmp(msg.provided_password.buffer.get(), deserialized_password->buffer.get(), password_size));
- ASSERT_EQ((size_t) 0, deserialized_msg.enrolled_password.length);
+ ASSERT_EQ((uint32_t) 0, deserialized_msg.enrolled_password.length);
ASSERT_EQ(NULL, deserialized_msg.enrolled_password.buffer.get());
- ASSERT_EQ((size_t) 0, deserialized_msg.password_handle.length);
+ ASSERT_EQ((uint32_t) 0, deserialized_msg.password_handle.length);
ASSERT_EQ(NULL, deserialized_msg.password_handle.buffer.get());
delete provided_password;
}
TEST(RoundTripTest, EnrollRequestNonNullEnrolledOrHandle) {
- const size_t password_size = 512;
+ const uint32_t password_size = 512;
SizedBuffer *provided_password = make_buffer(password_size);
SizedBuffer *enrolled_password = make_buffer(password_size);
SizedBuffer *password_handle = make_buffer(password_size);
@@ -139,7 +139,7 @@ TEST(RoundTripTest, EnrollRequestNonNullEnrolledOrHandle) {
TEST(RoundTripTest, EnrollResponse) {
- const size_t password_size = 512;
+ const uint32_t password_size = 512;
SizedBuffer *enrolled_password = make_buffer(password_size);
const SizedBuffer *deserialized_password;
// create request, serialize, deserialize, and validate
@@ -162,7 +162,7 @@ TEST(RoundTripTest, EnrollResponse) {
}
TEST(RoundTripTest, VerifyRequest) {
- const size_t password_size = 512;
+ const uint32_t password_size = 512;
SizedBuffer *provided_password = make_buffer(password_size),
*password_handle = make_buffer(password_size);
const SizedBuffer *deserialized_password;
@@ -191,7 +191,7 @@ TEST(RoundTripTest, VerifyRequest) {
}
TEST(RoundTripTest, VerifyResponse) {
- const size_t password_size = 512;
+ const uint32_t password_size = 512;
SizedBuffer *auth_token = make_buffer(password_size);
const SizedBuffer *deserialized_password;
// create request, serialize, deserialize, and validate
@@ -293,9 +293,9 @@ uint8_t msgbuf[] = {
template <typename Message> void parse_garbage() {
Message msg;
- size_t array_length = sizeof(msgbuf) / sizeof(msgbuf[0]);
+ uint32_t array_length = sizeof(msgbuf) / sizeof(msgbuf[0]);
const uint8_t* end = msgbuf + array_length;
- for (size_t i = 0; i < array_length; ++i) {
+ for (uint32_t i = 0; i < array_length; ++i) {
const uint8_t* begin = msgbuf + i;
const uint8_t* p = begin;
msg.Deserialize(p, end);
diff --git a/tests/gatekeeper_test.cpp b/tests/gatekeeper_test.cpp
index 2c91295..e47198b 100644
--- a/tests/gatekeeper_test.cpp
+++ b/tests/gatekeeper_test.cpp
@@ -36,13 +36,13 @@ public:
bytes_.length = 0;
}
- virtual void Write(const char *filename, const uint8_t *bytes, size_t length) {
+ virtual void Write(const char *filename, const uint8_t *bytes, uint32_t length) {
bytes_.buffer.reset(new uint8_t[length]);
memcpy(bytes_.buffer.get(), bytes, length);
bytes_.length = length;
}
- virtual size_t Read(const char *filename, UniquePtr<uint8_t> *bytes) const {
+ virtual uint32_t Read(const char *filename, UniquePtr<uint8_t> *bytes) const {
if (!bytes_.buffer.get() || bytes_.length == 0) {
bytes->reset();
} else {