Example #1
0
        private RelayConfig GetRelayConfig(ConDepRelayOptions relayOptions, ConDepOptions deployOptions)
        {
            if (relayOptions.HasAllOptionsSet())
            {
                return new RelayConfig
                       {
                           AccessKey    = relayOptions.AccessKey,
                           AccessSecret = relayOptions.AccessSecret,
                           Origin       = relayOptions.Origin,
                           RelayId      = relayOptions.RelayId
                       }
            }
            ;

            var path = !string.IsNullOrWhiteSpace(relayOptions.RelayConfigPath)
        ? relayOptions.RelayConfigPath
        : Path.Combine(Path.GetDirectoryName(GetType().Assembly.Location), "relay.json");

            if (!File.Exists(path))
            {
                throw new FileNotFoundException("");
            }

            var serializer = new JsonSerializer <RelayConfig>(new JsonConfigCrypto(deployOptions.CryptoKey));

            return(serializer.DeSerialize(File.OpenRead(path)));
        }
Example #2
0
        public async Task <ReleaseInfo> GetNewestSyrupFileInfo(string url)
        {
            var json = await DownloadString(url);

            var l = JsonSerializer <List <ReleaseInfo> > .DeSerialize(json);

            return(l.OrderByDescending(x => SemVersion.Parse(x.SemVer)).FirstOrDefault());
        }
Example #3
0
        public async Task <List <ReleaseInfo> > GetListSyrupFileInfos(string url)
        {
            var json = await DownloadString(url);

            var l = JsonSerializer <List <ReleaseInfo> > .DeSerialize(json);

            return(l);
        }
        public async Task SimpleTest()
        {
            var json = await DownloadString(url);

            var l = JsonSerializer <List <ReleaseInfo> > .DeSerialize(json);

            var max = l.OrderByDescending(x => SemVersion.Parse(x.SemVer));
        }
Example #5
0
        public static T Read <T>() where T : class
        {
            Type classInterfaceType = typeof(T);

            string filename = Paths.CurrentDirectory + FolderName + @"\" + classInterfaceType.Name + ".json";
            string json     = File.ReadAllText(filename);

            return(JsonSerializer <T> .DeSerialize(json));
        }
Example #6
0
        public Config GetConfig()
        {
            var syrupDir       = SyrupAndAppFinder.Instance.SyrupDirectoryPath;
            var configFilePath = Path.Combine(syrupDir, Consts.SYRUP_CONFIG_FILE);
            var json           = File.ReadAllText(configFilePath);
            var config         = JsonSerializer <Config> .DeSerialize(json);

            return(config);
        }
Example #7
0
        public void TestThatEncryptTagGetsEncrypted()
        {
            var crypto        = new JsonConfigCrypto(_cryptoKey);
            var encryptedJson = crypto.Encrypt(_encryptJson);

            var decryptedJson = crypto.Decrypt(encryptedJson);

            var serializer = new JsonSerializer <ConDepEnvConfig>(crypto);

            serializer.DeSerialize(decryptedJson);
        }
Example #8
0
        public void Given_an_rpc_transaction_with_big_inputs_When_deserialized_to_hex_Then_is_successfully_compared()
        {
            // A json transaction as it's returned by the rpc method
            var param = new CoinParameters {
                CoinTag = "BTC", PublicKeyAddressVersion = 0, PrivateKeyVersion = 128
            };
            var builder        = TransactionBuilder.Create(param);
            var BigTransaction = File.OpenText(@"..\..\Resources\BigTransaction.json").ReadToEnd();
            var trx            = JsonSerializer.DeSerialize <DecodedRawTransaction>(BigTransaction);
            var rawTransaction = builder.Serializer.ToHex(builder.Parse(trx));

            Assert.AreEqual(trx.Hex, rawTransaction);
        }
Example #9
0
        public void Given_a_scriptpubkey_When_parsed_Then_should_compare_to_address()
        {
            var jsonTransaction = File.OpenText(@"..\..\Resources\Transaction.json").ReadToEnd();
            var trx             = JsonSerializer.DeSerialize <DecodedRawTransaction>(jsonTransaction);

            // Check we can extract the to address
            var pubkeyBytes = CryptoUtil.ConvertHex(trx.VOut.First().ScriptPubKey.Hex);
            var pubkey      = new Script(pubkeyBytes);

            Assert.AreEqual("DUP HASH160 PUSHDATA(20)[ec4cca42352bc39020ba2da4b49bff6a72b6a079] EQUALVERIFY CHECKSIG", pubkey.ToString());
            var toAddr = Address.Create(parameters, pubkey.GetPubKeyHash());

            Assert.AreEqual("1NYSTjub949EBYTc6oDgzTorkDp4ZMbyB7", toAddr.ToString());
        }
Example #10
0
        public void Given_an_rpc_coinbase_transaction_When_deserialized_from_hex_Then_is_successfully_compared()
        {
            // A json transaction as it's returned by the rpc method
            var param = new CoinParameters {
                CoinTag = "BTC", PublicKeyAddressVersion = 0, PrivateKeyVersion = 128
            };
            var builder = TransactionBuilder.Create(param);
            var jsonCoinbaseTransaction = File.OpenText(@"..\..\Resources\CoinbaseTransaction.json").ReadToEnd();
            var trx = JsonSerializer.DeSerialize <DecodedRawTransaction>(jsonCoinbaseTransaction);

            var decoded = builder.Serializer.FromHex(trx.Hex);

            CompareTransactions(decoded, builder.Parse(trx));
        }
Example #11
0
        public void Given_a_scriptsig_When_parsed_Then_should_compare_to_previous_address()
        {
            var jsonTransaction = File.OpenText(@"..\..\Resources\Transaction.json").ReadToEnd();
            var trx             = JsonSerializer.DeSerialize <DecodedRawTransaction>(jsonTransaction);

            var sigProgBytes = CryptoUtil.ConvertHex(trx.VIn.First().ScriptSig.Hex);

            ////byte[] sigProgBytes = CryptoUtil.ConvertHex(SigProg);
            var script = new Script(sigProgBytes);

            // Test we can extract the from address.
            var hash160 = AddressUtil.Sha256Hash160(script.GetPubKey());

            Assert.AreEqual("1BYRkxUK1m8fAqYU48AY62rRQpsJc34tX9", Address.Create(parameters, hash160).ToString());
        }
Example #12
0
        public void TestThatEncryptedJsonCanBeDecryptedIntoTypedConfig()
        {
            //var parser = new EnvConfigParser(new ConfigJsonSerializer(new JsonConfigCrypto()), new JsonConfigCrypto());
            var cryptoHandler = new JsonConfigCrypto(_cryptoKey);
            var serializer    = new JsonSerializer <ConDepEnvConfig>(cryptoHandler);

            //parser.Encrypted(_json, out config);
            var config = serializer.DeSerialize(_json);

            string deploymentPassword = config.DeploymentUser.Password;
            string lbPassword         = config.LoadBalancer.Password;

            var encryptedJson = cryptoHandler.Encrypt(_json);

            //parser.EncryptJsonConfig(config, crypto);

            //var encryptedJson = parser.ConvertToJsonText(config);
            Assert.That(cryptoHandler.IsEncrypted(encryptedJson), Is.True);

            var decryptedConfig = serializer.DeSerialize(encryptedJson);

            Assert.That(decryptedConfig.DeploymentUser.Password, Is.EqualTo(deploymentPassword));
            Assert.That(decryptedConfig.LoadBalancer.Password, Is.EqualTo(lbPassword));
        }
        public void TestThatEncryptTagGetsEncrypted()
        {
            var crypto = new JsonConfigCrypto(_cryptoKey);
            var encryptedJson = crypto.Encrypt(_encryptJson);

            var decryptedJson = crypto.Decrypt(encryptedJson);

            var serializer = new JsonSerializer<ConDepEnvConfig>(crypto);
            serializer.DeSerialize(decryptedJson);
        }
        public void TestThatEncryptedJsonCanBeDecryptedIntoTypedConfig()
        {
            //var parser = new EnvConfigParser(new ConfigJsonSerializer(new JsonConfigCrypto()), new JsonConfigCrypto());
            var cryptoHandler = new JsonConfigCrypto(_cryptoKey);
            var serializer = new JsonSerializer<ConDepEnvConfig>(cryptoHandler);

            //parser.Encrypted(_json, out config);
            var config = serializer.DeSerialize(_json);

            string deploymentPassword = config.DeploymentUser.Password;
            string lbPassword = config.LoadBalancer.Password;

            var encryptedJson = cryptoHandler.Encrypt(_json);

            //parser.EncryptJsonConfig(config, crypto);

            //var encryptedJson = parser.ConvertToJsonText(config);
            Assert.That(cryptoHandler.IsEncrypted(encryptedJson), Is.True);

            var decryptedConfig = serializer.DeSerialize(encryptedJson);

            Assert.That(decryptedConfig.DeploymentUser.Password, Is.EqualTo(deploymentPassword));
            Assert.That(decryptedConfig.LoadBalancer.Password, Is.EqualTo(lbPassword));
        }