forked from moov-io/signedxml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
examples.go
70 lines (54 loc) · 1.37 KB
/
examples.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package main
import (
"fmt"
"io/ioutil"
"os"
"github.com/ma314smith/signedxml"
)
func main() {
testValidator()
testExclCanon()
}
func testValidator() {
xmlFile, err := os.Open("../testdata/valid-saml.xml")
if err != nil {
fmt.Println("Error opening file:", err)
return
}
defer xmlFile.Close()
xmlBytes, _ := ioutil.ReadAll(xmlFile)
validator, err := signedxml.NewValidator(string(xmlBytes))
if err != nil {
fmt.Printf("Validation Error: %s", err)
} else {
err = validator.Validate()
if err != nil {
fmt.Printf("Validation Error: %s", err)
} else {
fmt.Println("Example Validation Succeeded")
}
}
}
func testExclCanon() {
var input = `<?xml version="1.0"?>
<?xml-stylesheet href="doc.xsl" type="text/xsl" ?>
<!DOCTYPE doc SYSTEM "doc.dtd">
<doc>Hello, world!<!-- Comment 1 --></doc>
<?pi-without-data ?>
<!-- Comment 2 -->
<!-- Comment 3 -->`
var output = `<?xml-stylesheet href="doc.xsl" type="text/xsl" ?>
<doc>Hello, world!</doc>
<?pi-without-data?>`
transform := signedxml.ExclusiveCanonicalization{WithComments: false}
resultXML, err := transform.Process(input, "")
if err != nil {
fmt.Printf("Transformation Error: %s", err)
} else {
if resultXML == output {
fmt.Println("Example Tranformation Succeeded")
} else {
fmt.Println("Transformation Error: The transformed output did not match the expected output.")
}
}
}