-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
device_ledger: factor the prologue code #4032
Conversation
src/device/device_ledger.cpp
Outdated
@@ -317,6 +317,30 @@ namespace hw { | |||
memset(this->buffer_recv, 0, BUFFER_RECV_SIZE); | |||
} | |||
|
|||
int device_ledger::prologue(BYTE type, BYTE extra) { | |||
reset_buffer(); | |||
int offset = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused?
src/device/device_ledger.cpp
Outdated
return 5; | ||
} | ||
|
||
int device_ledger::prologue_noopt(BYTE type, BYTE extra) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is it necessary to have prologue
and prologue_noopt
separately? Can't we have just one prologue
as:
int device_ledger::prologue(BYTE type, BYTE extra) {
reset_buffer();
this->buffer_send[0] = 0x00;
this->buffer_send[1] = type;
this->buffer_send[2] = extra;
this->buffer_send[3] = 0x00;
this->buffer_send[4] = 0x00;
int offset = 5;
//options
this->buffer_send[offset++] = 0;
return offset;
}
void device_ledger::send_simple(BYTE type, BYTE extra) {
int offset = prologue(type, extra);
this->buffer_send[4] = offset - 5;
this->length_send = offset;
this->exchange();
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to allow some more factoring while avoiding a function with (what I think would be) too many parameters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But this way of split seems weird to me, because AIUI this line
this->buffer_send[4] = offset - 5;
is supposed to go together with these lines
this->length_send = offset;
this->exchange();
I.e. the content of buffer_send[4]
indicates the size of optional argument data starting from buffer_send[5]
. In the current patch, the call to prologue_noopt()
puts 1 to buffer_send[4]
, which will then be overwritten by the subsequent line this->buffer_send[4] = offset-5;
. The end result is the same, but this patch adds an unnecessary step of buffer_send[4] = 1
which seems weird to me. I also don't really understand what you said above (to allow more factoring and to avoid a function with too many parameters). Can you elaborate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAICT, buffer_send[4] is a message length, so it looks right. This step is only unnecessary when the prologue is followed by other data, increasing the message length.
What I meant by a function with more parameters is that there could be one single function which you configure with command byte, extra byte, optional byte, and possibly more. I simply decided not to do it that way because I judged it less clear/too annoying for the caller.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, thanks for the clarification.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, though approval from @cslashm would be very desirable
5b28a5c
to
7276fa6
Compare
one more call using send_simple |
7276fa6
to
9254b30
Compare
Expand the prologue functions to also factor a couple more variants, per request. |
9254b30
to
5abc65e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Except the naming, looks fine for me .
src/device/device_ledger.cpp
Outdated
offset = 5; | ||
//options | ||
this->buffer_send[offset] = 0x00; | ||
int device_ledger::prologue(BYTE type, BYTE extra, BYTE extraer) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In order to respect the ISO7816 protocol naming (which is used by PCSC and the NanosApp) I 'd prefere this naming:
int device_ledger::set_command_header(BYTE ins , BYTE p1, BYTE p2)
src/device/device_ledger.cpp
Outdated
this->buffer_send[4] = offset-5; | ||
this->length_send = offset; | ||
this->exchange(); | ||
int device_ledger::prologue_noopt(BYTE type, BYTE extra, BYTE extraer) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In order to respect the ISO7816 protocol naming (which is used by PCSC and the NanosApp) I 'd prefere this naming:
int device_ledger::set_command_header_noopt(BYTE ins , BYTE p1, BYTE p2)
5abc65e
to
87e158b
Compare
87e158b device_ledger: factor the prologue code (moneromooo-monero)
No description provided.