/// <summary>
        /// Parse child tag
        /// </summary>
        protected override ITlvTag ParseChild(ITlvTag childTag)
        {
            switch (childTag.Type)
            {
            case Constants.AggregationRequestPayload.TagType:
                AggregationRequestPayload aggregationRequestPayload = childTag as AggregationRequestPayload ?? new AggregationRequestPayload(childTag);
                Payloads.Add(aggregationRequestPayload);
                return(aggregationRequestPayload);

            case Constants.AggregatorConfigRequestPayload.TagType:
                AggregatorConfigRequestPayload aggregatorConfigRequestPayload = childTag as AggregatorConfigRequestPayload ?? new AggregatorConfigRequestPayload(childTag);
                Payloads.Add(aggregatorConfigRequestPayload);
                return(aggregatorConfigRequestPayload);

            default:
                return(base.ParseChild(childTag));
            }
        }
        /// <summary>
        ///     Begin create signature with given data hash (async).
        /// </summary>
        /// <param name="hash">data hash</param>
        /// <param name="level">the level value of the aggregation tree node</param>
        /// <param name="callback">callback when creating signature is finished</param>
        /// <param name="asyncState">callback async state object</param>
        /// <returns>async result</returns>
        public IAsyncResult BeginSign(DataHash hash, uint level, AsyncCallback callback, object asyncState)
        {
            if (hash == null)
            {
                throw new ArgumentNullException(nameof(hash));
            }

            if (hash.Algorithm.HasDeprecatedSinceDate)
            {
                throw new KsiServiceException(string.Format("Hash algorithm {0} is deprecated since {1} and can not be used for signing.", hash.Algorithm.Name,
                                                            hash.Algorithm.DeprecatedSinceDate?.ToString(Constants.DateFormat)));
            }

            if (_signingServiceProtocol == null)
            {
                throw new KsiServiceException("Signing service protocol is missing from service.");
            }

            if (_signingServiceCredentials == null)
            {
                throw new KsiServiceException("Signing service credentials are missing.");
            }

            if (IsLegacyPduVersion)
            {
                return(BeginLegacySign(hash, level, callback, asyncState));
            }

            PduHeader header    = new PduHeader(_signingServiceCredentials.LoginId);
            ulong     requestId = GenerateRequestId();
            AggregationRequestPayload payload = level == 0 ? new AggregationRequestPayload(requestId, hash) : new AggregationRequestPayload(requestId, hash, level);
            AggregationRequestPdu     pdu     = new AggregationRequestPdu(header, payload, _signingMacAlgorithm, _signingServiceCredentials.LoginKey);

            Logger.Debug("Begin sign (request id: {0}){1}{2}", payload.RequestId, Environment.NewLine, pdu);
            return(BeginSignRequest(pdu.Encode(), requestId, hash, level, callback, asyncState));
        }