本文整理汇总了Golang中github.com/project-iris/iris/proto.Message.Secure方法的典型用法代码示例。如果您正苦于以下问题:Golang Message.Secure方法的具体用法?Golang Message.Secure怎么用?Golang Message.Secure使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/project-iris/iris/proto.Message
的用法示例。
在下文中一共展示了Message.Secure方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: SendDirect
// The actual message sending logic. Calculates the payload MAC, encrypts the
// headers and sends it down to the stream. Direct send is public for handshake
// simplifications. After that is done, the link should switch to channel mode.
func (l *Link) SendDirect(msg *proto.Message) error {
var err error
// Sanity check for message data security
if !msg.Secure() && len(msg.Data) > 0 {
log.Printf("link: unsecured data, send denied.")
return errors.New("unsecured data, send denied")
}
// Flatten and encrypt the headers
if err = l.outCoder.Encode(msg.Head); err != nil {
return err
}
l.outCipher.XORKeyStream(l.outBuffer.Bytes(), l.outBuffer.Bytes())
defer l.outBuffer.Reset()
// Generate the MAC of the encrypted payload and headers
l.outMacer.Write(l.outBuffer.Bytes())
l.outMacer.Write(msg.Data)
// Send the multi-part message (headers + payload + MAC)
if err = l.socket.Send(l.outBuffer.Bytes()); err != nil {
return err
}
if err = l.socket.Send(msg.Data); err != nil {
return err
}
if err = l.socket.Send(l.outMacer.Sum(nil)); err != nil {
return err
}
return l.socket.Flush()
}