NetMQ.Security.V0_1.SecureChannel.DecryptApplicationMessage C# (CSharp) Method

DecryptApplicationMessage() public method

Decrypt the given NetMQMessage, the first frame of which is assumed to contain the protocol version.
cipherMessage must not be null. NetMQSecurityErrorCode.SecureChannelNotReady: The secure channel must be ready. NetMQSecurityErrorCode.InvalidFramesCount: The cipher message must have at least 2 frames. NetMQSecurityErrorCode.InvalidProtocolVersion: The protocol must be the correct version. NetMQSecurityErrorCode.InvalidContentType: The message must contain application data.
public DecryptApplicationMessage ( [ cipherMessage ) : NetMQMessage
cipherMessage [ the NetMQMessage to decrypt
return NetMQMessage
        public NetMQMessage DecryptApplicationMessage([NotNull] NetMQMessage cipherMessage)
        {
            if (!SecureChannelReady)
            {
                throw new NetMQSecurityException(NetMQSecurityErrorCode.SecureChannelNotReady, "Cannot decrypt messages until the secure channel is ready");
            }

            if (cipherMessage == null)
            {
                throw new ArgumentNullException("cipherMessage");
            }

            if (cipherMessage.FrameCount < 2)
            {
                throw new NetMQSecurityException(NetMQSecurityErrorCode.InvalidFramesCount, "cipher message should have at least 2 frames");
            }

            NetMQFrame protocolVersionFrame = cipherMessage.Pop();
            NetMQFrame contentTypeFrame = cipherMessage.Pop();

            if (!protocolVersionFrame.ToByteArray().SequenceEqual(m_protocolVersion))
            {
                throw new NetMQSecurityException(NetMQSecurityErrorCode.InvalidProtocolVersion, "Wrong protocol version");
            }

            ContentType contentType = (ContentType)contentTypeFrame.Buffer[0];

            if (contentType != ContentType.ApplicationData)
            {
                throw new NetMQSecurityException(NetMQSecurityErrorCode.InvalidContentType, "Not an application data message");
            }

            return m_recordLayer.DecryptMessage(ContentType.ApplicationData, cipherMessage);
        }