Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(slo): add Bytes() and Deflate() functions for LogoutRequest #251

Merged
merged 1 commit into from
Jan 31, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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