Beispiel #1
0
        static Utf8String s_emptyHeaders = (Utf8String)"\n\n\n\n\n\n\n\n\n\n\nx-ms-date:"; // this wont be needed once we have UTF8 literals

        public static bool TryWrite(Span <byte> output, Sha256 hash, string verb, string canonicalizedResource, DateTime utc, out int bytesWritten)
        {
            try
            {
                var writer = new SpanWriter(output);
                writer.WriteLine(verb);
                writer.Write("\n\n\n\n\n\n\n\n\n\n\nx-ms-date:");
                writer.WriteLine(utc, 'R');
                writer.Write(canonicalizedResource);
                hash.Append(writer.Written);
                writer.Index = 0;
                writer.WriteBytes(hash, default, Base64Experimental.BytesToUtf8Encoder);
Beispiel #2
0
        public static bool TryWrite(Span <byte> output, Sha256 hash, string keyType, string verb, string resourceId, string resourceType, string tokenVersion, DateTime utc, out int bytesWritten)
        {
            Span <byte> buffer = stackalloc byte[AuthenticationHeaderBufferSize];
            var         writer = new SpanWriter(buffer);

            writer.Enlarge = (minumumSize) => { return(new byte[minumumSize * 2]); };

            // compute signature hash
            writer.WriteLine(verb, Ascii.ToLowercase);
            writer.WriteLine(resourceType, Ascii.ToLowercase);
            writer.WriteLine(resourceId, Ascii.ToLowercase);
            writer.WriteLine(utc, 'l');
            writer.Write('\n');
            hash.Append(writer.Written);

            // combine token
            writer.Index = 0; // reuse writer and buffer
            writer.Write("type=");
            writer.Write(keyType);
            writer.Write("&ver=");
            writer.Write(tokenVersion);
            writer.Write("&sig=");

            writer.WriteBytes(hash, default, Base64Experimental.BytesToUtf8Encoder);