Skip to content

Commit

Permalink
[Source/cryptalgo/SecureSocketPort] : 'Read()' and 'Write()' map to a…
Browse files Browse the repository at this point in the history
… different error value

Minor change in 'Update'. 'Trigger' is not needed.
  • Loading branch information
msieben committed Dec 11, 2024
1 parent e5d4304 commit f47bf18
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions Source/cryptalgo/SecureSocketPort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,21 +268,19 @@ uint32_t SecureSocketPort::Handler::Initialize() {
}

int32_t SecureSocketPort::Handler::Read(uint8_t buffer[], const uint16_t length) const {
int result = 0;
ASSERT(_handShaking == CONNECTED);

if (_handShaking == CONNECTED) { // Avoid reading while still in CONNECTING or ACCEPTING
result = SSL_read(static_cast<SSL*>(_ssl), buffer, length);
}
int result = SSL_read(static_cast<SSL*>(_ssl), buffer, length);

return (result > 0 ? result : 0);
return (result > 0 ? result : /* error */ -1);
}

int32_t SecureSocketPort::Handler::Write(const uint8_t buffer[], const uint16_t length) {
ASSERT(_handShaking == CONNECTED);

int result = SSL_write(static_cast<SSL*>(_ssl), buffer, length);

return (result > 0 ? result : 0);
return (result > 0 ? result : /* error */ -1);
}


Expand Down Expand Up @@ -447,7 +445,7 @@ void SecureSocketPort::Handler::Update() {
ValidateHandShake();
}
} // Re-initialie a previous session
if (_handShaking == EXCHANGE) {
else if (_handShaking == EXCHANGE) {
if ((result = SSL_do_handshake(static_cast<SSL*>(_ssl))) == 1) {
_handShaking = CONNECTED;
ValidateHandShake();
Expand All @@ -461,16 +459,14 @@ void SecureSocketPort::Handler::Update() {
// Non-blocking I/O: select may be used to check if condition has changed
_handShaking = CONNECTED;
ValidateHandShake();
Trigger();
}
else {
_handShaking = ERROR;
}
}
}
else {
_parent.StateChange();
}

_parent.StateChange();
}

} } // namespace Thunder::Crypto

0 comments on commit f47bf18

Please sign in to comment.