github.com/cyverse/go-irodsclient@v0.13.2/irods/message/ssl_sharedsecret.go (about) 1 package message 2 3 import ( 4 "golang.org/x/xerrors" 5 ) 6 7 const ( 8 // RODS_MESSAGE_SSL_SHARED_SECRET_TYPE is a message type for shared secret used in SSL connection establishment 9 RODS_MESSAGE_SSL_SHARED_SECRET_TYPE MessageType = "SHARED_SECRET" 10 ) 11 12 // IRODSMessageSSLSharedSecret stores shared secret data 13 type IRODSMessageSSLSharedSecret struct { 14 SharedSecret []byte 15 } 16 17 // NewIRODSMessageSSLSharedSecret creates a IRODSMessageSSLSharedSecret message 18 func NewIRODSMessageSSLSharedSecret(sharedSecret []byte) *IRODSMessageSSLSharedSecret { 19 return &IRODSMessageSSLSharedSecret{ 20 SharedSecret: sharedSecret, 21 } 22 } 23 24 // GetMessage builds a message 25 func (msg *IRODSMessageSSLSharedSecret) GetMessage() (*IRODSMessage, error) { 26 msgBody := IRODSMessageBody{ 27 Type: RODS_MESSAGE_SSL_SHARED_SECRET_TYPE, 28 Message: msg.SharedSecret, 29 Error: nil, 30 Bs: nil, 31 IntInfo: 0, 32 } 33 34 msgHeader, err := msgBody.BuildHeader() 35 if err != nil { 36 return nil, xerrors.Errorf("failed to build header from irods message: %w", err) 37 } 38 39 return &IRODSMessage{ 40 Header: msgHeader, 41 Body: &msgBody, 42 }, nil 43 } 44 45 // FromMessage returns struct from IRODSMessage 46 func (msg *IRODSMessageSSLSharedSecret) FromMessage(msgIn *IRODSMessage) error { 47 if msgIn.Body == nil { 48 return xerrors.Errorf("empty message body") 49 } 50 51 msg.SharedSecret = msgIn.Body.Message 52 53 return nil 54 }