Esempio n. 1
0
 static void Writer()
 {
     foreach (var iteration in Benchmark.Iterations)
     {
         using (iteration.StartMeasurement()) {
             CosmosDbAuthorizationHeader.TryWrite(output, sha, keyType, verb, resourceId, resourceType, version, utc, out int bytesWritten);
         }
     }
 }
Esempio n. 2
0
        public void CosmosDbAuthenticationHeaderTryWriteUtf8()
        {
            var keyBytes = Key.ComputeKeyBytes(fakeKey);
            var sha      = Sha256.Create(keyBytes);

            // Generate using non-allocating APIs
            var buffer = new byte[256];

            Assert.True(CosmosDbAuthorizationHeader.TryWrite(buffer, sha, (Utf8Span)keyType, (Utf8Span)"GET", (Utf8Span)resourceId, (Utf8Span)resourceType, (Utf8Span)version, utc, out int bytesWritten));
            var signatureAsString = Encoding.UTF8.GetString(buffer, 0, bytesWritten);

            // Generate using existing .NET APIs (sample from Asure documentation)
            var expected = CosmosDbBaselineFromMsdn(fakeKey, keyType, "GET", resourceId, resourceType, version, utc);

            Assert.Equal(expected, signatureAsString);
        }
Esempio n. 3
0
        public void CosmosDbAuthenticationHeaderTryFormat()
        {
            var header = new CosmosDbAuthorizationHeader();

            header.Hash         = Sha256.Create(Key.ComputeKeyBytes(fakeKey));
            header.KeyType      = keyType;
            header.Method       = "GET";
            header.ResourceId   = resourceId;
            header.ResourceType = resourceType;
            header.Version      = version;
            header.Time         = utc;

            // Generate using non-allocating APIs
            var buffer = new byte[256];

            Assert.True(header.TryFormat(buffer, out int bytesWritten));

            var signatureAsString = Encoding.UTF8.GetString(buffer, 0, bytesWritten);

            // Generate using existing .NET APIs (sample from Asure documentation)
            var expected = CosmosDbBaselineFromMsdn(fakeKey, keyType, "GET", resourceId, resourceType, version, utc);

            Assert.Equal(expected, signatureAsString);
        }
Esempio n. 4
0
 public bool WriterUtf8()
 => CosmosDbAuthorizationHeader.TryWrite(output, sha, keyTypeU8, verbU8, resourceIdU8, resourceTypeU8, versionU8, utc, out int bytesWritten);
Esempio n. 5
0
 public bool Writer()
 => CosmosDbAuthorizationHeader.TryWrite(output, sha, keyType, verb, resourceId, resourceType, version, utc, out int bytesWritten);