Skip to content

Commit def6432

Browse files
committed
C#-flavor all the things, remove ~400 warnings
1 parent fd00756 commit def6432

File tree

83 files changed

+1026
-4511
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+1026
-4511
lines changed

libsignal-service-dotnet/AsyncHelper.cs

Lines changed: 0 additions & 50 deletions
This file was deleted.

libsignal-service-dotnet/Base64.cs

Lines changed: 10 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,17 @@
1-
/**
2-
* Copyright (C) 2015 smndtrl
3-
*
4-
* This program is free software: you can redistribute it and/or modify
5-
* it under the terms of the GNU General Public License as published by
6-
* the Free Software Foundation, either version 3 of the License, or
7-
* (at your option) any later version.
8-
*
9-
* This program is distributed in the hope that it will be useful,
10-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12-
* GNU General Public License for more details.
13-
*
14-
* You should have received a copy of the GNU General Public License
15-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16-
*/
17-
181
using System;
192
using System.Text;
203

214
namespace libsignalservice.util
22-
{
23-
public class Base64
5+
{
6+
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
7+
public class Base64
248
{
25-
/*public static byte[] encodeBytes(byte[] input)
26-
{
27-
char[] chars = System.Text.Encoding.UTF8.GetString(input, 0, input.Length).ToCharArray();
28-
return Convert.ToBase64String(input);
29-
}*/
30-
319
public static string EncodeBytes(byte[] input)
3210
{
3311
return Convert.ToBase64String(input);
3412
}
3513

36-
public static string encodeBytesWithoutPadding(byte[] input)
14+
public static string EncodeBytesWithoutPadding(byte[] input)
3715
{
3816
String encoded = null;
3917

@@ -44,32 +22,27 @@ public static string encodeBytesWithoutPadding(byte[] input)
4422
else return encoded;
4523
}
4624

47-
/*public static byte[] encodeWithoutPadding(byte[] input)
48-
{
49-
char[] chars = System.Text.Encoding.UTF8.GetString(input, 0, input.Length).ToCharArray();
50-
return Convert.ToBase64CharArray(chars, 0, chars.Length);
51-
}*/
52-
53-
public static byte[] encode(byte[] input)
25+
public static byte[] Encode(byte[] input)
5426
{
5527
char[] chars = System.Text.Encoding.UTF8.GetString(input, 0, input.Length).ToCharArray();
5628
return Encoding.UTF8.GetBytes(Convert.ToBase64String(input));
5729
}
5830

59-
public static byte[] decode(string input)
31+
public static byte[] Decode(string input)
6032
{
6133
return Convert.FromBase64String(input);
6234
}
6335

64-
public static byte[] decodeWithoutPadding(string input)
36+
public static byte[] DecodeWithoutPadding(string input)
6537
{
6638
int padding = input.Length % 4;
6739

6840
if (padding == 1) input = input + "=";
6941
else if (padding == 2) input = input + "==";
7042
else if (padding == 3) input = input + "=";
7143

72-
return decode(input);
44+
return Decode(input);
7345
}
74-
}
46+
}
47+
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
7548
}

libsignal-service-dotnet/LibsignalLogging.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
using System.Text;
55

66
namespace libsignalservice
7-
{
7+
{
8+
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
89
public class LibsignalLogging
910
{
1011
public static ILoggerFactory LoggerFactory { get; } = new LoggerFactory();
1112
public static ILogger CreateLogger<T>() => LoggerFactory.CreateLogger<T>();
12-
}
13+
}
14+
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
1315
}

libsignal-service-dotnet/SignalServiceAccountManager.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ public SignalServiceAccountManager(SignalServiceConfiguration configuration, Can
6262
PushServiceSocket = new PushServiceSocket(configuration, new StaticCredentialsProvider(null, null, null, (int)SignalServiceAddress.DEFAULT_DEVICE_ID), userAgent);
6363
}
6464

65+
/// <summary>
66+
///
67+
/// </summary>
68+
/// <param name="pin"></param>
6569
public void SetPin(string pin)
6670
{
6771
if (pin != null)
@@ -118,6 +122,7 @@ public void RequestVoiceVerificationCode()// throws IOException
118122
/// same install, but probabilistically differ across registrations
119123
/// for separate installs.</param>
120124
/// <param name="fetchesMessages">True if the client does not support GCM</param>
125+
/// <param name="pin"></param>
121126
/// <returns></returns>
122127
public void VerifyAccountWithCode(string verificationCode, string signalingKey,
123128
uint signalProtocolRegistrationId, bool fetchesMessages, string pin)
@@ -135,6 +140,7 @@ public void VerifyAccountWithCode(string verificationCode, string signalingKey,
135140
/// install, but probabilistically differ across registrations for
136141
/// separate installs.</param>
137142
/// <param name="fetchesMessages">True if the client does not support GCM</param>
143+
/// <param name="pin"></param>
138144
/// <returns></returns>
139145
public void SetAccountAttributes(string signalingKey, uint signalProtocolRegistrationId, bool fetchesMessages, string pin)
140146
{
@@ -355,7 +361,7 @@ public TurnServerInfo GetTurnServerInfo()
355361
public void SetProfileName(byte[] key, string name)
356362
{
357363
if (name == null) name = "";
358-
string ciphertextName = Base64.encodeBytesWithoutPadding(new ProfileCipher(key).EncryptName(Encoding.Unicode.GetBytes(name), ProfileCipher.NAME_PADDED_LENGTH));
364+
string ciphertextName = Base64.EncodeBytesWithoutPadding(new ProfileCipher(key).EncryptName(Encoding.Unicode.GetBytes(name), ProfileCipher.NAME_PADDED_LENGTH));
359365
PushServiceSocket.SetProfileName(ciphertextName);
360366
}
361367

@@ -395,8 +401,8 @@ private string CreateDirectoryServerToken(string e164number, bool urlSafe)
395401
{
396402
try
397403
{
398-
byte[] token = Util.trim(Hash.sha1(Encoding.UTF8.GetBytes(e164number)), 10);
399-
string encoded = Base64.encodeBytesWithoutPadding(token);
404+
byte[] token = Util.Trim(Hash.Sha1(Encoding.UTF8.GetBytes(e164number)), 10);
405+
string encoded = Base64.EncodeBytesWithoutPadding(token);
400406

401407
if (urlSafe) return encoded.Replace('+', '-').Replace('/', '_');
402408
else return encoded;

libsignal-service-dotnet/SignalServiceMessagePipe.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public void ReadBlocking(IMessagePipeCallback callback)
4646

4747
if (IsSignalServiceEnvelope(request))
4848
{
49-
SignalServiceMessagePipeMessage message = new SignalServiceEnvelope(request.Body.ToByteArray(), CredentialsProvider.GetSignalingKey());
49+
SignalServiceMessagePipeMessage message = new SignalServiceEnvelope(request.Body.ToByteArray(), CredentialsProvider.SignalingKey);
5050
WebSocketResponseMessage response = CreateWebSocketResponse(request);
5151
try
5252
{
@@ -83,10 +83,10 @@ public SendMessageResponse Send(OutgoingPushMessageList list)
8383
Logger.LogTrace("Send()");
8484
WebSocketRequestMessage requestmessage = new WebSocketRequestMessage()
8585
{
86-
Id = BitConverter.ToUInt64(Util.getSecretBytes(sizeof(long)), 0),
86+
Id = BitConverter.ToUInt64(Util.GetSecretBytes(sizeof(long)), 0),
8787
Verb = "PUT",
88-
Path = $"/v1/messages/{list.getDestination()}",
89-
Body = ByteString.CopyFrom(Encoding.UTF8.GetBytes(JsonUtil.toJson(list)))
88+
Path = $"/v1/messages/{list.Destination}",
89+
Body = ByteString.CopyFrom(Encoding.UTF8.GetBytes(JsonUtil.ToJson(list)))
9090
};
9191
requestmessage.Headers.Add("content-type:application/json");
9292
Logger.LogDebug("Sending message {0}", requestmessage.Id);
@@ -119,7 +119,7 @@ public SignalServiceProfile GetProfile(SignalServiceAddress address)
119119
Logger.LogTrace("GetProfile()");
120120
WebSocketRequestMessage requestMessage = new WebSocketRequestMessage()
121121
{
122-
Id = BitConverter.ToUInt64(Util.getSecretBytes(sizeof(long)), 0),
122+
Id = BitConverter.ToUInt64(Util.GetSecretBytes(sizeof(long)), 0),
123123
Verb = "GET",
124124
Path = $"/v1/profile/{address.E164number}"
125125
};

libsignal-service-dotnet/SignalServiceMessageReceiver.cs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414
using System.Security.Cryptography;
1515
using System.Threading;
1616
using static libsignalservice.messages.SignalServiceAttachment;
17+
using static libsignalservice.SignalServiceMessagePipe;
1718

1819
namespace libsignalservice
1920
{
21+
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
2022
/// <summary>
2123
/// The primary interface for receiving Signal Service messages.
2224
/// </summary>
@@ -111,29 +113,25 @@ public SignalServiceMessagePipe CreateMessagePipe()
111113
return new SignalServiceMessagePipe(Token, webSocket, CredentialsProvider);
112114
}
113115

114-
public List<SignalServiceEnvelope> RetrieveMessages(MessageReceivedCallback callback)
116+
public List<SignalServiceEnvelope> RetrieveMessages(IMessagePipeCallback callback)
115117
{
116118
List<SignalServiceEnvelope> results = new List<SignalServiceEnvelope>();
117119
List<SignalServiceEnvelopeEntity> entities = Socket.GetMessages();
118120

119121
foreach (SignalServiceEnvelopeEntity entity in entities)
120122
{
121-
SignalServiceEnvelope envelope = new SignalServiceEnvelope((int)entity.getType(), entity.getSource(),
122-
(int)entity.getSourceDevice(), entity.getRelay(),
123-
(int)entity.getTimestamp(), entity.getMessage(),
124-
entity.getContent());
123+
SignalServiceEnvelope envelope = new SignalServiceEnvelope((int)entity.Type, entity.Source,
124+
(int)entity.SourceDevice, entity.Relay,
125+
(int)entity.Timestamp, entity.Message,
126+
entity.Content);
125127

126-
callback.onMessage(envelope);
128+
callback.OnMessage(envelope);
127129
results.Add(envelope);
128130

129-
Socket.AcknowledgeMessage(entity.getSource(), entity.getTimestamp());
131+
Socket.AcknowledgeMessage(entity.Source, entity.Timestamp);
130132
}
131133
return results;
132134
}
133-
134-
public interface MessageReceivedCallback
135-
{
136-
void onMessage(SignalServiceEnvelope envelope);
137-
}
138135
}
136+
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
139137
}

libsignal-service-dotnet/SignalServiceMessageSender.cs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ private void SendMessage(VerifiedMessage message)
213213
{
214214
byte[] nullMessageBody = new DataMessage()
215215
{
216-
Body = Base64.EncodeBytes(Util.getRandomLengthBytes(140))
216+
Body = Base64.EncodeBytes(Util.GetRandomLengthBytes(140))
217217
}.ToByteArray();
218218

219219
NullMessage nullMessage = new NullMessage()
@@ -446,8 +446,8 @@ private byte[] CreateMultiDeviceReadContent(List<ReadMessage> readMessages)
446446
{
447447
syncMessage.Read.Add(new SyncMessage.Types.Read
448448
{
449-
Timestamp = (ulong)readMessage.getTimestamp(),
450-
Sender = readMessage.getSender()
449+
Timestamp = (ulong)readMessage.Timestamp,
450+
Sender = readMessage.Sender
451451
});
452452
}
453453
content.SyncMessage = syncMessage;
@@ -460,7 +460,7 @@ private byte[] CreateMultiDeviceBlockedContent(BlockedListMessage blocked)
460460
SyncMessage syncMessage = new SyncMessage { };
461461
Blocked blockedMessage = new Blocked { };
462462

463-
blockedMessage.Numbers.AddRange(blocked.getNumbers());
463+
blockedMessage.Numbers.AddRange(blocked.Numbers);
464464
syncMessage.Blocked = blockedMessage;
465465
content.SyncMessage = syncMessage;
466466
return content.ToByteArray();
@@ -516,7 +516,7 @@ private byte[] CreateMultiDeviceVerifiedContent(VerifiedMessage verifiedMessage,
516516
private SyncMessage CreateSyncMessage()
517517
{
518518
SyncMessage syncMessage = new SyncMessage { };
519-
syncMessage.Padding = ByteString.CopyFrom(Util.getRandomLengthBytes(512));
519+
syncMessage.Padding = ByteString.CopyFrom(Util.GetRandomLengthBytes(512));
520520
return syncMessage;
521521
}
522522

@@ -603,17 +603,11 @@ private SendMessageResponse SendMessage(SignalServiceAddress recipient, long tim
603603
}
604604
catch (MismatchedDevicesException mde)
605605
{
606-
Debug.WriteLine("MismatchedDevicesException");
607-
Debug.WriteLine(mde.Message);
608-
Debug.WriteLine(mde.StackTrace);
609606
HandleMismatchedDevices(socket, recipient, mde.MismatchedDevices);
610607
}
611608
catch (StaleDevicesException ste)
612609
{
613-
Debug.WriteLine("MismatchedDevicesException");
614-
Debug.WriteLine(ste.Message);
615-
Debug.WriteLine(ste.StackTrace);
616-
HandleStaleDevices(recipient, ste.getStaleDevices());
610+
HandleStaleDevices(recipient, ste.StaleDevices);
617611
}
618612
}
619613
Debug.WriteLine("Failed to resolve conflicts after 3 attempts!");
@@ -648,7 +642,7 @@ private IList<AttachmentPointer> CreateAttachmentPointers(List<SignalServiceAtta
648642

649643
private AttachmentPointer CreateAttachmentPointer(SignalServiceAttachmentStream attachment)
650644
{
651-
byte[] attachmentKey = Util.getSecretBytes(64);
645+
byte[] attachmentKey = Util.GetSecretBytes(64);
652646
long paddedLength = PaddingInputStream.GetPaddedSize(attachment.Length);
653647
long ciphertextLength = AttachmentCipherInputStream.GetCiphertextLength(paddedLength);
654648
PushAttachmentData attachmentData = new PushAttachmentData(attachment.getContentType(),
@@ -749,14 +743,14 @@ private OutgoingPushMessageList GetEncryptedMessages(PushServiceSocket socket,
749743
List<OutgoingPushMessage> messages = new List<OutgoingPushMessage>();
750744

751745
bool myself = recipient.Equals(localAddress);
752-
if (!myself || CredentialsProvider.GetDeviceId() != SignalServiceAddress.DEFAULT_DEVICE_ID)
746+
if (!myself || CredentialsProvider.DeviceId != SignalServiceAddress.DEFAULT_DEVICE_ID)
753747
{
754748
messages.Add(GetEncryptedMessage(socket, recipient, SignalServiceAddress.DEFAULT_DEVICE_ID, plaintext, silent));
755749
}
756750

757751
foreach (uint deviceId in store.GetSubDeviceSessions(recipient.E164number))
758752
{
759-
if (!myself || deviceId != CredentialsProvider.GetDeviceId())
753+
if (!myself || deviceId != CredentialsProvider.DeviceId)
760754
{
761755
if (store.ContainsSession(new SignalProtocolAddress(recipient.E164number, deviceId)))
762756
{
@@ -781,7 +775,7 @@ private OutgoingPushMessage GetEncryptedMessage(PushServiceSocket socket, Signal
781775

782776
foreach (PreKeyBundle preKey in preKeys)
783777
{
784-
if (CredentialsProvider.GetUser().Equals(recipient.E164number) && CredentialsProvider.GetDeviceId() == preKey.getDeviceId())
778+
if (CredentialsProvider.User.Equals(recipient.E164number) && CredentialsProvider.DeviceId == preKey.getDeviceId())
785779
{
786780
continue;
787781
}

libsignal-service-dotnet/configuration/SignalCdnUrl.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44

55
namespace libsignalservice.configuration
66
{
7+
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
78
public class SignalCdnUrl : SignalUrl
89
{
910
public SignalCdnUrl(string url) : base(url) { }
1011

1112
public SignalCdnUrl(string url, string hostHeader) : base(url, hostHeader) { }
1213
}
14+
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
1315
}

0 commit comments

Comments
 (0)