// used by Compute
 public static void ValidateInputRequestTime(
     INameValueCollection requestHeaders,
     int masterTokenExpiryInSeconds,
     int allowedClockSkewInSeconds)
 {
     ValidateInputRequestTime(
         requestHeaders,
         (headers, field) => AuthorizationHelper.GetHeaderValue(headers, field),
         masterTokenExpiryInSeconds,
         allowedClockSkewInSeconds);
 }
        public static void SerializeMessagePayload(
            MemoryStream stream,
            string verb,
            string resourceId,
            string resourceType,
            INameValueCollection headers,
            bool bUseUtcNowForMissingXDate = false)
        {
            string xDate = AuthorizationHelper.GetHeaderValue(headers, HttpConstants.HttpHeaders.XDate);
            string date  = AuthorizationHelper.GetHeaderValue(headers, HttpConstants.HttpHeaders.HttpDate);

            // At-least one of date header should present
            // https://docs.microsoft.com/en-us/rest/api/documentdb/access-control-on-documentdb-resources
            if (string.IsNullOrEmpty(xDate) && string.IsNullOrWhiteSpace(date))
            {
                if (!bUseUtcNowForMissingXDate)
                {
                    throw new UnauthorizedException(RMResources.InvalidDateHeader);
                }

                headers[HttpConstants.HttpHeaders.XDate] = DateTime.UtcNow.ToString("r", CultureInfo.InvariantCulture);
                xDate = AuthorizationHelper.GetHeaderValue(headers, HttpConstants.HttpHeaders.XDate);
            }

            // for name based, it is case sensitive, we won't use the lower case
            if (!PathsHelper.IsNameBased(resourceId))
            {
                resourceId = resourceId.ToLowerInvariant();
            }

            stream.Write(verb.ToLowerInvariant());
            stream.Write("\n");
            stream.Write(resourceType.ToLowerInvariant());
            stream.Write("\n");
            stream.Write(resourceId);
            stream.Write("\n");
            stream.Write(xDate.ToLowerInvariant());
            stream.Write("\n");
            stream.Write(xDate.Equals(string.Empty, StringComparison.OrdinalIgnoreCase) ? date.ToLowerInvariant() : string.Empty);
            stream.Write("\n");
        }