Skip to content

Commit

Permalink
Rename methods in API to make string return more obvious
Browse files Browse the repository at this point in the history
Signed-off-by: Szczepan Zalega <[email protected]>
  • Loading branch information
szszszsz committed Nov 26, 2016
1 parent 8d4bff3 commit cdd16f3
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 14 deletions.
8 changes: 4 additions & 4 deletions NK_C_API.cc
Original file line number Diff line number Diff line change
Expand Up @@ -450,17 +450,17 @@ extern int NK_change_update_password(const char* current_update_password,
});
}

extern const char* NK_get_status_storage() {
extern const char* NK_get_status_storage_as_string() {
auto m = NitrokeyManager::instance();
return get_with_string_result([&](){
return m->get_status_storage();
return m->get_status_storage_as_string();
});
}

extern const char* NK_get_SD_usage_data() {
extern const char* NK_get_SD_usage_data_as_string() {
auto m = NitrokeyManager::instance();
return get_with_string_result([&](){
return m->get_SD_usage_data();
return m->get_SD_usage_data_as_string();
});
}

Expand Down
4 changes: 2 additions & 2 deletions NK_C_API.h
Original file line number Diff line number Diff line change
Expand Up @@ -430,15 +430,15 @@ extern int NK_change_update_password(const char* current_update_password,
* Storage only
* @return string with devices attributes
*/
extern const char* NK_get_status_storage();
extern const char* NK_get_status_storage_as_string();

/**
* Get SD card usage attributes as string.
* Usable during hidden volumes creation.
* Storage only
* @return string with SD card usage attributes
*/
extern const char* NK_get_SD_usage_data();
extern const char* NK_get_SD_usage_data_as_string();

/**
* Get progress value of current long operation.
Expand Down
7 changes: 3 additions & 4 deletions NitrokeyManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -491,9 +491,8 @@ namespace nitrokey{

void NitrokeyManager::send_startup(uint64_t seconds_from_epoch){
auto p = get_payload<stick20::SendStartup>();
// p.set_defaults();
// p.set_defaults(); //set current time
p.localtime = seconds_from_epoch;
//auto device_status =
stick20::SendStartup::CommandTransaction::run(*device, p);
}

Expand Down Expand Up @@ -547,12 +546,12 @@ namespace nitrokey{
stick20::ChangeUpdatePassword::CommandTransaction::run(*device, p);
}

const char * NitrokeyManager::get_status_storage(){
const char * NitrokeyManager::get_status_storage_as_string(){
auto p = stick20::GetDeviceStatus::CommandTransaction::run(*device);
return strdup(p.data().dissect().c_str());
}

const char * NitrokeyManager::get_SD_usage_data(){
const char * NitrokeyManager::get_SD_usage_data_as_string(){
auto p = stick20::GetSDCardOccupancy::CommandTransaction::run(*device);
return strdup(p.data().dissect().c_str());
}
Expand Down
4 changes: 2 additions & 2 deletions include/NitrokeyManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ namespace nitrokey {

void send_startup(uint64_t seconds_from_epoch);

const char * get_status_storage();
const char * get_status_storage_as_string();

const char *get_SD_usage_data();
const char *get_SD_usage_data_as_string();

int get_progress_bar_value();

Expand Down
7 changes: 5 additions & 2 deletions unittest/test_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,18 @@ def get_dict_from_dissect(status):


def test_get_status_storage(C):
status_pointer = C.NK_get_status_storage()
status_pointer = C.NK_get_status_storage_as_string()
assert C.NK_get_last_command_status() == DeviceErrorCode.STATUS_OK
status_string = gs(status_pointer)
assert len(status_string) > 0
status_dict = get_dict_from_dissect(status_string)
default_admin_password_retry_count = 3
assert int(status_dict['AdminPwRetryCount']) == default_admin_password_retry_count


def test_sd_card_usage(C):
data_pointer = C.NK_get_SD_usage_data()
data_pointer = C.NK_get_SD_usage_data_as_string()
assert C.NK_get_last_command_status() == DeviceErrorCode.STATUS_OK
data_string = gs(data_pointer)
assert len(data_string) > 0
data_dict = get_dict_from_dissect(data_string)
Expand Down

0 comments on commit cdd16f3

Please sign in to comment.