diff --git a/schema.go b/schema.go index 7ce5471c..cc462af2 100644 --- a/schema.go +++ b/schema.go @@ -100,31 +100,31 @@ func (r *AuthnRequest) Element() *etree.Element { } // MarshalXML implements xml.Marshaler -func (a *AuthnRequest) MarshalXML(e *xml.Encoder, start xml.StartElement) error { +func (r *AuthnRequest) MarshalXML(e *xml.Encoder, start xml.StartElement) error { type Alias AuthnRequest aux := &struct { IssueInstant RelaxedTime `xml:",attr"` *Alias }{ - IssueInstant: RelaxedTime(a.IssueInstant), - Alias: (*Alias)(a), + IssueInstant: RelaxedTime(r.IssueInstant), + Alias: (*Alias)(r), } return e.Encode(aux) } // UnmarshalXML implements xml.Unmarshaler -func (a *AuthnRequest) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { +func (r *AuthnRequest) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { type Alias AuthnRequest aux := &struct { IssueInstant RelaxedTime `xml:",attr"` *Alias }{ - Alias: (*Alias)(a), + Alias: (*Alias)(r), } if err := d.DecodeElement(&aux, &start); err != nil { return err } - a.IssueInstant = time.Time(aux.IssueInstant) + r.IssueInstant = time.Time(aux.IssueInstant) return nil } diff --git a/service_provider.go b/service_provider.go index 76a5b3ca..1043d01c 100644 --- a/service_provider.go +++ b/service_provider.go @@ -25,6 +25,7 @@ import ( // NameIDFormat is the format of the id type NameIDFormat string +// Element returns an XML element representation of n. func (n NameIDFormat) Element() *etree.Element { el := etree.NewElement("") el.SetText(string(n)) diff --git a/time.go b/time.go index 00ce754c..3f266f97 100644 --- a/time.go +++ b/time.go @@ -2,10 +2,13 @@ package saml import "time" +// RelaxedTime is a version of time.Time that supports the time format +// found in SAML documents. type RelaxedTime time.Time const timeFormat = "2006-01-02T15:04:05.999Z07:00" +// MarshalText implements encoding.TextMarshaler func (m RelaxedTime) MarshalText() ([]byte, error) { // According to section 1.2.2 of the OASIS SAML 1.1 spec, we can't trust // other applications to handle time resolution finer than a millisecond. @@ -18,6 +21,7 @@ func (m RelaxedTime) String() string { return time.Time(m).Round(time.Millisecond).UTC().Format(timeFormat) } +// UnmarshalText implements encoding.TextUnmarshaler func (m *RelaxedTime) UnmarshalText(text []byte) error { if len(text) == 0 { *m = RelaxedTime(time.Time{})