Esempio n. 1
0
        async Task <SignResponse> SignAsyncWithRetry(HttpWorkloadClient hsmHttpClient, SignRequest signRequest)
        {
            var          transientRetryPolicy = new RetryPolicy(TransientErrorDetectionStrategy, TransientRetryStrategy);
            SignResponse response             = await transientRetryPolicy.ExecuteAsync(() => hsmHttpClient.SignAsync(this.apiVersion, this.moduleId, this.generationId, signRequest));

            return(response);
        }
Esempio n. 2
0
        public async Task <string> SignAsync(string data)
        {
            var signRequest = new SignRequest
            {
                KeyId = DefaultKeyId,
                Algo  = DefaultSignRequestAlgo,
                Data  = Encoding.UTF8.GetBytes(data)
            };

            HttpClient httpClient = HttpClientHelper.GetHttpClient(this.providerUri);

            try
            {
                var hsmHttpClient = new HttpWorkloadClient(httpClient)
                {
                    BaseUrl = HttpClientHelper.GetBaseUrl(this.providerUri)
                };

                SignResponse response = await this.SignAsyncWithRetry(hsmHttpClient, signRequest);

                return(Convert.ToBase64String(response.Digest));
            }
            catch (Exception ex)
            {
                switch (ex)
                {
                case IoTEdgedException <ErrorResponse> errorResponseException:
                    throw new HttpHsmCommunicationException(
                              $"Error calling SignAsync: {errorResponseException.Result?.Message ?? string.Empty}",
                              errorResponseException.StatusCode);

                case IoTEdgedException ioTEdgedException:
                    throw new HttpHsmCommunicationException(
                              $"Error calling SignAsync: {ioTEdgedException.Response ?? string.Empty}",
                              ioTEdgedException.StatusCode);

                default:
                    throw;
                }
            }
            finally
            {
                httpClient.Dispose();
            }
        }