Esempio n. 1
0
        /// <summary>
        /// Verifies the signature of this response matches the expected signature using the <see cref="ISignatureGenerator"/> provided.
        /// </summary>
        /// <remarks>
        /// <para>The <see cref="HummClient"/> automatically calls this method when a reponse is received, application code does not need to call this method explicitly unless performing it's own calls without using a <see cref="HummClient"/> instance.</para>
        /// <para>The <paramref name="signatureGenerator"/> must have been created/initialised with the same device key as the request that generated this response.</para>
        /// <para>If the <see cref="Signature"/> property is null or empty, this call is a no-op and will return without throwing an exception.</para>
        /// </remarks>
        /// <param name="signatureGenerator">The signature generator to use to confirm the response signature.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="signatureGenerator"/> is null.</exception>
        /// <exception cref="HummResponseSignatureException">Thrown if the signature of the response does not match the expected signature.</exception>
        public void VerifySignature(ISignatureGenerator signatureGenerator)
        {
            if (String.IsNullOrEmpty(Signature))
            {
                return;
            }

            signatureGenerator.GuardNull(nameof(signatureGenerator));

            var calcSig = signatureGenerator.GenerateSignature(HummModelPropertyReader.GetPropertyValues(this));

            if (calcSig != this.Signature)
            {
                throw new HummResponseSignatureException();
            }
        }