Skip to content

Commit ba096d0

Browse files
crimsonredClient Engineering Bot
andauthored
Remove BouncyCastle, JsonFx.Json, MarkerMetro and crypto DLLs. (#56)
* Remove BouncyCastle, JsonFx.Json, MarkerMetro and crypto DLLs. Features works without the need of these libs. * PubNub SDK v6.0.1 release. * Update PlayModeCommon.cs Co-authored-by: Client Engineering Bot <Client Engineering [email protected]>
1 parent 71dc2b9 commit ba096d0

17 files changed

+17
-354
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,4 @@ Thumbs.db
6767

6868
unity_installer_cache
6969
logs
70+
.vscode

.pubnub.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
---
2-
version: v6.0.0
2+
version: v6.0.1
33
changelog:
4+
- date: 2021-11-30
5+
version: v6.0.1
6+
changes:
7+
- type: improvement
8+
text: "Remove BouncyCastle, JsonFx.Json, MarkerMetro and crypto DLLs. Features works without the need of these libs."
49
-
510
changes:
611
-

PubNubUnity/Assets/PubNub/Crypto/MD5.cs

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,7 @@
33
using System.Text;
44
using System.Text.RegularExpressions;
55
using System.Globalization;
6-
#if UNITY_WSA || UNITY_WSA_8_1 || UNITY_WSA_10_0
7-
using Org.BouncyCastle.Crypto;
8-
using Org.BouncyCastle.Crypto.Parameters;
9-
using Org.BouncyCastle.Security;
10-
#else
116
using System.Security.Cryptography;
12-
#endif
137

148
namespace PubNubAPI
159
{
@@ -676,27 +670,6 @@ protected string EncodeNonAsciiCharacters (string value)
676670
return sb.ToString ();
677671
}
678672

679-
#if UNITY_WSA || UNITY_WSA_8_1 || UNITY_WSA_10_0
680-
public string PubnubAccessManagerSign(string key, string data)
681-
{
682-
string secret = key;
683-
string message = data;
684-
685-
var encoding = new System.Text.UTF8Encoding();
686-
byte[] keyByte = encoding.GetBytes(secret);
687-
byte[] messageBytes = encoding.GetBytes(message);
688-
689-
//http://mycsharp.de/wbb2/thread.php?postid=3550104
690-
KeyParameter paramKey = new KeyParameter(keyByte);
691-
IMac mac = MacUtilities.GetMac("HMac-SHA256");
692-
mac.Init(paramKey);
693-
mac.Reset();
694-
mac.BlockUpdate(messageBytes, 0, messageBytes.Length);
695-
byte[] hashmessage = new byte[mac.GetMacSize()];
696-
mac.DoFinal(hashmessage, 0);
697-
return Convert.ToBase64String(hashmessage).Replace('+', '-').Replace('/', '_');
698-
}
699-
#else
700673
public string PubnubAccessManagerSign (string key, string data)
701674
{
702675
string secret = key;
@@ -711,7 +684,6 @@ public string PubnubAccessManagerSign (string key, string data)
711684
return Convert.ToBase64String (hashmessage).Replace ('+', '-').Replace ('/', '_');
712685
}
713686
}
714-
#endif
715687
}
716688
#endregion
717689
}

PubNubUnity/Assets/PubNub/Crypto/PubnubCrypto.cs

Lines changed: 0 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,6 @@
11
using System;
22
using System.Text;
3-
4-
#if UNITY_WSA || UNITY_WSA_8_1 || UNITY_WSA_10_0
5-
using Org.BouncyCastle.Crypto.Digests;
6-
using Org.BouncyCastle.Crypto.Engines;
7-
using Org.BouncyCastle.Crypto.Modes;
8-
using Org.BouncyCastle.Crypto.Paddings;
9-
using Org.BouncyCastle.Crypto.Parameters;
10-
using Org.BouncyCastle.Security;
11-
#endif
123
using System.Security.Cryptography;
13-
144
using System.IO;
155

166
namespace PubNubAPI
@@ -111,110 +101,7 @@ public bool EncryptOrDecryptFile(bool encrypt, byte[] iv, string filePath, strin
111101

112102
return true;
113103
}
114-
115-
#if UNITY_WSA || UNITY_WSA_8_1 || UNITY_WSA_10_0
116-
public override string ComputeHashRaw(string input)
117-
{
118-
Sha256Digest algorithm = new Sha256Digest();
119-
Byte[] inputBytes = System.Text.Encoding.UTF8.GetBytes(input);
120-
Byte[] bufferBytes = new byte[algorithm.GetDigestSize()];
121-
algorithm.BlockUpdate(inputBytes, 0, inputBytes.Length);
122-
algorithm.DoFinal(bufferBytes, 0);
123-
return BitConverter.ToString(bufferBytes);
124-
}
125-
126-
protected override string EncryptOrDecrypt(bool type, string plainStr)
127-
{
128-
//Demo params
129-
string keyString = GetEncryptionKey();
130-
131-
string input = plainStr;
132-
byte[] inputBytes;
133-
byte[] keyBytes = System.Text.Encoding.UTF8.GetBytes(keyString);
134-
135-
//Set up
136-
AesEngine engine = new AesEngine();
137-
CbcBlockCipher blockCipher = new CbcBlockCipher(engine); //CBC
138-
PaddedBufferedBlockCipher cipher = new PaddedBufferedBlockCipher(blockCipher); //Default scheme is PKCS5/PKCS7
139-
KeyParameter keyParam = new KeyParameter(keyBytes);
140-
141-
if (type)
142-
{
143-
// Encrypt
144-
byte[] iv = new byte[16];
145-
if(UseRandomInitializationVector){
146-
// Generate IV here
147-
iv = new byte[16];
148-
SecureRandom sr = new SecureRandom();
149-
sr.NextBytes(iv);
150-
151-
152-
} else {
153-
iv = System.Text.Encoding.ASCII.GetBytes("0123456789012345");
154-
}
155-
156-
ParametersWithIV keyParamWithIV = new ParametersWithIV(keyParam, iv, 0, iv.Length);
157-
158-
input = EncodeNonAsciiCharacters(input);
159-
inputBytes = Encoding.UTF8.GetBytes(input);
160-
cipher.Init(true, keyParamWithIV);
161-
byte[] outputBytes = new byte[cipher.GetOutputSize(inputBytes.Length)];
162-
int length = cipher.ProcessBytes(inputBytes, outputBytes, 0);
163-
cipher.DoFinal(outputBytes, length); //Do the final block
164-
165-
if(UseRandomInitializationVector){
166-
// Add IV
167-
byte[] message = new byte[outputBytes.Length + iv.Length];
168-
System.Buffer.BlockCopy(iv, 0, message, 0, iv.Length);
169-
System.Buffer.BlockCopy(outputBytes, 0, message, iv.Length, outputBytes.Length);
170-
outputBytes = new byte[message.Length];
171-
System.Buffer.BlockCopy(message, 0, outputBytes, 0, message.Length);
172-
}
173104

174-
return Convert.ToBase64String(outputBytes);
175-
}
176-
else
177-
{
178-
try
179-
{
180-
//Decrypt
181-
182-
inputBytes = Convert.FromBase64CharArray(input.ToCharArray(), 0, input.Length);
183-
byte[] iv = new byte[16];
184-
185-
if(UseRandomInitializationVector){
186-
// Extract IV here
187-
System.Buffer.BlockCopy(inputBytes, 0, iv, 0, 16);
188-
byte[] message = new byte[inputBytes.Length - 16];
189-
System.Buffer.BlockCopy(inputBytes, 16, message, 0, inputBytes.Length-16);
190-
inputBytes = new byte[message.Length];
191-
System.Buffer.BlockCopy(message, 0, inputBytes, 0, message.Length);
192-
193-
} else {
194-
iv = System.Text.Encoding.ASCII.GetBytes("0123456789012345");
195-
}
196-
197-
ParametersWithIV keyParamWithIV = new ParametersWithIV(keyParam, iv, 0, iv.Length);
198-
199-
cipher.Init(false, keyParamWithIV);
200-
byte[] encryptedBytes = new byte[cipher.GetOutputSize(inputBytes.Length)];
201-
int encryptLength = cipher.ProcessBytes(inputBytes, encryptedBytes, 0);
202-
int numOfOutputBytes = cipher.DoFinal(encryptedBytes, encryptLength); //Do the final block
203-
int len = Array.IndexOf(encryptedBytes, (byte)0);
204-
len = (len == -1) ? encryptedBytes.Length : len;
205-
return Encoding.UTF8.GetString(encryptedBytes, 0, len);
206-
207-
}
208-
catch (Exception ex)
209-
{
210-
#if (ENABLE_PUBNUB_LOGGING)
211-
pnLog.WriteToLog(string.Format("Decrypt Error. {0}", ex.ToString()), PNLoggingMethod.LevelVerbose);
212-
#endif
213-
throw ex;
214-
}
215-
}
216-
}
217-
#else
218105
public override string ComputeHashRaw (string input)
219106
{
220107
#if (SILVERLIGHT || WINDOWS_PHONE || MONOTOUCH || __IOS__ || MONODROID || __ANDROID__ || UNITY_STANDALONE || UNITY_WEBPLAYER || UNITY_IOS || UNITY_ANDROID || UNITY_5 || UNITY_WEBGL)
@@ -299,9 +186,6 @@ protected override string EncryptOrDecrypt (bool type, string plainStr)
299186
}
300187
}
301188
}
302-
303-
#endif
304-
305189
}
306190
#endregion
307191
}

PubNubUnity/Assets/PubNub/PlayModeTests/PlayModeCommon.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace PubNubAPI.Tests
99
{
1010

11+
#if !UNITY_WSA && !UNITY_WSA_10_0
1112
class PubnubDemoObject
1213
{
1314
public double VersionID {get; set;}
@@ -109,4 +110,5 @@ public static PNConfiguration SetPNConfig(bool useCipher, bool withPAM){
109110

110111

111112
}
112-
}
113+
#endif
114+
}

PubNubUnity/Assets/PubNub/PlayModeTests/PlayModeTests.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
using UnityEngine;
1+
#if !UNITY_WSA && !UNITY_WSA_10_0
2+
using UnityEngine;
23
using UnityEngine.TestTools;
3-
using NUnit.Framework;
44
using System.Collections;
55
using System.Collections.Generic;
66
using System;
77
using System.Text;
88
using System.IO;
99
using System.Linq;
10+
using NUnit.Framework;
1011

1112
namespace PubNubAPI.Tests
1213
{
@@ -5917,3 +5918,4 @@ public IEnumerator TestGrantToken() {
59175918

59185919
}
59195920
}
5921+
#endif

PubNubUnity/Assets/PubNub/PubNubUnity/PubNubUnityBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace PubNubAPI
77
public class PubNubUnityBase
88
{
99
protected Counter publishMessageCounter;
10-
private const string build = "6.0.0";
10+
private const string build = "6.0.1";
1111
private string pnsdkVersion = string.Format ("PubNub-CSharp-Unity/{0}", build);
1212

1313
public string Version {
Binary file not shown.

PubNubUnity/Assets/PubNub/ThirdParty/BouncyCastle.dll.meta

Lines changed: 0 additions & 122 deletions
This file was deleted.
Binary file not shown.

0 commit comments

Comments
 (0)