//-----------------------------------------------------------------------
//
// Copyright (c) Outercurve Foundation. All rights reserved.
//
//-----------------------------------------------------------------------
namespace DotNetOpenAuth.Test.Mocks {
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using DotNetOpenAuth.Messaging;
using DotNetOpenAuth.Messaging.Bindings;
internal class MockSigningBindingElement : IChannelBindingElement {
internal const string MessageSignature = "mocksignature";
#region IChannelBindingElement Members
MessageProtections IChannelBindingElement.Protection {
get { return MessageProtections.TamperProtection; }
}
///
/// Gets or sets the channel that this binding element belongs to.
///
public Channel Channel { get; set; }
Task IChannelBindingElement.ProcessOutgoingMessageAsync(IProtocolMessage message, CancellationToken cancellationToken) {
var signedMessage = message as ITamperResistantProtocolMessage;
if (signedMessage != null) {
signedMessage.Signature = MessageSignature;
return MessageProtectionTasks.TamperProtection;
}
return MessageProtectionTasks.Null;
}
Task IChannelBindingElement.ProcessIncomingMessageAsync(IProtocolMessage message, CancellationToken cancellationToken) {
var signedMessage = message as ITamperResistantProtocolMessage;
if (signedMessage != null) {
if (signedMessage.Signature != MessageSignature) {
throw new InvalidSignatureException(message);
}
return MessageProtectionTasks.TamperProtection;
}
return MessageProtectionTasks.Null;
}
#endregion
}
}