Skip to content

Commit

Permalink
make SAuthentication optional in KMIP serialiser
Browse files Browse the repository at this point in the history
  • Loading branch information
HouzuoGuo committed Jun 1, 2017
1 parent d07d15d commit b5ae717
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions kmip/structure/op_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,21 +137,29 @@ type SRequestHeader struct {

func (header SRequestHeader) SerialiseToTTLV() ttlv.Item {
header.IBatchCount.Tag = TagBatchCount
return ttlv.NewStructure(
TagRequestHeader,
header.SProtocolVersion.SerialiseToTTLV(),
header.SAuthentication.SerialiseToTTLV(),
&header.IBatchCount)
if header.SAuthentication.SCredential.SCredentialValue.TUsername.Value == "" {
// Omit authentication header if no username data is given
return ttlv.NewStructure(
TagRequestHeader,
header.SProtocolVersion.SerialiseToTTLV(),
&header.IBatchCount)
} else {
return ttlv.NewStructure(
TagRequestHeader,
header.SProtocolVersion.SerialiseToTTLV(),
header.SAuthentication.SerialiseToTTLV(),
&header.IBatchCount)
}
}

func (header *SRequestHeader) DeserialiseFromTTLV(in ttlv.Item) error {
if err := DecodeStructItem(in, TagRequestHeader, TagProtocolVersion, &header.SProtocolVersion); err != nil {
return err
} else if err := DecodeStructItem(in, TagRequestHeader, TagAuthentication, &header.SAuthentication); err != nil {
return err
} else if err := DecodeStructItem(in, TagRequestHeader, TagBatchCount, &header.IBatchCount); err != nil {
return err
}
// Decode authentication header if it is given
DecodeStructItem(in, TagRequestHeader, TagAuthentication, &header.SAuthentication)
return nil
}

Expand Down

0 comments on commit b5ae717

Please sign in to comment.