Skip to content

Commit

Permalink
feat(slo): add Bytes() and Deflate() functions for LogoutRequest (#251)
Browse files Browse the repository at this point in the history
Bytes() is needed in for returning a byte array for POST Binding.
Deflate() is needed for compressing using gzip algorithm a LogoutRequest
byte array.
  • Loading branch information
mmailhos authored Jan 31, 2020
1 parent eefb3b2 commit 0e0bf51
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions schema.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package saml

import (
"bytes"
"compress/flate"
"encoding/xml"
"strconv"
"time"
Expand Down Expand Up @@ -112,6 +114,43 @@ func (r *LogoutRequest) UnmarshalXML(d *xml.Decoder, start xml.StartElement) err
return nil
}

// Bytes returns a byte array representation of the LogoutRequest
func (r *LogoutRequest) Bytes() ([]byte, error) {
doc := etree.NewDocument()
doc.SetRoot(r.Element())

buf, err := doc.WriteToBytes()
if err != nil {
return nil, err
}

return buf, nil
}

// Deflate returns a compressed byte array of the LogoutRequest
func (r *LogoutRequest) Deflate() ([]byte, error) {
buf, err := r.Bytes()
if err != nil {
return nil, err
}

var b bytes.Buffer
writer, err := flate.NewWriter(&b, flate.DefaultCompression)
if err != nil {
return nil, err
}

if _, err := writer.Write(buf); err != nil {
return nil, err
}

if err := writer.Close(); err != nil {
return nil, err
}

return b.Bytes(), nil
}

// Element returns an etree.Element representing the object
// Element returns an etree.Element representing the object in XML form.
func (r *AuthnRequest) Element() *etree.Element {
Expand Down

0 comments on commit 0e0bf51

Please sign in to comment.