File tree Expand file tree Collapse file tree 2 files changed +10
-5
lines changed
Mastercard.Developer.OAuth1Signer.Core
Mastercard.Developer.OAuth1Signer.Tests Expand file tree Collapse file tree 2 files changed +10
-5
lines changed Original file line number Diff line number Diff line change 11using System ;
22using System . Collections . Generic ;
3+ using System . Linq ;
34using System . Security . Cryptography ;
45using System . Text ;
56using Mastercard . Developer . OAuth1Signer . Core . Utils ;
@@ -13,6 +14,7 @@ namespace Mastercard.Developer.OAuth1Signer.Core
1314 public static class OAuth
1415 {
1516 public const string AuthorizationHeaderName = "Authorization" ;
17+ private static readonly Random Random = new Random ( ) ;
1618
1719 /// <summary>
1820 /// Creates a Mastercard API compliant OAuth Authorization header.
@@ -210,9 +212,9 @@ private static byte[] Sha256Digest(string input, Encoding encoding)
210212 }
211213
212214 /// <summary>
213- /// Generates a random string for replay protection as per https://tools.ietf.org/html/rfc5849#section-3.3.
215+ /// Generates a 16 char random string for replay protection as per https://tools.ietf.org/html/rfc5849#section-3.3.
214216 /// </summary>
215- internal static string GetNonce ( ) => Guid . NewGuid ( ) . ToString ( ) . Replace ( "-" , string . Empty ) ;
217+ internal static string GetNonce ( ) => string . Concat ( Enumerable . Range ( 0 , 16 ) . Select ( _ => Random . Next ( 16 ) . ToString ( "x" ) ) ) ;
216218
217219 /// <summary>
218220 /// Returns UNIX Timestamp as required per https://tools.ietf.org/html/rfc5849#section-3.3.
Original file line number Diff line number Diff line change @@ -173,10 +173,13 @@ public void TestToUriRfc3986()
173173 }
174174
175175 [ TestMethod ]
176- public void TestGetNonce_ShouldHaveLengthOf32 ( )
176+ public void TestGetNonce_ShouldHaveLengthOf16 ( )
177177 {
178- var nonce = OAuth . GetNonce ( ) ;
179- Assert . AreEqual ( 32 , nonce . Length ) ;
178+ Enumerable . Range ( 0 , 100000 ) . ToList ( ) . ForEach ( _ =>
179+ {
180+ var nonce = OAuth . GetNonce ( ) ;
181+ Assert . AreEqual ( 16 , nonce . Length ) ;
182+ } ) ;
180183 }
181184 }
182185}
You can’t perform that action at this time.
0 commit comments