예제 #1
0
        public async Task <IRfc3161TimestampToken> SubmitRequestAsync(Uri timestampUri, TimeSpan timeout)
        {
            if (timestampUri == null)
            {
                throw new ArgumentNullException(nameof(timestampUri));
            }

            if (!timestampUri.IsAbsoluteUri)
            {
                throw new ArgumentException(
                          Strings.AnAbsoluteUriIsRequired, nameof(timestampUri));
            }

            if (timestampUri.Scheme != Uri.UriSchemeHttp && timestampUri.Scheme != Uri.UriSchemeHttps)
            {
                throw new ArgumentException(
                          Strings.HttpOrHttpsIsRequired, nameof(timestampUri));
            }

            using (var content = new ReadOnlyMemoryContent(_rfc3161TimestampRequest.Encode()))
            {
                content.Headers.ContentType = new MediaTypeHeaderValue("application/timestamp-query");
                using (HttpResponseMessage httpResponse = await HttpClient.PostAsync(timestampUri, content))
                {
                    if (!httpResponse.IsSuccessStatusCode)
                    {
                        throw new CryptographicException(
                                  string.Format(
                                      CultureInfo.CurrentCulture,
                                      Strings.TimestampServiceRespondedError,
                                      (int)httpResponse.StatusCode,
                                      httpResponse.ReasonPhrase));
                    }

                    if (!string.Equals(httpResponse.Content.Headers.ContentType.MediaType, "application/timestamp-response", StringComparison.OrdinalIgnoreCase))
                    {
                        throw new CryptographicException(Strings.TimestampServiceRespondedInvalidFormat);
                    }

                    var data = await httpResponse.Content.ReadAsByteArrayAsync();

                    System.Security.Cryptography.Pkcs.Rfc3161TimestampToken response = _rfc3161TimestampRequest.ProcessResponse(data, out var _);

                    var timestampToken = new Rfc3161TimestampTokenNetstandard21Wrapper(response);

                    return(timestampToken);
                }
            }
        }
예제 #2
0
 public static bool TryDecode(System.ReadOnlyMemory <byte> encodedBytes, out System.Security.Cryptography.Pkcs.Rfc3161TimestampToken token, out int bytesConsumed)
 {
     throw null;
 }
예제 #3
0
 public static bool TryDecode(System.ReadOnlyMemory <byte> encodedBytes, [System.Diagnostics.CodeAnalysis.NotNullWhenAttribute(true)] out System.Security.Cryptography.Pkcs.Rfc3161TimestampToken token, out int bytesConsumed)
 {
     throw null;
 }