Пример #1
0
        public void TestHashIds()
        {
            var configuration = MockBuilder.BuildConfiguration();
            var hashId        = new HashKeys(configuration.EncryptionSalt);
            var encrypted     = hashId.Encrypt(12345);
            var decrypt       = hashId.Decrypt(encrypted);

            Assert.AreEqual(decrypt, 12345);
        }
Пример #2
0
            public HashKeyCondition AddHashKeyCondition(ExpressionAttributeName attrName, ExpressionAttributeValue attrValue)
            {
                var hashKey = new HashKey
                {
                    ExpressionAttributeName  = attrName,
                    ExpressionAttributeValue = attrValue,
                };

                var hashKeyCondition = new HashKeyCondition(hashKey);

                HashKeys.Add(hashKey, hashKeyCondition);

                return(hashKeyCondition);
            }
        public void Generating_new_keys_with_UserId_should_succeed()
        {
            // arrange
            var userId        = "my_fany_user_id";
            var hashAlgorithm = "MD5";
            var hmacAlgorithm = "HMACSHA256";

            // action
            var keys = HashKeys.GenerateHashKeys(userId, hashAlgorithm, hmacAlgorithm);

            // assert
            keys.UserId.ShouldNotBeNull();
            keys.UserId.ShouldMatch(userId);
        }
        public void Generating_new_keys_without_specifying_an_APPId_should_succeed()
        {
            // arrange
            var userId        = "1";
            var hashAlgorithm = "MD5";
            var hmacAlgorithm = "HMACSHA256";

            // action
            var keys = HashKeys.GenerateHashKeys(userId, hashAlgorithm, hmacAlgorithm);

            // assert
            keys.APPId.ShouldNotBeNull();
            keys.APPId.ShouldNotBeEmpty();
        }
        public void Generating_HMACSHA_384_keys_should_succeed()
        {
            // arrange
            var userId        = "";
            var hashAlgorithm = "MD5";
            var hmacAlgorithm = "HMACSHA384";

            // action
            var keys = HashKeys.GenerateHashKeys(userId, hashAlgorithm, hmacAlgorithm);

            // assert
            keys.ApiKey.ShouldNotBeNull();
            keys.ApiKey.ShouldNotBeEmpty();
            Convert.FromBase64String(keys.ApiKey).Length.ShouldBe(384 / 8);
        }
        public void Generating_new_keys_by_specifying_an_APPId_should_succeed()
        {
            // arrange
            var userId        = "2";
            var hashAlgorithm = "MD5";
            var hmacAlgorithm = "HMACSHA256";
            var appId         = "my_fancy_new_apikey";

            // action
            var keys = HashKeys.GenerateHashKeys(userId, hashAlgorithm, hmacAlgorithm, appId);

            // assert
            keys.APPId.ShouldNotBeNull();
            keys.APPId.ShouldMatch(appId);
        }
        public void Signing_with_null_message_body_should_succeed()
        {
            // arrange
            var signer     = new Signer();
            var hashKeys   = HashKeys.GenerateHashKeys("747D1358-89E4-4A49-BFB3-65E020D1D4BD", "MD5", "HMACSHA256", "MY_APPID");
            var authHeader = new AuthorizationHeader(hashKeys.APPId);
            var httpMethod = "GET";
            var requstUrl  = @"https:\\LOCALHOST\MyApi\WonderLand";

            // action
            var signature = signer.Sign(requstUrl, httpMethod, null, authHeader, hashKeys);

            // assert
            signature.ShouldNotBeNull();
            signature.ShouldNotBeEmpty();
            signature.Length.ShouldBe(44);
        }
        public void Signing_with_same_url_with_different_casing_should_not_generate_same_signatures()
        {
            // arrange
            var signer     = new Signer();
            var hashKeys   = HashKeys.GenerateHashKeys("747D1358-89E4-4A49-BFB3-65E020D1D4BD", "MD5", "HMACSHA256", "MY_APPID");
            var authHeader = new AuthorizationHeader(hashKeys.APPId);
            var httpMethod = "GET";
            var requstUrl1 = @"HTTPS:\\localhost\MYAPI\WONDERLAND";
            var requstUrl2 = @"https:\\LOCALHOST\MyApi\wonderland";

            // action
            var signature1 = signer.Sign(requstUrl1, httpMethod, null, authHeader, hashKeys);
            var signature2 = signer.Sign(requstUrl2, httpMethod, null, authHeader, hashKeys);

            // assert
            signature1.ShouldNotBe(signature2);
        }
        public void Signing_async_with_should_succeedAsync()
        {
            // arrange
            var signer     = new Signer();
            var hashKeys   = new HashKeys("ae5d53eb-e000-4de0-93a9-a70aa61300bf", "E0wMj/lLap3nmzOVYQUKdOlo/EuQRsFh76gxAaPRqZk=", "MD5", "HMACSHA256", "4735e15e-b85c-4010-b641-5736e9483b03");
            var authHeader = new AuthorizationHeader(hashKeys.APPId);
            var request    = new HttpRequestMessage {
                Content = null, Method = HttpMethod.Get, RequestUri = new Uri("https://localhost:44321/HealthData/shared", UriKind.Absolute)
            };

            // action
            var signature = signer.SignAsync(request, authHeader, hashKeys).Result;

            // assert
            signature.ShouldNotBeNull();
            signature.ShouldNotBeEmpty();
            signature.Length.ShouldBe(44);
        }
Пример #10
0
    // Start is called before the first frame update
    public override void Start()
    {
        RControllerEvents = RController.GetComponent <VRTK_ControllerEvents>();
        LControllerEvents = LController.GetComponent <VRTK_ControllerEvents>();

        buttonsHashed = new Hashtable();

        textScreens[0].SetActive(true);

        for (int i = 0; i < buttons.Length; i++)
        {
            HashKeys key = (HashKeys)System.Enum.Parse(typeof(HashKeys), buttons[i].hand.ToString() + "_" + buttons[i].tag.ToString());
            buttonsHashed.Add(key, buttons[i].button);
        }

        isDone = false;
        InputTracking.Recenter();

        StartCoroutine(Wait());
    }
Пример #11
0
            public bool RemoveKey(IKey key)
            {
                if (key is HashKey hashKey && HashKeys.ContainsKey(hashKey))
                {
                    Leave(hashKey.ExpressionAttributeName);
                    Leave(hashKey.ExpressionAttributeValue);

                    return(HashKeys.Remove(hashKey));
                }

                if (key is SortKey sortKey && SortKeys.ContainsKey(sortKey))
                {
                    Leave(sortKey.ExpressionAttributeName);
                    Leave(sortKey.ExpressionAttributeValue);
                    Leave(sortKey.ExpressionAttributeValue2);

                    return(SortKeys.Remove(sortKey));
                }

                return(false);
            }
Пример #12
0
        private void LoadTableInfo()
        {
            ClearTableData();

            var              tableInfoCache = SdkCache.GetCache <string, TableDescription>(DDBClient, TableInfoCacheIdentifier, StringComparer.Ordinal);
            bool             staleCacheData;
            TableDescription table = tableInfoCache.GetValue(TableName, this.DescribeTable, out staleCacheData);

            if (staleCacheData)
            {
                var logger = Logger.GetLogger(typeof(Table));
                logger.InfoFormat("Description for table [{0}] loaded from SDK Cache", TableName);
            }

            foreach (var key in table.KeySchema)
            {
                string keyName = key.AttributeName;
                AttributeDefinition attributeDefinition = table.AttributeDefinitions
                                                          .FirstOrDefault(a => string.Equals(a.AttributeName, keyName, StringComparison.Ordinal));
                if (attributeDefinition == null)
                {
                    throw new InvalidOperationException("No attribute definition found for key " + key.AttributeName);
                }
                KeyDescription keyDescription = new KeyDescription
                {
                    IsHash = string.Equals(key.KeyType, "HASH", StringComparison.OrdinalIgnoreCase),
                    Type   = GetType(attributeDefinition.AttributeType)
                };
                if (keyDescription.IsHash)
                {
                    HashKeys.Add(keyName);
                }
                else
                {
                    RangeKeys.Add(keyName);
                }
                Keys[keyName] = keyDescription;
            }

            if (table.LocalSecondaryIndexes != null)
            {
                foreach (var index in table.LocalSecondaryIndexes)
                {
                    LocalSecondaryIndexes[index.IndexName] = index;
                    LocalSecondaryIndexNames.Add(index.IndexName);
                }
            }

            if (table.GlobalSecondaryIndexes != null)
            {
                foreach (var index in table.GlobalSecondaryIndexes)
                {
                    GlobalSecondaryIndexes[index.IndexName] = index;
                    GlobalSecondaryIndexNames.Add(index.IndexName);
                }
            }

            foreach (var attribute in table.AttributeDefinitions)
            {
                Attributes.Add(attribute);
            }
        }
Пример #13
0
        private void GetTableInfo()
        {
            DescribeTableRequest req = new DescribeTableRequest
            {
                TableName = TableName
            };

            req.BeforeRequestEvent += new RequestEventHandler(this.UserAgentRequestEventHandlerSync);
            DescribeTableResult info = this.DDBClient.DescribeTable(req);

            if (info.Table == null)
            {
                throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Table name {0} does not exist", TableName));
            }

            Keys.Clear();
            HashKeys.Clear();
            RangeKeys.Clear();
            TableDescription table = info.Table;

            foreach (var key in table.KeySchema)
            {
                string keyName = key.AttributeName;
                AttributeDefinition attributeDefinition = table.AttributeDefinitions
                                                          .FirstOrDefault(a => string.Equals(a.AttributeName, keyName, StringComparison.Ordinal));
                if (attributeDefinition == null)
                {
                    throw new InvalidOperationException("No attribute definition found for key " + key.AttributeName);
                }
                KeyDescription keyDescription = new KeyDescription
                {
                    IsHash = string.Equals(key.KeyType, "HASH", StringComparison.OrdinalIgnoreCase),
                    Type   = GetType(attributeDefinition.AttributeType)
                };
                if (keyDescription.IsHash)
                {
                    HashKeys.Add(keyName);
                }
                else
                {
                    RangeKeys.Add(keyName);
                }
                Keys[keyName] = keyDescription;
            }

            LocalSecondaryIndexes.Clear();
            LocalSecondaryIndexNames.Clear();
            if (table.LocalSecondaryIndexes != null)
            {
                foreach (var index in table.LocalSecondaryIndexes)
                {
                    LocalSecondaryIndexes[index.IndexName] = index;
                    LocalSecondaryIndexNames.Add(index.IndexName);
                }
            }

            GlobalSecondaryIndexes.Clear();
            GlobalSecondaryIndexNames.Clear();
            if (table.GlobalSecondaryIndexes != null)
            {
                foreach (var index in table.GlobalSecondaryIndexes)
                {
                    GlobalSecondaryIndexes[index.IndexName] = index;
                    GlobalSecondaryIndexNames.Add(index.IndexName);
                }
            }

            Attributes.Clear();
            foreach (var attribute in table.AttributeDefinitions)
            {
                Attributes.Add(attribute);
            }

            keyNames = Keys.Keys.ToArray();
        }