本文整理匯總了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()
}