public static string GetSignature(DigitalSignature digitalSignature) { if (digitalSignature == null || digitalSignature.Nickname == null || digitalSignature.PublicKey == null) { return(null); } try { if (digitalSignature.DigitalSignatureAlgorithm == DigitalSignatureAlgorithm.EcDsaP521_Sha256 || digitalSignature.DigitalSignatureAlgorithm == DigitalSignatureAlgorithm.Rsa2048_Sha256) { using (BufferStream bufferStream = new BufferStream(_bufferManager)) { Signature.WriteString(bufferStream, digitalSignature.Nickname); bufferStream.Write(digitalSignature.PublicKey, 0, digitalSignature.PublicKey.Length); bufferStream.Seek(0, SeekOrigin.Begin); var signature = digitalSignature.Nickname + "@" + NetworkConverter.ToBase64UrlString(Sha256.ComputeHash(bufferStream)); return(_signatureCache.GetValue(signature, digitalSignature)); } } return(null); } catch (Exception) { return(null); } }
public void Test_InternPool() { //var w = new WeakReference(new object()); Intern <object> rt = new Intern <object>(); { var target1 = rt.GetValue(new Uri("http://127.0.0.1/"), new object()); // Set var target2 = rt.GetValue(new Uri("http://127.0.0.1/"), new object()); Assert.IsTrue(object.ReferenceEquals(target1, target2)); } System.GC.Collect(); System.GC.WaitForPendingFinalizers(); System.GC.Collect(); rt.Refresh(); Assert.IsTrue(rt.Count == 0); }