Skip to content

Commit f6a0c02

Browse files
authored
Merge pull request #2 from GovTechSG/development
Development
2 parents 0bb3127 + c497ab1 commit f6a0c02

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

ApiUtilLib/ApiAuthorization.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -220,23 +220,21 @@ public static long NewTimestamp()
220220
return dto.ToUnixTimeMilliseconds();
221221
}
222222

223-
public static long NewNonce()
223+
public static string NewNonce()
224224
{
225225
long nonce = 0;
226+
byte[] data = null;
226227
using (RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider())
227228
{
228229
// Buffer storage.
229-
byte[] data = new byte[8];
230+
data = new byte[8];
230231

231232
// Fill buffer.
232233
rng.GetBytes(data);
233-
234-
// Convert to int 64.
235-
nonce = BitConverter.ToInt64(data, 0);
236234
}
237235

238236
Logger.LogEnterExit(LoggerBase.Args(nonce.ToString()));
239-
return nonce;
237+
return System.Convert.ToBase64String(data);
240238
}
241239

242240
public static String Token(

ApiUtilLib/ApiList.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,22 @@ public string ToString(string delimiter = "&", bool sort = true, bool quote = fa
2525
if (sort)
2626
{
2727
// sort by key, than by value
28-
var sortedList = this.OrderBy(k => k.Key).ThenBy(v => v.Value);
28+
var sortedList = this.OrderBy(k => k.Key,StringComparer.Ordinal).ThenBy(v => v.Value,StringComparer.Ordinal); //Fixed issue to sort by capital letter.
29+
2930

3031
foreach (var item in sortedList)
3132
{
32-
list.Add(string.Format(format, item.Key, item.Value));
33+
format = "{0}={1}";
34+
if (quote) format = "{0}=\"{1}\"";
35+
36+
if (item.Value == null && !quote)
37+
{
38+
list.Add(string.Format("{0}", item.Key, item.Value));
39+
}
40+
else
41+
{
42+
list.Add(string.Format(format, item.Key, item.Value));
43+
}
3344
}
3445
}
3546
else

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@
33
## Added
44
### V1.0-SNAPSHOT
55
+ 2017-10-29 - Initial release.
6+
### V1.1-SNAPSHOT
7+
+ 2018-09-10 - Bug fixes to return basestring nonce value as basestring64 from integer value.
8+
### V1.2-SNAPSHOT
9+
+ 2018-09-13 - Bug fixes to sort list by ordinal comparison.

0 commit comments

Comments
 (0)