public void PublicKeyWrapperTest()
 {
     using (var s = new Station(new TestUi(), "dataEncryption.key", "yo boii", 62001, "CoreDataTypesTestsPkWrapperVoters.sqlite")) {
         var originalKey = s.Crypto.Keys.Item1.Value;
         var pkWrapper   = new PublicKeyWrapper(s.Crypto, "batman");
         Assert.That(originalKey.Equals(pkWrapper.GetKey(s.Crypto, "batman").Value));
         try {
             pkWrapper.GetKey(s.Crypto, "wrongKey");
             Assert.Fail();
         }
         catch (ArgumentException) {}
     }
     File.Delete("CoreDataTypesTestsPkWrapperVoters.sqlite");
 }
Example #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PublicKeyExchangeCommand"/> class.
        /// May I have a new command that exchanges public keys with the target?
        /// </summary>
        /// <param name="parent">
        /// The parent station starting the exchange. Should be a manager.
        /// </param>
        /// <param name="isReply">
        /// Whether it's a reply from the target. Shouldn't be set manually. Set to false as default.
        /// </param>
        public PublicKeyExchangeCommand(Station parent, IPEndPoint destination, bool isReply = false)
        {
            Contract.Requires(parent != null);
            _isReply = isReply;
            Sender   = parent.Address;
            var pswd = Crypto.GeneratePassword();

            if (isReply)
            {
                parent.UI.ShowPasswordOnStation(pswd, destination);
            }
            else
            {
                parent.UI.ShowPasswordOnManager(pswd, destination);
            }
            _wrapper = new PublicKeyWrapper(parent.Crypto, pswd);
        }
Example #3
0
        /// <summary>
        ///   The public key wrapper test.
        /// </summary>
        [Test] public void PublicKeyWrapperTest()
        {
            File.Delete("CoreDataTypesTestsPkWrapperVoters.sqlite");
            using (var s = new Station(
                       new TestUi(),
                       SystemTestData.Key,
                       SystemTestData.Password,
                       SystemTestData.ManagerPort,
                       "CoreDataTypesTestsPkWrapperVoters.sqlite")) {
                AsymmetricKeyParameter originalKey = s.Crypto.KeyPair.Public;
                var pkWrapper = new PublicKeyWrapper(s.Crypto, "batman");
                Assert.That(originalKey.Equals(pkWrapper.GetKey(s.Crypto, "batman").Value));
                try {
                    pkWrapper.GetKey(s.Crypto, "wrongKey");
                    Assert.Fail();
                } catch (ArgumentException) { }
            }

            File.Delete("CoreDataTypesTestsPkWrapperVoters.sqlite");
        }