Commits

Devin Martin committed 79e6a64

Protected key tests for alternate MemoryProtectionScopes. Change the API method name.

Comments (0)

Files changed (4)

OtpSharp.Tests/ProtectedKeyTests.cs

             ProtectedMemory.Protect(originalCopy, MemoryProtectionScope.SameProcess);
             CollectionAssert.AreNotEqual(originalKey, originalCopy);
 
-            var pk = ProtectedKey.CreateProtectedKeyFromPreprotectedMemory(originalCopy, 16, MemoryProtectionScope.SameProcess);
+            var pk = ProtectedKey.CreateProtectedKeyFromPreProtectedMemory(originalCopy, 16, MemoryProtectionScope.SameProcess);
+
+            pk.UsePlainKey(key => CollectionAssert.AreEqual(originalKey, key));
+        }
+
+        [TestMethod]
+        public void ProtectedKey_ProtectKey_CrossProcess()
+        {
+            var originalKey = KeyGeneration.GenerateKey(16);
+            var originalCopy = new byte[16];
+            Array.Copy(originalKey, originalCopy, 16);
+            CollectionAssert.AreEqual(originalKey, originalCopy);
+
+            ProtectedMemory.Protect(originalCopy, MemoryProtectionScope.CrossProcess);
+            CollectionAssert.AreNotEqual(originalKey, originalCopy);
+
+            var pk = ProtectedKey.CreateProtectedKeyFromPreProtectedMemory(originalCopy, 16, MemoryProtectionScope.CrossProcess);
+
+            pk.UsePlainKey(key => CollectionAssert.AreEqual(originalKey, key));
+        }
+
+        [TestMethod]
+        public void ProtectedKey_ProtectKey_SameLogon()
+        {
+            var originalKey = KeyGeneration.GenerateKey(16);
+            var originalCopy = new byte[16];
+            Array.Copy(originalKey, originalCopy, 16);
+            CollectionAssert.AreEqual(originalKey, originalCopy);
+
+            ProtectedMemory.Protect(originalCopy, MemoryProtectionScope.SameLogon);
+            CollectionAssert.AreNotEqual(originalKey, originalCopy);
+
+            var pk = ProtectedKey.CreateProtectedKeyFromPreProtectedMemory(originalCopy, 16, MemoryProtectionScope.SameLogon);
 
             pk.UsePlainKey(key => CollectionAssert.AreEqual(originalKey, key));
         }
         [ExpectedException(typeof(ArgumentException))]
         public void ProtectedKey_ProtectKeyEmpty()
         {
-            var pk = ProtectedKey.CreateProtectedKeyFromPreprotectedMemory(new byte[] { }, 16, MemoryProtectionScope.SameProcess);
+            var pk = ProtectedKey.CreateProtectedKeyFromPreProtectedMemory(new byte[] { }, 16, MemoryProtectionScope.SameProcess);
+        }
+
+        [TestMethod]
+        [ExpectedException(typeof(ArgumentException))]
+        public void ProtectedKey_ProtectKeyZeroLength()
+        {
+            var pk = ProtectedKey.CreateProtectedKeyFromPreProtectedMemory(OtpCalculationTests.rfcTestKey, 0, MemoryProtectionScope.SameProcess);
         }
 
         [TestMethod]
         [ExpectedException(typeof(ArgumentNullException))]
         public void ProtectedKey_ProtectKeyNull()
         {
-            var pk = ProtectedKey.CreateProtectedKeyFromPreprotectedMemory(null, 16, MemoryProtectionScope.SameProcess);
+            var pk = ProtectedKey.CreateProtectedKeyFromPreProtectedMemory(null, 16, MemoryProtectionScope.SameProcess);
         }
 
         [TestMethod]
             ProtectedMemory.Protect(originalCopy, MemoryProtectionScope.SameProcess);
             CollectionAssert.AreNotEqual(originalKey, originalCopy);
 
-            var pk = ProtectedKey.CreateProtectedKeyFromPreprotectedMemory(originalCopy, 16, MemoryProtectionScope.SameProcess);
+            var pk = ProtectedKey.CreateProtectedKeyFromPreProtectedMemory(originalCopy, 16, MemoryProtectionScope.SameProcess);
 
             // The key is protected and un-protected several times.
             // Make sure that the key can be used multiple times.
             ProtectedMemory.Protect(originalCopy, MemoryProtectionScope.SameProcess);
             CollectionAssert.AreNotEqual(originalKey, originalCopy);
 
-            var pk = ProtectedKey.CreateProtectedKeyFromPreprotectedMemory(originalCopy, 20, MemoryProtectionScope.SameProcess);
+            var pk = ProtectedKey.CreateProtectedKeyFromPreProtectedMemory(originalCopy, 20, MemoryProtectionScope.SameProcess);
 
             pk.UsePlainKey(key => CollectionAssert.AreEqual(originalKey, key, "The unprotected plain key and the original key don't match"));
         }
                 {
                     tempKey = key;
                     CollectionAssert.AreEqual(OtpCalculationTests.rfcTestKey, tempKey);
-                    throw new ArgumentNullException();
+                    throw new ArgumentNullException(); // Throw a specific exception type of argument null as this is what is caught below
                 });
 
                 Assert.Fail("The exception should have diverted control away from here.");
             }
-            catch (ArgumentNullException)
+            catch (ArgumentNullException) // Catch a specific argument null exception so as not to catch assert exceptions if thrown
             {
                 CollectionAssert.AreNotEqual(OtpCalculationTests.rfcTestKey, tempKey);
             }
   </TestList>
   <TestList name="Protected Key" id="23f8b9b2-1d7c-4f71-9c5d-5c7af728efd6" parentListId="925e9ca5-3a1b-41be-8ef0-f1050bf4322e">
     <TestLinks>
+      <TestLink id="b72b0e1e-b961-31e1-1e09-ac63fac7894b" name="ProtectedKey_ProtectKey_SameLogon" storage="otpsharp.tests\bin\debug\otpsharp.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
+      <TestLink id="66a32921-9352-2b26-756e-395d9eaee5ef" name="ProtectedKey_Basic" storage="otpsharp.tests\bin\debug\otpsharp.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
+      <TestLink id="b254cc4f-2e57-5b8b-e313-14463abd2153" name="ProtectedKey_MultipleUse" storage="otpsharp.tests\bin\debug\otpsharp.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
+      <TestLink id="595055c8-7387-6d56-f168-5077c4b1d59c" name="ProtectedKey_SkipWipeReference" storage="otpsharp.tests\bin\debug\otpsharp.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
+      <TestLink id="75bc9899-9ec2-fcd5-d178-6066cc9ecee7" name="ProtectedKey_ProtectKey_CrossProcess" storage="otpsharp.tests\bin\debug\otpsharp.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
+      <TestLink id="d56330ac-ad64-a959-6fb0-1b5c5121973c" name="ProtectedKey_ProtectKeyWithSpecificLength" storage="otpsharp.tests\bin\debug\otpsharp.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
+      <TestLink id="ef1e487c-508e-101e-9e84-dfeaf9faec7b" name="ProtectedKey_ProtectKeyZeroLength" storage="otpsharp.tests\bin\debug\otpsharp.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
+      <TestLink id="42114568-ea9a-625c-bea7-970fd704e7cd" name="ProtectedKey_ProtectKeyEmpty" storage="otpsharp.tests\bin\debug\otpsharp.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
+      <TestLink id="5a4a33d3-8c8c-fea1-4281-a1c8bcc137b0" name="ProtectedKey_WipeReference" storage="otpsharp.tests\bin\debug\otpsharp.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
+      <TestLink id="f5cc6ba3-facf-ccc4-5b69-7e7df9419de4" name="ProtectedKey_UseKeyThrowExceptionWipeKey" storage="otpsharp.tests\bin\debug\otpsharp.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
+      <TestLink id="e7746551-65d0-f75c-1881-7e28189fce6a" name="ProtectedKey_UseKeyWipeTempKey" storage="otpsharp.tests\bin\debug\otpsharp.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
+      <TestLink id="d5e983df-fa01-e676-d2cb-315006b01e7b" name="ProtectedKey_EnsureOriginalkeyIntegrity" storage="otpsharp.tests\bin\debug\otpsharp.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
       <TestLink id="83114c11-bac0-01c2-aaa1-783727d5eeab" name="ProtectedKey_ProtectKey" storage="otpsharp.tests\bin\debug\otpsharp.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
-      <TestLink id="b254cc4f-2e57-5b8b-e313-14463abd2153" name="ProtectedKey_MultipleUse" storage="otpsharp.tests\bin\debug\otpsharp.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
-      <TestLink id="e7746551-65d0-f75c-1881-7e28189fce6a" name="ProtectedKey_UseKeyWipeTempKey" storage="otpsharp.tests\bin\debug\otpsharp.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
+      <TestLink id="27e0a263-92c0-c3af-ab39-4f060ae0f7dd" name="ProtectedKey_ProtectKeyNull" storage="otpsharp.tests\bin\debug\otpsharp.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
       <TestLink id="9c3fc269-e3c7-b57f-c08a-a301f8b35f1a" name="ProtectedKey_UseKeyWithNullDelegate" storage="otpsharp.tests\bin\debug\otpsharp.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
-      <TestLink id="66a32921-9352-2b26-756e-395d9eaee5ef" name="ProtectedKey_Basic" storage="otpsharp.tests\bin\debug\otpsharp.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
-      <TestLink id="f5cc6ba3-facf-ccc4-5b69-7e7df9419de4" name="ProtectedKey_UseKeyThrowExceptionWipeKey" storage="otpsharp.tests\bin\debug\otpsharp.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
-      <TestLink id="595055c8-7387-6d56-f168-5077c4b1d59c" name="ProtectedKey_SkipWipeReference" storage="otpsharp.tests\bin\debug\otpsharp.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
-      <TestLink id="5a4a33d3-8c8c-fea1-4281-a1c8bcc137b0" name="ProtectedKey_WipeReference" storage="otpsharp.tests\bin\debug\otpsharp.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
-      <TestLink id="d56330ac-ad64-a959-6fb0-1b5c5121973c" name="ProtectedKey_ProtectKeyWithSpecificLength" storage="otpsharp.tests\bin\debug\otpsharp.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
     </TestLinks>
   </TestList>
   <TestList name="Key Generation" id="2faa864c-1e21-4964-bc2f-c34cf03be62a" parentListId="925e9ca5-3a1b-41be-8ef0-f1050bf4322e">
   </TestList>
   <TestList name="Base 32" id="4c1a13b8-b445-4c68-8b02-eff2174082b0" parentListId="925e9ca5-3a1b-41be-8ef0-f1050bf4322e">
     <TestLinks>
-      <TestLink id="d9a42195-3c34-e849-8df9-8bd0c2f65be2" name="Base32Decoding" storage="otpsharp.tests\bin\debug\otpsharp.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
+      <TestLink id="565bbd3b-4c07-101d-4b2f-25f5af91efbd" name="Base32Decoding_EmptyString" storage="otpsharp.tests\bin\debug\otpsharp.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
       <TestLink id="15379218-50c0-971d-2539-ecb6e3ce0d42" name="Base32Encoding_Null" storage="otpsharp.tests\bin\debug\otpsharp.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
       <TestLink id="85197f0d-f9eb-ee70-6c33-33fc86f4ab8d" name="Base32Decoding_Unpadded" storage="otpsharp.tests\bin\debug\otpsharp.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
-      <TestLink id="565bbd3b-4c07-101d-4b2f-25f5af91efbd" name="Base32Decoding_EmptyString" storage="otpsharp.tests\bin\debug\otpsharp.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
+      <TestLink id="74cad199-bbc2-d582-548f-57ced3a21ab1" name="Base32Encoding_Empty" storage="otpsharp.tests\bin\debug\otpsharp.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
+      <TestLink id="d9a42195-3c34-e849-8df9-8bd0c2f65be2" name="Base32Decoding" storage="otpsharp.tests\bin\debug\otpsharp.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
       <TestLink id="3de071b6-dde6-a831-16ad-cf940f8c65f9" name="Base32Decoding_Null" storage="otpsharp.tests\bin\debug\otpsharp.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
+      <TestLink id="3ea19e30-abc0-3ee0-606f-458cd3f97506" name="Base32Encoding" storage="otpsharp.tests\bin\debug\otpsharp.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
       <TestLink id="e7e157d0-fd89-054f-84f3-5d159d91c730" name="Base32Decoding_IllegalCharacters" storage="otpsharp.tests\bin\debug\otpsharp.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
-      <TestLink id="3ea19e30-abc0-3ee0-606f-458cd3f97506" name="Base32Encoding" storage="otpsharp.tests\bin\debug\otpsharp.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
-      <TestLink id="74cad199-bbc2-d582-548f-57ced3a21ab1" name="Base32Encoding_Empty" storage="otpsharp.tests\bin\debug\otpsharp.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
       <TestLink id="b5e04664-ba29-ec21-5263-e9f07a2c0aa4" name="Base32Decoding_Empty" storage="otpsharp.tests\bin\debug\otpsharp.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
     </TestLinks>
   </TestList>
     <TestLinks>
       <TestLink id="7e457054-69c3-5c93-0900-6cd0612bab26" name="TotpUrl_DigitsTen" storage="otpsharp.tests\bin\debug\otpsharp.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
       <TestLink id="cd047fce-cf0d-c719-dd6c-c559903304bb" name="TotpUrl_Sha512" storage="otpsharp.tests\bin\debug\otpsharp.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
-      <TestLink id="425bb0c7-1494-6acf-58a6-a5bb06830744" name="TotpUrl_EmptyUser" storage="otpsharp.tests\bin\debug\otpsharp.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
+      <TestLink id="cad3d70b-b222-d482-8a2d-9b85108098b5" name="TotpUrl_Sha256" storage="otpsharp.tests\bin\debug\otpsharp.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
       <TestLink id="2040137d-5743-130e-afba-a9a78889bbfb" name="TotpUrl_Sha512AndStepSizeFifteenDigitsEight" storage="otpsharp.tests\bin\debug\otpsharp.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
       <TestLink id="b951e8a8-2368-2d84-e25b-175dc81a5a1f" name="TotpUrl_Sha512AndStepSizeFifteen" storage="otpsharp.tests\bin\debug\otpsharp.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
       <TestLink id="c4a6b5a6-e4e0-7e80-78ef-6c6f14f61615" name="TotpUrl_DigitsEight" storage="otpsharp.tests\bin\debug\otpsharp.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
       <TestLink id="5ade319a-7b66-62ee-3f1a-9ac579f7ba2e" name="TotpUrl" storage="otpsharp.tests\bin\debug\otpsharp.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
       <TestLink id="4315f2e2-072d-9ea1-355b-c6bc1dcdf0d1" name="TotpUrl_StepSizeFifteen" storage="otpsharp.tests\bin\debug\otpsharp.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
       <TestLink id="84f210d4-e57d-1575-f55c-c00a1e2a198c" name="TotpUrl_NullUser" storage="otpsharp.tests\bin\debug\otpsharp.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
-      <TestLink id="cad3d70b-b222-d482-8a2d-9b85108098b5" name="TotpUrl_Sha256" storage="otpsharp.tests\bin\debug\otpsharp.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
+      <TestLink id="425bb0c7-1494-6acf-58a6-a5bb06830744" name="TotpUrl_EmptyUser" storage="otpsharp.tests\bin\debug\otpsharp.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
       <TestLink id="08067570-fa6a-903b-6226-37560e218a4a" name="TotpUtcOverload" storage="otpsharp.tests\bin\debug\otpsharp.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
     </TestLinks>
   </TestList>
   <TestList name="OTP" id="5b487326-b7c1-4084-8b30-297b5878346f" parentListId="925e9ca5-3a1b-41be-8ef0-f1050bf4322e">
     <TestLinks>
+      <TestLink id="ba295ce8-1bba-cbd7-ba81-31acf68c684a" name="TotpTypeProperty" storage="otpsharp.tests\bin\debug\otpsharp.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
       <TestLink id="f4c82e7b-c6d3-1c00-ed21-701f740dbc15" name="StepSize_Fifteen" storage="otpsharp.tests\bin\debug\otpsharp.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
       <TestLink id="ffbea82f-ea4c-0d8e-b1b6-878e184c7168" name="Digits_Ten" storage="otpsharp.tests\bin\debug\otpsharp.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
-      <TestLink id="fde2e3db-9b16-a54f-3078-d11a15f615b9" name="HotpTypeProperty" storage="otpsharp.tests\bin\debug\otpsharp.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
       <TestLink id="50fc56de-ec0e-c1a8-3f2f-26c5e0f6b1dc" name="StepSize_Negative" storage="otpsharp.tests\bin\debug\otpsharp.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
       <TestLink id="f128974a-b87f-906d-168b-fc3140d98a8e" name="TotpAppendixBTests_ProtectedKey" storage="otpsharp.tests\bin\debug\otpsharp.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
       <TestLink id="846e8a5c-1cd2-29bc-328d-5f9e788f7a44" name="Digits_Zero" storage="otpsharp.tests\bin\debug\otpsharp.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
-      <TestLink id="ba295ce8-1bba-cbd7-ba81-31acf68c684a" name="TotpTypeProperty" storage="otpsharp.tests\bin\debug\otpsharp.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
+      <TestLink id="fde2e3db-9b16-a54f-3078-d11a15f615b9" name="HotpTypeProperty" storage="otpsharp.tests\bin\debug\otpsharp.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
+      <TestLink id="20d86c36-af4c-5b69-9baa-261739eaf6f7" name="Digits_Negative" storage="otpsharp.tests\bin\debug\otpsharp.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
+      <TestLink id="71467365-14ea-ead2-c604-d1627c70c06d" name="Digits_Eleven" storage="otpsharp.tests\bin\debug\otpsharp.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
+      <TestLink id="e88d2bc1-9eef-64cf-5dd8-f9062177f8a8" name="HotpAppendixDTests_ProtectedKey" storage="otpsharp.tests\bin\debug\otpsharp.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
       <TestLink id="e4eeb4a8-078e-1e6c-96d5-21f60d2a3ddd" name="StepSize_Zero" storage="otpsharp.tests\bin\debug\otpsharp.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
-      <TestLink id="20d86c36-af4c-5b69-9baa-261739eaf6f7" name="Digits_Negative" storage="otpsharp.tests\bin\debug\otpsharp.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
-      <TestLink id="e88d2bc1-9eef-64cf-5dd8-f9062177f8a8" name="HotpAppendixDTests_ProtectedKey" storage="otpsharp.tests\bin\debug\otpsharp.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
-      <TestLink id="71467365-14ea-ead2-c604-d1627c70c06d" name="Digits_Eleven" storage="otpsharp.tests\bin\debug\otpsharp.tests.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
     </TestLinks>
   </TestList>
   <TestList name="Time Correction" id="5b567812-482e-454d-bdf6-d9aad47d312a" parentListId="925e9ca5-3a1b-41be-8ef0-f1050bf4322e">

OtpSharp/Properties/AssemblyInfo.cs

 [assembly: AssemblyVersion("1.0.4")]
 [assembly: AssemblyFileVersion("1.0.4")]
 
-// allow the test assembly to unit test
+// allow the test assembly to unit test internals
 [assembly: InternalsVisibleTo("OtpSharp.Tests")]

OtpSharp/ProtectedKey.cs

         /// <summary>
         /// Creates an instance of the protected key from a byte array that has already been protected using the ProtectedMemory.Protect method call.
         /// </summary>
-        /// <remarks>
-        /// This must use the SameProcess protection scope or it won't work
-        /// </remarks>
         /// <param name="preProtectedKey">Pre-protected key data</param>
         /// <param name="keyLength">The length of the plaintext key (protected memory may need to be padded)</param>
         /// <param name="scope">The memory protection scope that was used to protect the memory</param>
         /// <returns>A protected key instance from the provided key</returns>
-        public static ProtectedKey CreateProtectedKeyFromPreprotectedMemory(byte[] preProtectedKey, int keyLength, MemoryProtectionScope scope)
+        public static ProtectedKey CreateProtectedKeyFromPreProtectedMemory(byte[] preProtectedKey, int keyLength, MemoryProtectionScope scope)
         {
             return new ProtectedKey(preProtectedKey, keyLength, scope);
         }
                 throw new ArgumentNullException("A secret key must be provided");
             if (!(preProtectedKey.Length > 0))
                 throw new ArgumentException("The key must not be empty");
+            if (!(keyLength > 0))
+                throw new ArgumentException("The key must not be empty");
 
             this.keyLength = keyLength;
             this.isProtected = true;