Skip to content

Commit 8d51fc2

Browse files
authored
Refactor WebRTC exception messages and fingerprint comparison (#1661)
* Refactor WebRTC exception messages and fingerprint comparison Consolidate exception message formatting to single lines for clarity. Update certificate fingerprint comparison to use string.Equals with ordinal ignore case, following best practices and user preferences. * Fix extra spaces in RTCDataChannel exception messages Removed unnecessary double spaces in exception strings to improve consistency and readability in RTCDataChannel.cs.
1 parent 46bf3c6 commit 8d51fc2

3 files changed

Lines changed: 6 additions & 8 deletions

File tree

src/SIPSorcery/net/WebRTC/RTCDataChannel.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,7 @@ public void send(string message)
134134
{
135135
if (message != null && Encoding.UTF8.GetByteCount(message) > _transport.maxMessageSize)
136136
{
137-
throw new ApplicationException($"Data channel {label} was requested to send data of length {Encoding.UTF8.GetByteCount(message)} " +
138-
$" that exceeded the maximum allowed message size of {_transport.maxMessageSize}.");
137+
throw new ApplicationException($"Data channel {label} was requested to send data of length {Encoding.UTF8.GetByteCount(message)} that exceeded the maximum allowed message size of {_transport.maxMessageSize}.");
139138
}
140139
else if (_transport.state != RTCSctpTransportState.Connected)
141140
{
@@ -173,8 +172,7 @@ public void send(byte[] data, int offset = 0, int count = -1)
173172

174173
if (effectiveCount > _transport.maxMessageSize)
175174
{
176-
throw new ApplicationException($"Data channel {label} was requested to send data of length {effectiveCount} " +
177-
$" that exceeded the maximum allowed message size of {_transport.maxMessageSize}.");
175+
throw new ApplicationException($"Data channel {label} was requested to send data of length {effectiveCount} that exceeded the maximum allowed message size of {_transport.maxMessageSize}.");
178176
}
179177
else if (_transport.state != RTCSctpTransportState.Connected)
180178
{

src/SIPSorcery/net/WebRTC/RTCPeerConnection.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1876,12 +1876,13 @@ private bool DoDtlsHandshake(DtlsSrtpTransport dtlsHandle)
18761876
}
18771877
else
18781878
{
1879-
logger.LogDebug($"RTCPeerConnection DTLS handshake result {handshakeResult}, is handshake complete {dtlsHandle.IsHandshakeComplete()}.");
1879+
logger.LogDebug("RTCPeerConnection DTLS handshake result {HandshakeResult}, is handshake complete {IsHandshakeComplete}.",
1880+
handshakeResult, dtlsHandle.IsHandshakeComplete());
18801881

18811882
var expectedFp = RemotePeerDtlsFingerprint;
18821883
var remoteFingerprint = DtlsUtils.Fingerprint(expectedFp.algorithm, dtlsHandle.GetRemoteCertificate().GetCertificateAt(0));
18831884

1884-
if (remoteFingerprint.value?.ToUpper() != expectedFp.value?.ToUpper())
1885+
if (!string.Equals(remoteFingerprint.value, expectedFp.value, StringComparison.OrdinalIgnoreCase))
18851886
{
18861887
logger.LogWarning("RTCPeerConnection remote certificate fingerprint mismatch, expected {ExpectedFingerprint}, actual {RemoteFingerprint}.", expectedFp, remoteFingerprint);
18871888
Close("dtls fingerprint mismatch");

src/SIPSorcery/net/WebRTC/RTCSctpTransport.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,7 @@ public override void Send(string associationID, byte[] buffer, int offset, int l
380380
{
381381
if (length > maxMessageSize)
382382
{
383-
throw new ApplicationException($"RTCSctpTransport was requested to send data of length {length} " +
384-
$" that exceeded the maximum allowed message size of {maxMessageSize}.");
383+
throw new ApplicationException($"RTCSctpTransport was requested to send data of length {length} that exceeded the maximum allowed message size of {maxMessageSize}.");
385384
}
386385

387386
if (!_isClosed)

0 commit comments

Comments
 (0)