forked from SAP/go-hdb
/
sessioncookie.go
60 lines (50 loc) · 1.58 KB
/
sessioncookie.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
package auth
import (
"fmt"
)
// SessionCookie implements session cookie authentication.
type SessionCookie struct {
cookie []byte
logonname string
clientID string
}
// NewSessionCookie creates a new authSessionCookie instance.
func NewSessionCookie(cookie []byte, logonname, clientID string) *SessionCookie {
return &SessionCookie{cookie: cookie, logonname: logonname, clientID: clientID}
}
func (a *SessionCookie) String() string {
return fmt.Sprintf("method type %s cookie %v", a.Typ(), a.cookie)
}
// Typ implements the Mthod interface.
func (a *SessionCookie) Typ() string { return MtSessionCookie }
// Order implements the Method interface.
func (a *SessionCookie) Order() byte { return MoSessionCookie }
// PrepareInitReq implements the Method interface.
func (a *SessionCookie) PrepareInitReq(prms *Prms) error {
prms.addString(a.Typ())
prms.addBytes(append(a.cookie, a.clientID...)) // cookie + clientID !!!
return nil
}
// InitRepDecode implements the Method interface.
func (a *SessionCookie) InitRepDecode(d *Decoder) error {
return nil
}
// PrepareFinalReq implements the Method interface.
func (a *SessionCookie) PrepareFinalReq(prms *Prms) error {
prms.AddCESU8String(a.logonname)
prms.addString(a.Typ())
prms.addEmpty() // empty parameter
return nil
}
// FinalRepDecode implements the Method interface.
func (a *SessionCookie) FinalRepDecode(d *Decoder) error {
if err := d.NumPrm(2); err != nil {
return err
}
mt := d.String()
if err := checkAuthMethodType(mt, a.Typ()); err != nil {
return err
}
d.bytes() // second parameter seems to be empty
return nil
}