/// <summary> /// End get additional aggregator configuration data (async) /// </summary> /// <param name="asyncResult"></param> /// <returns>Aggregator configuration data</returns> public AggregatorConfig EndGetAggregatorConfig(IAsyncResult asyncResult) { if (_signingServiceProtocol == null) { throw new KsiServiceException("Signing service protocol is missing from service."); } KsiServiceAsyncResult serviceAsyncResult = GetKsiServiceAsyncResult(asyncResult); if (!serviceAsyncResult.IsCompleted) { serviceAsyncResult.AsyncWaitHandle.WaitOne(); } byte[] data = _signingServiceProtocol.EndGetAggregatorConfig(serviceAsyncResult); PduPayload payload = AggregatorConfigRequestResponseParser.Parse(data); AggregatorConfigResponsePayload configResponsePayload = payload as AggregatorConfigResponsePayload; if (configResponsePayload == null) { Logger.Warn("Aggregator config request failed. Invalid response payload.{0}Payload:{0}{1}", Environment.NewLine, payload); throw new KsiServiceException("Invalid config response payload. Type: " + payload.Type); } return(new AggregatorConfig(configResponsePayload)); }
private IAsyncResult BeginSignRequest(byte[] pdu, ulong requestId, DataHash hash, uint level, AsyncCallback callback, object asyncState) { IAsyncResult asyncResult = _signingServiceProtocol.BeginSign(pdu, requestId, callback, asyncState); KsiServiceAsyncResult ar = asyncResult as KsiServiceAsyncResult; if (ar == null) { throw new KsiServiceException("Unexpected async result type received from signing service protocol: " + asyncResult.GetType()); } ar.DocumentHash = hash; ar.Level = level; return(ar); }
private static KsiServiceAsyncResult GetKsiServiceAsyncResult(IAsyncResult asyncResult) { if (asyncResult == null) { throw new ArgumentNullException(nameof(asyncResult)); } KsiServiceAsyncResult serviceAsyncResult = asyncResult as KsiServiceAsyncResult; if (serviceAsyncResult == null) { throw new KsiServiceException("Invalid " + nameof(asyncResult) + " type: " + asyncResult.GetType() + "; Expected type: KsiServiceAsyncResult."); } return(serviceAsyncResult); }
/// <summary> /// End create signature (async). /// </summary> /// <param name="asyncResult">async result</param> /// <returns>KSI signature</returns> public IKsiSignature EndSign(IAsyncResult asyncResult) { KsiServiceAsyncResult serviceAsyncResult = GetKsiServiceAsyncResult(asyncResult); SignRequestResponsePayload responsePayload = GetSignResponsePayload(serviceAsyncResult); LegacyAggregationResponsePayload legacyPayload = responsePayload as LegacyAggregationResponsePayload; AggregationResponsePayload payload = responsePayload as AggregationResponsePayload; IKsiSignature signature = legacyPayload != null ? _ksiSignatureFactory.Create(legacyPayload, serviceAsyncResult.DocumentHash, serviceAsyncResult.Level) : _ksiSignatureFactory.Create(payload, serviceAsyncResult.DocumentHash, serviceAsyncResult.Level); Logger.Debug("End sign successful (request id: {0}){1}{2}", serviceAsyncResult.RequestId, Environment.NewLine, signature); return(signature); }
/// <summary> /// End extend (async). /// </summary> /// <param name="asyncResult">async result</param> /// <returns>extended calendar hash chain</returns> public CalendarHashChain EndExtend(IAsyncResult asyncResult) { if (_extendingServiceProtocol == null) { throw new KsiServiceException("Extending service protocol is missing from service."); } KsiServiceAsyncResult serviceAsyncResult = GetKsiServiceAsyncResult(asyncResult); if (!serviceAsyncResult.IsCompleted) { serviceAsyncResult.AsyncWaitHandle.WaitOne(); } byte[] data = _extendingServiceProtocol.EndExtend(serviceAsyncResult); PduPayload payload = ExtendRequestResponseParser.Parse(data, serviceAsyncResult.RequestId); if (IsLegacyPduVersion) { LegacyExtendResponsePayload legacyResponsePayload = payload as LegacyExtendResponsePayload; if (legacyResponsePayload == null) { Logger.Warn("Extend request failed. Invalid response payload.{0}Payload:{0}{1}", Environment.NewLine, payload); throw new KsiServiceException("Invalid extend response payload. Type: " + payload.Type); } return(legacyResponsePayload.CalendarHashChain); } else { ExtendResponsePayload responsePayload = payload as ExtendResponsePayload; if (responsePayload == null) { Logger.Warn("Extend request failed. Invalid response payload.{0}Payload:{0}{1}", Environment.NewLine, payload); throw new KsiServiceException("Invalid extend response payload. Type: " + payload.Type); } Logger.Debug("End extend successful (request id: {0}){1}{2}", serviceAsyncResult.RequestId, Environment.NewLine, responsePayload.CalendarHashChain); return(responsePayload.CalendarHashChain); } }
/// <summary> /// End get publications file (async). /// </summary> /// <param name="asyncResult">async result</param> /// <returns>publications file</returns> public IPublicationsFile EndGetPublicationsFile(IAsyncResult asyncResult) { if (_publicationsFileServiceProtocol == null) { throw new KsiServiceException("Publications file service protocol is missing from service."); } if (_publicationsFileFactory == null) { throw new KsiServiceException("Publications file factory is missing from service."); } KsiServiceAsyncResult serviceAsyncResult = GetKsiServiceAsyncResult(asyncResult); if (!serviceAsyncResult.IsCompleted) { serviceAsyncResult.AsyncWaitHandle.WaitOne(); } byte[] data = _publicationsFileServiceProtocol.EndGetPublicationsFile(serviceAsyncResult); Logger.Debug("End get publications file successful."); return(_publicationsFileFactory.Create(data)); }
private SignRequestResponsePayload GetSignResponsePayload(KsiServiceAsyncResult serviceAsyncResult) { if (_signingServiceProtocol == null) { throw new KsiServiceException("Signing service protocol is missing from service."); } if (!serviceAsyncResult.IsCompleted) { serviceAsyncResult.AsyncWaitHandle.WaitOne(); } byte[] data = _signingServiceProtocol.EndSign(serviceAsyncResult); PduPayload payload = SignRequestResponseParser.Parse(data, serviceAsyncResult.RequestId); SignRequestResponsePayload signResponsePayload = payload as SignRequestResponsePayload; if (signResponsePayload == null) { Logger.Warn("Sign request failed. Invalid response payload.{0}Payload:{0}{1}", Environment.NewLine, payload); throw new KsiServiceException("Invalid sign response payload. Type: " + payload.Type); } return(signResponsePayload); }