-
Notifications
You must be signed in to change notification settings - Fork 0
/
crypto_test_helpers.go
62 lines (53 loc) · 1.71 KB
/
crypto_test_helpers.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
package utils
import (
"bytes"
"encoding/xml"
)
// Data represents a <data> element.
type data struct {
XMLName xml.Name `xml:"data"`
//Entry []Entry `xml:"entry"`
Name string `xml:"name"`
Age int `xml:"age"`
}
// PubnubDemoMessage is a struct to test a non-alphanumeric message
type pubnubDemoMessage struct {
DefaultMessage string `json:",string"`
}
// CustomComplexMessage is used to test the custom structure encryption and decryption.
// The variables "foo" and "bar" as used in the other languages are not
// accepted by golang and give an empty value when serialized, used "Foo"
// and "Bar" instead.
type customComplexMessage struct {
VersionID float32 `json:",string"`
TimeToken int64 `json:",string"`
OperationName string
Channels []string
DemoMessage pubnubDemoMessage `json:",string"`
SampleXML string `json:",string"`
}
// InitComplexMessage initializes a complex structure of the
// type CustomComplexMessage which includes a xml, struct of type PubnubDemoMessage,
// strings, float and integer.
func initComplexMessage() customComplexMessage {
pubnubDemoMessage := pubnubDemoMessage{
DefaultMessage: "~!@#$%^&*()_+ `1234567890-= qwertyuiop[]\\ {}| asdfghjkl;' :\" zxcvbnm,./ <>? ",
}
xmlDoc := &data{Name: "Doe", Age: 42}
output := new(bytes.Buffer)
enc := xml.NewEncoder(output)
err := enc.Encode(xmlDoc)
if err != nil {
//fmt.Printf("error: %v\n", err)
return customComplexMessage{}
}
customComplexMessage := customComplexMessage{
VersionID: 3.4,
TimeToken: 13601488652764619,
OperationName: "Publish",
Channels: []string{"ch1", "ch 2"},
DemoMessage: pubnubDemoMessage,
SampleXML: output.String(),
}
return customComplexMessage
}