Skip to content

Commit f5df3b0

Browse files
committed
Add default constructor to PreKeyEntity
1 parent d8e13e0 commit f5df3b0

File tree

1 file changed

+56
-54
lines changed

1 file changed

+56
-54
lines changed
Lines changed: 56 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,60 @@
1-
using libsignal.ecc;
2-
using libsignalservice.util;
3-
using Newtonsoft.Json;
4-
using Newtonsoft.Json.Linq;
5-
6-
using System;
7-
8-
namespace libsignalservice.push
9-
{
1+
using libsignal.ecc;
2+
using libsignalservice.util;
3+
using Newtonsoft.Json;
4+
using Newtonsoft.Json.Linq;
5+
6+
using System;
7+
8+
namespace libsignalservice.push
9+
{
1010
[JsonObject(MemberSerialization.OptIn)]
1111
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
1212
public class PreKeyEntity
13-
{
14-
[JsonProperty("keyId")]
15-
public uint KeyId { get; set; }
16-
17-
[JsonProperty("publicKey")]
18-
[JsonConverter(typeof(ECPublicKeySerializer))]
19-
public ECPublicKey PublicKey { get; set; }
20-
21-
internal PreKeyEntity(uint keyId, ECPublicKey publicKey)
22-
{
23-
KeyId = keyId;
24-
PublicKey = publicKey;
25-
}
26-
27-
private class ECPublicKeySerializer : JsonConverter
28-
{
29-
public override bool CanConvert(Type objectType)
30-
{
31-
throw new NotImplementedException();
32-
}
33-
34-
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
35-
{
36-
try
37-
{
38-
var token = JToken.Load(reader);
39-
40-
string key = token.Value<string>();
41-
return Curve.decodePoint(Base64.DecodeWithoutPadding(key), 0);
42-
}
43-
catch (Exception e)
44-
{
45-
throw new Exception(e.Message);
46-
}
47-
}
48-
49-
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
50-
{
51-
ECPublicKey pubKey = (ECPublicKey)value;
52-
53-
writer.WriteValue(Base64.EncodeBytesWithoutPadding(pubKey.serialize()));
54-
}
55-
}
13+
{
14+
[JsonProperty("keyId")]
15+
public uint KeyId { get; set; }
16+
17+
[JsonProperty("publicKey")]
18+
[JsonConverter(typeof(ECPublicKeySerializer))]
19+
public ECPublicKey PublicKey { get; set; }
20+
21+
internal PreKeyEntity() { }
22+
23+
internal PreKeyEntity(uint keyId, ECPublicKey publicKey)
24+
{
25+
KeyId = keyId;
26+
PublicKey = publicKey;
27+
}
28+
29+
private class ECPublicKeySerializer : JsonConverter
30+
{
31+
public override bool CanConvert(Type objectType)
32+
{
33+
throw new NotImplementedException();
34+
}
35+
36+
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
37+
{
38+
try
39+
{
40+
var token = JToken.Load(reader);
41+
42+
string key = token.Value<string>();
43+
return Curve.decodePoint(Base64.DecodeWithoutPadding(key), 0);
44+
}
45+
catch (Exception e)
46+
{
47+
throw new Exception(e.Message);
48+
}
49+
}
50+
51+
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
52+
{
53+
ECPublicKey pubKey = (ECPublicKey)value;
54+
55+
writer.WriteValue(Base64.EncodeBytesWithoutPadding(pubKey.serialize()));
56+
}
57+
}
5658
}
57-
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
58-
}
59+
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
60+
}

0 commit comments

Comments
 (0)