Skip to content

Commit 0e0bf51

Browse files
authored
feat(slo): add Bytes() and Deflate() functions for LogoutRequest (#251)
Bytes() is needed in for returning a byte array for POST Binding. Deflate() is needed for compressing using gzip algorithm a LogoutRequest byte array.
1 parent eefb3b2 commit 0e0bf51

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

schema.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package saml
22

33
import (
4+
"bytes"
5+
"compress/flate"
46
"encoding/xml"
57
"strconv"
68
"time"
@@ -112,6 +114,43 @@ func (r *LogoutRequest) UnmarshalXML(d *xml.Decoder, start xml.StartElement) err
112114
return nil
113115
}
114116

117+
// Bytes returns a byte array representation of the LogoutRequest
118+
func (r *LogoutRequest) Bytes() ([]byte, error) {
119+
doc := etree.NewDocument()
120+
doc.SetRoot(r.Element())
121+
122+
buf, err := doc.WriteToBytes()
123+
if err != nil {
124+
return nil, err
125+
}
126+
127+
return buf, nil
128+
}
129+
130+
// Deflate returns a compressed byte array of the LogoutRequest
131+
func (r *LogoutRequest) Deflate() ([]byte, error) {
132+
buf, err := r.Bytes()
133+
if err != nil {
134+
return nil, err
135+
}
136+
137+
var b bytes.Buffer
138+
writer, err := flate.NewWriter(&b, flate.DefaultCompression)
139+
if err != nil {
140+
return nil, err
141+
}
142+
143+
if _, err := writer.Write(buf); err != nil {
144+
return nil, err
145+
}
146+
147+
if err := writer.Close(); err != nil {
148+
return nil, err
149+
}
150+
151+
return b.Bytes(), nil
152+
}
153+
115154
// Element returns an etree.Element representing the object
116155
// Element returns an etree.Element representing the object in XML form.
117156
func (r *AuthnRequest) Element() *etree.Element {

0 commit comments

Comments
 (0)