Skip to content

Commit

Permalink
fix: parse CacheDuration and ValidUntil in EntitiesDescriptor
Browse files Browse the repository at this point in the history
  • Loading branch information
hf committed Aug 16, 2024
1 parent bbccb79 commit 5ac38ab
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,55 @@ type EntitiesDescriptor struct {
EntityDescriptors []EntityDescriptor `xml:"urn:oasis:names:tc:SAML:2.0:metadata EntityDescriptor"`
}

// MarshalXML implements xml.Marshaler
func (m EntitiesDescriptor) MarshalXML(e *xml.Encoder, _ xml.StartElement) error {
var validUntil *RelaxedTime
var cacheDuration *Duration
if m.ValidUntil != nil {
vu := RelaxedTime(*m.ValidUntil)
validUntil = &vu
}
if m.CacheDuration != nil {
cd := Duration(*m.CacheDuration)
cacheDuration = &cd
}
type Alias EntitiesDescriptor
aux := &struct {
ValidUntil *RelaxedTime `xml:"validUntil,attr,omitempty"`
CacheDuration *Duration `xml:"cacheDuration,attr,omitempty"`
*Alias
}{
ValidUntil: validUntil,
CacheDuration: cacheDuration,
Alias: (*Alias)(&m),
}
return e.Encode(aux)
}

// UnmarshalXML implements xml.Unmarshaler
func (m *EntitiesDescriptor) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
type Alias EntitiesDescriptor
aux := &struct {
ValidUntil *RelaxedTime `xml:"validUntil,attr,omitempty"`
CacheDuration *Duration `xml:"cacheDuration,attr,omitempty"`
*Alias
}{
Alias: (*Alias)(m),
}
if err := d.DecodeElement(aux, &start); err != nil {
return err
}
if aux.ValidUntil != nil {
t := time.Time(*aux.ValidUntil)
m.ValidUntil = &t
}
if aux.CacheDuration != nil {
d := time.Duration(*aux.CacheDuration)
m.CacheDuration = &d
}
return nil
}

// Metadata as been renamed to EntityDescriptor
//
// This change was made to be consistent with the rest of the API which uses names
Expand Down

0 comments on commit 5ac38ab

Please sign in to comment.