github.com/cyverse/go-irodsclient@v0.13.2/irods/message/auth_pam_response.go (about) 1 package message 2 3 import ( 4 "encoding/xml" 5 6 "golang.org/x/xerrors" 7 ) 8 9 // IRODSMessagePamAuthResponse stores auth challenge 10 type IRODSMessagePamAuthResponse struct { 11 XMLName xml.Name `xml:"pamAuthRequestOut_PI"` 12 GeneratedPassword string `xml:"irodsPamPassword"` 13 } 14 15 // GetBytes returns byte array 16 func (msg *IRODSMessagePamAuthResponse) GetBytes() ([]byte, error) { 17 xmlBytes, err := xml.Marshal(msg) 18 if err != nil { 19 return nil, xerrors.Errorf("failed to marshal irods message to xml: %w", err) 20 } 21 return xmlBytes, nil 22 } 23 24 // FromBytes returns struct from bytes 25 func (msg *IRODSMessagePamAuthResponse) FromBytes(bytes []byte) error { 26 err := xml.Unmarshal(bytes, msg) 27 if err != nil { 28 return xerrors.Errorf("failed to unmarshal xml to irods message: %w", err) 29 } 30 return nil 31 } 32 33 // FromMessage returns struct from IRODSMessage 34 func (msg *IRODSMessagePamAuthResponse) FromMessage(msgIn *IRODSMessage) error { 35 if msgIn.Body == nil { 36 return xerrors.Errorf("empty message body") 37 } 38 39 err := msg.FromBytes(msgIn.Body.Message) 40 if err != nil { 41 return xerrors.Errorf("failed to get irods message from message body") 42 } 43 return nil 44 }